Home Forums Chart Support Creating line graph from array of coordinates

Creating line graph from array of coordinates

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

    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.

    #15840

    @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.

    populating chart using array

    ___________
    Indranil Deo
    Team CanvasJS

    • This reply was modified 7 years, 4 months ago by Indranil.
    • This reply was modified 7 years, 4 months ago by Indranil.
Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.