# Problems with chart node (multiple lines)

**URL:** <https://discourse.nodered.org/t/problems-with-chart-node-multiple-lines/16380>\
**Category:** General\
**Created:** [6 October 2019 10:29 UTC](https://discourse.nodered.org/t/problems-with-chart-node-multiple-lines/16380 "2019-10-06T10:29:46Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![WhiteLion](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/whitelion/32/12266_2.png) [@WhiteLion](https://discourse.nodered.org/u/WhiteLion)\
**Post date:** [6 October 2019 10:29 UTC](https://discourse.nodered.org/t/problems-with-chart-node-multiple-lines/16380/1 "2019-10-06T10:29:46Z")

</div>

I got no success with a chart, using multiple lines. Maybe some can help.  
This is what I have:  
[picture 1](http://puu.sh/EpnpD/3d9d380ace.png)  
[picture 2](http://puu.sh/EpnsP/9e08bab9e2.png)

```auto
var dataArray = [[]];
var seriesArray = []; 
var labelsArray = [""];

for (i=0; i< 5; i++) 
{
    var name = msg.payload[i].brand + " " + msg.payload[i].place + " " + msg.payload[i].street;
    var preis = parseFloat(msg.payload[i].diesel);
    var dateTime = Date.now();
    //var timestamp = Math.floor(dateTime / 1000);

    dataArray[0][i] = {"x":dateTime,"y":preis};
    seriesArray[i] = name;
    //node.send({payload: chart });
}

var chart = [{
    "series":seriesArray,
    "data":dataArray,
    "labels":labelsArray
}];

var chartMsg = {payload: chart};
return chartMsg;

```

Flow needs "Tankerkoenig" + API Id so may be its not so usefull for you:

```auto
[
    {
        "id": "97dfc7db.a3c4d",
        "type": "ui_chart",
        "z": "30b57812.5c8b38",
        "name": "Dieselpreise",
        "group": "107ce709.2e71e1",
        "order": 0,
        "width": "6",
        "height": "6",
        "label": "Diesel",
        "chartType": "line",
        "legend": "true",
        "xformat": "HH:mm:ss",
        "interpolate": "linear",
        "nodata": "Noch keine Daten vorhanden",
        "dot": true,
        "ymin": "1.00",
        "ymax": "2.00",
        "removeOlder": "72",
        "removeOlderPoints": "",
        "removeOlderUnit": "60",
        "cutout": 0,
        "useOneColor": false,
        "colors": [
            "#1f77b4",
            "#aec7e8",
            "#ff7f0e",
            "#2ca02c",
            "#98df8a",
            "#d62728",
            "#ff9896",
            "#9467bd",
            "#c5b0d5"
        ],
        "useOldStyle": false,
        "outputs": 1,
        "x": 1530,
        "y": 560,
        "wires": [
            []
        ]
    },
    {
        "id": "107ce709.2e71e1",
        "type": "ui_group",
        "z": "",
        "name": "wenzlaff.info",
        "tab": "7e68b62d.0b5fa",
        "disp": false,
        "width": "6",
        "collapse": false
    },
    {
        "id": "7e68b62d.0b5fa",
        "type": "ui_tab",
        "z": "",
        "name": "wenzlaff.info",
        "icon": "dashboard",
        "disabled": false,
        "hidden": false
    }
]

```

I am unsure whats wrong, since I see no big differences to the working version of @truglodite  
The chart should show a line for every entry of [seriesArray](http://puu.sh/EpnpD/3d9d380ace.png) and add a new entries without deleding the old once.  
Thanx for your help!

---

<div class="post-metadata">

**Author:** ![bakman2](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bakman2/32/6207_2.png) [@bakman2](https://discourse.nodered.org/u/bakman2)\
**Post date:** [6 October 2019 10:33 UTC](https://discourse.nodered.org/t/problems-with-chart-node-multiple-lines/16380/2 "2019-10-06T10:33:42Z")

</div>

Your code will not output multiple "series".  
The output should look [like this](https://github.com/node-red/node-red-dashboard/blob/master/Charts.md#line-charts-1) (3 lines in this example).

---

<div class="post-metadata">

**Author:** ![WhiteLion](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/whitelion/32/12266_2.png) [@WhiteLion](https://discourse.nodered.org/u/WhiteLion)\
**Post date:** [6 October 2019 11:49 UTC](https://discourse.nodered.org/t/problems-with-chart-node-multiple-lines/16380/3 "2019-10-06T11:49:48Z")

</div>

In the example are 3 lines / values:

```auto
"data": [
    [{ "x": 1504029632890, "y": 5 },
     { "x": 1504029636001, "y": 4 },
     { "x": 1504029638656, "y": 2 }
    ],
    ....

```

I ve one but the same structure (If I didn´t miss a thing)  
With one line I expected to set only one point BUT multiple lines. - for every entry in "series" one.  
But see what I got: [click](http://puu.sh/Eppzm/12aed81a56.png)  
There is only one line for first iteration. - Shouldn´t it be like I descriped ?

I would like to draw more values to the chart when I request the values next time without deleding the existing ones. - I guess that is another problem I have no solution for atm.

---

<div class="post-metadata">

**Author:** ![WhiteLion](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/whitelion/32/12266_2.png) [@WhiteLion](https://discourse.nodered.org/u/WhiteLion)\
**Post date:** [6 October 2019 21:14 UTC](https://discourse.nodered.org/t/problems-with-chart-node-multiple-lines/16380/4 "2019-10-06T21:14:09Z")

</div>

This is my solution for the problem(s):

Function node:

```auto
var sqr = 0.0;
var len = msg.payload.length;
for (i=0; i< len; i++) 
{
    var name = msg.payload[i].brand + " " + msg.payload[i].place + " " + msg.payload[i].street;
    var preis = parseFloat(msg.payload[i].diesel.toFixed(2));
    node.send({topic:msg.payload[i].brand + " / " + msg.payload[i].place,payload: preis.toFixed(2) });
    sqr+=preis;
}
node.send({topic:"DURCHSCHNITT",payload: (sqr/len).toFixed(2) });
return null;

```

flow could remain like posted.
