Home Forums Chart Support plotting two lines

plotting two lines

Viewing 2 posts - 1 through 2 (of 2 total)
  • #27106

    Hello,

    I am working on plotting to lines on a graph from a json file. Having an issue with plotting the second line.

    json sample: [[0, 69.8, 53.0], [1, 69.8, 53.0], [2, 69.8, 53.0], [3, 69.8, 53.0]]

    <!DOCTYPE HTML>
    <html>
    <head>
    <script type="text/javascript" src="https://canvasjs.com/assets/script/jquery-1.11.1.min.js"></script>
    <script type="text/javascript" src="https://cdn.canvasjs.com/canvasjs.min.js"></script>
    <script type="text/javascript">
    window.onload = function () {
    var dataPoints = [];
    $.getJSON("data.json", function(data) {  
    	$.each(data, function(key, value){
    		dataPoints.push({x: value[0], y: parseInt(value[1])});
    		dataPoints2.push({x: value[0], y: parseInt(value[2])});
    	});
    	var chart = new CanvasJS.Chart("chartContainer",{
    		title:{
    			text:"Plotting Temperature and Humidity"
    		},
    		data: [{
    			type: "line",
    			dataPoints : dataPoints,},	
    			{
    			type: "line",
    			dataPoints : dataPoints2,
    	
    		}]
    	});
    	chart.render();
    });
    }
    </script>
    
    </head>
    <body>
    <div id="chartContainer" style="height: 300px; width: 100%;"></div>
    </body>
    </html>
    
    #27111

    @solidsandwich,

    There seems to be issue with variable declaration. Declaring dataPoints2 should work fine in this case. Please take a look at this JSFiddle for working code.

    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

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

You must be logged in to reply to this topic.