Home Forums Chart Support Scaling


Viewing 4 posts - 1 through 4 (of 4 total)
  • #27052

    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?



    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.
    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>
            <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",
                          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}
                 var setButton=document.getElementById("setViewports");
                 var xMin=document.getElementById("xMinimum");
                 var xMax=document.getElementById("xMaximum");
                 function setViewports(){
                           chart.axisX[0].set("viewportMaximum", xMax.value);
                           chart.axisX[0].set("viewportMinimum", xMin.value);
                //var button=document.getElementById("setViewports");
            <script type="text/javascript" src="https://cdn.canvasjs.com/canvasjs.min.js"></script>
            <div id="chartContainer" style="height: 400px; width: 80%;"></div>
              X Min : <input id="xMinimum" type="text" placeholder="Enter X Minimum" > 
              X Max : <input id="xMaximum" type="text" placeholder="Enter X Maximum" >
              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>


    Setting viewportMinimum and viewportMaximum to null within rangeChanged will reset the chart as shown in this JSFiddle.

    Vishwas R
    Team CanvasJS

Viewing 4 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic.