# How a line chart shows a payload of 700 data separated by comma?

**URL:** https://discourse.nodered.org/t/how-a-line-chart-shows-a-payload-of-700-data-separated-by-comma/42526
**Category:** Dashboard
**Created:** [12 March 2021 05:43 UTC](https://discourse.nodered.org/t/how-a-line-chart-shows-a-payload-of-700-data-separated-by-comma/42526 "2021-03-12T05:43:39Z")
**Posts on this page:** 13
**Page:** 1

<div class="post-metadata">

### Author: ![AK51](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ak51/32/8438_2.png) [@AK51](https://discourse.nodered.org/u/AK51)
#### Post date: [12 March 2021 05:43 UTC](https://discourse.nodered.org/t/how-a-line-chart-shows-a-payload-of-700-data-separated-by-comma/42526/1 "2021-03-12T05:43:40Z")

</div>

Hi,

I have a payload of 700 data separated by comma. I would like to show them in a line chart. How should I set the chart node? Note: The chart will be updated if the new payload comes in.

Thx  
8526,7846,7855,7879,7649,7600,7927,7772,7411,7600,7689,7659,7760,7826,7608,7821,7866,7998,7812,7748,7698,7810,8205,8111,7702,7859,8134,7976,7539,7771,7960,7999,8082,7815,8914,8525,8301,8239,7988,8091,7889,7929,7778,7905,7804,7797,7978,8002,7863,8014,8204,8576,9352,10188,10025,9453,9046,9498,9274,9357,9381,9301,8897,8581,8505,8657,8723,9035,9658,9808,9191,7364,7486,8004,8098,5932,7467,8875,8422,8291,8057,7370,6290,5439,5404,5548,5792,6144,6554,6559,7148,6096,5595,5842,5420,5161,4907,4797,4907,4875,4735,4383,4348,4573,5383,6869,8300,9661,10365,10992,11374,11211,11143,12114,12834,12863,23061,33937,16510,17189,11958,8871,7758,6992,12194,14164,12654,11075,9977,9885,9455,9855,10650,11235,10975,10513,10576,10414,11024,12271,10813,7878,10520,10025,9022,8569,8262,7554,6623,6069,6000,6822,7802,8718,8802,8012,6150,9654,9148,10577,11737,13397,14372,15947,16254,16959,17716,18130,17792,26737,34973,29777,21057,26178,22241,16104,19420,15130,11475,8212,8963,8547,8392,8976,9315...

---

<div class="post-metadata">

### Author: ![hotNipi](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/hotnipi/32/383_2.png) [@hotNipi](https://discourse.nodered.org/u/hotNipi)
#### Post date: [12 March 2021 06:12 UTC](https://discourse.nodered.org/t/how-a-line-chart-shows-a-payload-of-700-data-separated-by-comma/42526/2 "2021-03-12T06:12:41Z")

</div>

Line chart is a line, drawn between points. Point is two-dimensional object. ` {x;y}` You have only one dimension. Let's say those numbers represent value, which most commonly goes to vertical axis `y` but you are missing the horizontal component `x` (most commonly the time)  
Line chart can be created only if you add some value for `x`, every next a bit bigger than previous.  
For live data, if new value is sent to chart, the `x` (timestamp) is created automatically so you can send only the value. But for historical data, you'll need to store values with timestamps.

.

---

<div class="post-metadata">

### Author: ![AK51](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ak51/32/8438_2.png) [@AK51](https://discourse.nodered.org/u/AK51)
#### Post date: [12 March 2021 06:54 UTC](https://discourse.nodered.org/t/how-a-line-chart-shows-a-payload-of-700-data-separated-by-comma/42526/3 "2021-03-12T06:54:17Z")

</div>

Hi,

What the output payload should be?  
Thanks.

---

<div class="post-metadata">

### Author: ![hotNipi](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/hotnipi/32/383_2.png) [@hotNipi](https://discourse.nodered.org/u/hotNipi)
#### Post date: [12 March 2021 06:57 UTC](https://discourse.nodered.org/t/how-a-line-chart-shows-a-payload-of-700-data-separated-by-comma/42526/4 "2021-03-12T06:57:33Z")

</div>

Maybe you'll get the answer from this document: [node-red-dashboard/Charts.md at master · node-red/node-red-dashboard · GitHub](https://github.com/node-red/node-red-dashboard/blob/master/Charts.md)

---

<div class="post-metadata">

### Author: ![AK51](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ak51/32/8438_2.png) [@AK51](https://discourse.nodered.org/u/AK51)
#### Post date: [12 March 2021 08:39 UTC](https://discourse.nodered.org/t/how-a-line-chart-shows-a-payload-of-700-data-separated-by-comma/42526/5 "2021-03-12T08:39:06Z")

</div>

Hi,

I have made the payload to be this (just 10 data for testing). But I am not sure the setting in the line chart node. Thanks

 ![chart](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/7/9/794b6b1ce65f34612a0e0df6c49089b40adf6db3.jpeg)

"[{"data":[{"x":2,"y":10005},{"x":3,"y":9223},{"x":4,"y":9007},{"x":5,"y":8522},{"x":6,"y":8489},{"x":7,"y":9283},{"x":8,"y":8902},{"x":9,"y":8790},{"x":10,"y":8403},{"x":11,"y":8036}],"labels": [""]}]"

---

<div class="post-metadata">

### Author: ![hotNipi](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/hotnipi/32/383_2.png) [@hotNipi](https://discourse.nodered.org/u/hotNipi)
#### Post date: [12 March 2021 08:54 UTC](https://discourse.nodered.org/t/how-a-line-chart-shows-a-payload-of-700-data-separated-by-comma/42526/6 "2021-03-12T08:54:33Z")

</div>

The debug tab says, that data has bad format.

Correct will be

```auto
msg.payload = [
    {
        "series": ["A"],
        "data": [
            [{"x":2,"y":10005},
            {"x":3,"y":9223},
            {"x":4,"y":9007},
            {"x":5,"y":8522},
            {"x":6,"y":8489},
            {"x":7,"y":9283},
            {"x":8,"y":8902},
            {"x":9,"y":8790},
            {"x":10,"y":8403},
            {"x":11,"y":8036}
            ]
        ],
        "labels": [""]
    }
]
return msg

```

---

<div class="post-metadata">

### Author: ![AK51](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ak51/32/8438_2.png) [@AK51](https://discourse.nodered.org/u/AK51)
#### Post date: [12 March 2021 09:11 UTC](https://discourse.nodered.org/t/how-a-line-chart-shows-a-payload-of-700-data-separated-by-comma/42526/7 "2021-03-12T09:11:51Z")

</div>

I have made the same format but still can not show the line.... Sorry to bother you but I wonder if my chart node setting is correct. Thx  
Thanks.

[{"series": ["AccT"],"data":[[{"x":2,"y":9296},{"x":3,"y":7829},{"x":4,"y":7880},{"x":5,"y":7660},{"x":6,"y":7921},{"x":7,"y":7657},{"x":8,"y":7891},{"x":9,"y":7813},{"x":10,"y":7876},{"x":11,"y":7909}]],"labels": [""]}]

Better format to this (Same)  
[  
{  
"series": ["AccT"],  
"data":[  
[{"x":2,"y":9296},  
{"x":3,"y":7829},  
{"x":4,"y":7880},  
{"x":5,"y":7660},  
{"x":6,"y":7921},  
{"x":7,"y":7657},  
{"x":8,"y":7891},  
{"x":9,"y":7813},  
{"x":10,"y":7876},  
{"x":11,"y":7909}  
]  
],  
"labels": [""]  
}  
]

 ![chart1](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/4/0/40644071f86a3c157570b850460261b0d6ad66a9.jpeg)

---

<div class="post-metadata">

### Author: ![hotNipi](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/hotnipi/32/383_2.png) [@hotNipi](https://discourse.nodered.org/u/hotNipi)
#### Post date: [12 March 2021 09:23 UTC](https://discourse.nodered.org/t/how-a-line-chart-shows-a-payload-of-700-data-separated-by-comma/42526/8 "2021-03-12T09:23:01Z")

</div>

With your settings I get this  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/6/7/6771e33cec4d1b2acc7aa6092cd4a30a1e9f027f.jpeg)

