You must be logged in to post your query.
Home › Forums › Chart Support › Scaling
Tagged: scaling
Hi, How can I get a the portion of a particular graph when i insert the values X-min,X-max,Y-min,Y-max ?(That is, when we use Zoom enable – we drag the mouse on the graph and we get a portion of graph. Like this we did not use the mouse, only from the user input how can get that particular area?) Give me a solution?
@vpaswin1994,
You can programmatically zoom / pan to a region by setting viewportMinimum & viewportMaximum. Please take a look at this JSFiddle which shows setting viewport based on values entered in input-fields.
From what we have observed, sometimes things get delayed mostly when we are not able to reproduce your use-case or not able to understand the exact requirements. Having a JSFiddle helps us in understanding your case better and many a times we can just edit your code on JSFiddle to fix the issue right-away. I request you to brief more along with JSFiddle with your use-case if you have further queries or facing any issue.
— Vishwas R Team CanvasJS
thanks for the support, and I have an issue there. https://jsfiddle.net/canvasjs/0gohkjj3/ as per the code ,clicking on the set viewport button – we get the portion ,but when I click on reset button the i didin’t get the old graph. But the pan button i can drag the graph. Is there any solution?
my code is below– scaling.jsp
<%@page contentType="text/html" pageEncoding="UTF-8"%> <!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>Scaling </title> <script type="text/javascript"> window.onload = function(){ var chart = new CanvasJS.Chart("chartContainer", { zoomEnabled: true, zoomType: "xy", title:{ text: "Setting Viewport Based on User Input" }, data: [ { type: "line", dataPoints: [ { x: 10, y: 71 }, { x: 20, y: 55}, { x: 30, y: 50 }, { x: 40, y: 65 }, { x: 50, y: 95 }, { x: 60, y: 68 }, { x: 70, y: 28 }, { x: 80, y: 34 }, { x: 90, y: 14} ] } ] }); chart.render(); var setButton=document.getElementById("setViewports"); var xMin=document.getElementById("xMinimum"); var xMax=document.getElementById("xMaximum"); setButton.addEventListener("click",setViewports); function setViewports(){ alert(xMax.value); alert(xMin.value); if(xMax.value) chart.axisX[0].set("viewportMaximum", xMax.value); else chart.axisX[0].set("viewportMaximum",null); if(xMin.value) chart.axisX[0].set("viewportMinimum", xMin.value); else chart.axisX[0].set("viewportMinimum",null); }; }; //var button=document.getElementById("setViewports"); </script> </head> <body> <script type="text/javascript" src="https://cdn.canvasjs.com/canvasjs.min.js"></script> <div id="chartContainer" style="height: 400px; width: 80%;"></div> <br><br> <div> X Min : <input id="xMinimum" type="text" placeholder="Enter X Minimum" > X Max : <input id="xMaximum" type="text" placeholder="Enter X Maximum" > <br> Y Min : <input id="yMinimum" type="text" placeholder="Enter Y Minimum" > Y Max : <input id="yMaximum" type="text" placeholder="Enter Y Maximum" > <button id="setViewports" type="button">Change Viewports</button> </div> </body> </html>
Setting viewportMinimum and viewportMaximum to null within rangeChanged will reset the chart as shown in this JSFiddle.
You must be logged in to reply to this topic. Login/Register