Home Forums Chart Support Call 2 arrays in the datapoints[ ]

Call 2 arrays in the datapoints[ ]

Viewing 3 posts - 1 through 3 (of 3 total)
  • #11431

    Hi, I have 2 arrays which is dynamically being made with some algorithm and it all depends on the user inputs.

    I want to plot each of the arrays in respective axis of the graph. That is call the 1 array(with dates) for the x-axis values and 1 array with numbers for y-axis.

    So how do I call the 2 arrays in the datapoints[ ] ?

    #11432

    Elina,

    To render the dataPoint with one array for x value and other array for y values, you need to parse the arrays according to data format accepted by CanvasJS. Check out the below code snippet for parsing the arrays.

    function parseDataPoints() {
      for (var i = dps.length; i < dateArray.length; i++)
        dps.push({
          x: new Date(dateArray[i]),
          y: numberArray[i]
        });
    };

    Please take a look at this JSFiddle for complete code sample.

    Chart with user input data and parsing from array

    —-
    Sanjoy Debnath
    Team CanvasJS

    #11436

    Thanks Sanjoy,

    The code works perfectly. Thanks you so much. You are the best!

    Regards,
    Elina

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

You must be logged in to reply to this topic.