You must be logged in to post your query.
Home › Forums › Chart Support › Creating line graph from array of coordinates
I’m trying to create a line graph from two arrays, one containing x-coordinates, and one containing y-coordinates. Can anyone show an example of how to do this?
I’ve been trying to adapt the for loop to create random points in the stress test graphs but can’t get anything to work so far, any help would be appreciated. Thanks.
@harryroberts,
To populate chart from array you can loop through the array and parse it to the format accepted by CanvasJS before passing to the chart options as shown below –
var x1 = [1, 2, 3]; var y1 = [4, 7, 4]; var dataPoints = []; for (var i = 0; i < 3; i++) { dataPoints.push({ x: x1[i], y: y1[i] }); }
Please take a look at this JSFiddle for an example.
___________ Indranil Deo Team CanvasJS
You must be logged in to reply to this topic. Login/Register