Home Forums Chart Support Difference for two graph-lines

Difference for two graph-lines

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

    WR

    Dear All

    I want to calculate with two lines (or more) to create a new line

    suppose:
    line 1 gives Import of energy -> {3, 7, 9, 8}
    line 2 gives Used energy -> {2, 5, 10, 7}

    I’d like to get a resultset of

    line 3 = line1 – line 2
    Line 3 gives losses -> {1,2,-1,1}

    indexes are off course timebased

    How could I realise this, from within canvasjs?

    To get the data for those lines i use Influxdb

    With kind regards

    Ron

    • This topic was modified 3 years, 1 month ago by WR.
    #33609

    @kerrith,

    It is possible to create a new dataPoints array by summing up/subtracting each y value of the first 2 dataPoints array as shown below –

    function createThirdDataSeries() {
      for(var i = 0; i < dps1.length; i++) {
        dps3.push({x: dps1[i].x, y: dps1[i].y + dps2[i].y})
      }
    } 

    You can create a multi-series area chart by providing each of these dataPoints array as separate dataSeries.

    Kindly take a look at this JSFiddle for an example on creating a multi-series area chart with the third dataSeries being the sum of the first two dataSeries.

    dataseries displaying the sum of other dataseries

    Also, kindly take a look at this forum thread for your reference.

    ___________
    Adithya Menon
    Team CanvasJS

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

You must be logged in to reply to this topic.