---

<div class="post-metadata">

### Author: ![hotNipi](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/hotnipi/32/383_2.png) [@hotNipi](https://discourse.nodered.org/u/hotNipi)
#### Post date: [12 March 2021 09:30 UTC](https://discourse.nodered.org/t/how-a-line-chart-shows-a-payload-of-700-data-separated-by-comma/42526/9 "2021-03-12T09:30:36Z")

</div>

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/6/e/6e272820bf6bdb61904df0071f046579af9f5aa7.png)

`msg.payload` is `string`. That's why you don't get anything.  
It should be an array.

```auto
msg.payload = [
    {
        "series": ["A"],
        "data": [ .....

```

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/8/a/8a7c700239b26d894b53d6a4ecc59a299a74d469.png)

---

<div class="post-metadata">

### Author: ![Simon01011](https://avatars.discourse-cdn.com/v4/letter/s/e68b1a/32.png) [@Simon01011](https://discourse.nodered.org/u/Simon01011)
#### Post date: [12 March 2021 09:51 UTC](https://discourse.nodered.org/t/how-a-line-chart-shows-a-payload-of-700-data-separated-by-comma/42526/10 "2021-03-12T09:51:04Z")

</div>

You can simply put a function node before your chart with

```auto
msg.payload = JSON.parse(msg.payload);
return msg;

```

That will do the conversion

---

<div class="post-metadata">

### Author: ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)
#### Post date: [12 March 2021 09:52 UTC](https://discourse.nodered.org/t/how-a-line-chart-shows-a-payload-of-700-data-separated-by-comma/42526/11 "2021-03-12T09:52:49Z")

</div>

Though probably better to build it as an object in the first place. You can convert your input (assuming that is a string too) into an array by adding a `[` on the front and a `]` on the end and feeding it through a JSON node. Then you can build your payload much easier that using string manipulation, which I assume you have been doing.

---

<div class="post-metadata">

### Author: ![AK51](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ak51/32/8438_2.png) [@AK51](https://discourse.nodered.org/u/AK51)
#### Post date: [12 March 2021 09:59 UTC](https://discourse.nodered.org/t/how-a-line-chart-shows-a-payload-of-700-data-separated-by-comma/42526/12 "2021-03-12T09:59:18Z")

</div>

It is working now.

Thanks all. :\>

![chart_working](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/7/4/746179263779489e245a7777b7853946c1a7f7d9.jpeg)

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)
#### Post date: [11 April 2021 10:00 UTC](https://discourse.nodered.org/t/how-a-line-chart-shows-a-payload-of-700-data-separated-by-comma/42526/13 "2021-04-11T10:00:01Z")

</div>

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
