Search code examples
chartsnode-red

NodeRED : chart node does not show multiple lines?


I have a NodeRED flow setup with a chart node. In my function node I have a super simple code as following

var left = {payload : msg.payload.readResults[0].v };
var right = {payload : msg.payload.readResults[1].v };


return [[left,right]];

Now I have a debug node connected to both function node and chart node and was hoping the cart would output 2 lines(one for each result).

But all I see is just one line with one color and the debug node connected to the graph is outputting Arrays of multiple objects while the debug node connected to the function is outputting the numbers as I'm expecting.

What am I doing wrong here to get output of 2 lines(left and right variables) with different colors?

enter image description here

enter image description here


Solution

  • You need to add msg.topic values to each message so the chart node knows to assign the values to different datasets.

    As it is it will just plot both messages as if they are the same dataset.

    From the docs:

    Line charts

    To display two or more lines on the same chart then each msg must also contain topic property that identifies which data series it belongs to

    • for example:

      {topic:"temperature", payload:22}
      {topic:"humidity", payload:66}