# Graph with stored data

**URL:** <https://discourse.nodered.org/t/graph-with-stored-data/5956>\
**Category:** Dashboard\
**Created:** [19 December 2018 09:58 UTC](https://discourse.nodered.org/t/graph-with-stored-data/5956 "2018-12-19T09:58:25Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![Giacomino](https://avatars.discourse-cdn.com/v4/letter/g/ba8739/32.png) [@Giacomino](https://discourse.nodered.org/u/Giacomino)\
**Post date:** [19 December 2018 09:58 UTC](https://discourse.nodered.org/t/graph-with-stored-data/5956/1 "2018-12-19T09:58:25Z")

</div>

Hi everybody,  
I'm pretty new to NodeRed. I have a problem with making graph with data stored. My data are in Json format like :{"t":"2018-12-12T15:00:00.000Z","temp\_in\_cooling":"320.00"}. i Can make graph using directly these data by means of $.feeds.{"x":t, "y" :temp\_in\_cooling} with the exchange node. In this way i get an array of object (objects are x and y}. The problem is that i have so many others data for each time stamp that i need to process before (i have to make some moltiplications and if statement, so with a for loop i convert, the data from string to numbers and i do my operations and finally i gat an array. but i can't display that array in a graph, i guess i'd have to convert that array in a array of object or something like that.

This what i get if i create an array of number for processing the data:

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/2/25f2399f4330a654e088eeac2baa3770742fb4d1.png)

Can anybody help me please?  
Thank you!

---

<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:** [19 December 2018 10:10 UTC](https://discourse.nodered.org/t/graph-with-stored-data/5956/2 "2018-12-19T10:10:24Z")

</div>

First thing is to explore the documentation [Chart with stored data](https://github.com/node-red/node-red-dashboard/blob/master/Charts.md#stored-data)  
Format of the data to be feed to chart must be done correctly. So investigate, try and ask when you cant understand something.

---

<div class="post-metadata">

**Author:** ![Giacomino](https://avatars.discourse-cdn.com/v4/letter/g/ba8739/32.png) [@Giacomino](https://discourse.nodered.org/u/Giacomino)\
**Post date:** [20 December 2018 11:27 UTC](https://discourse.nodered.org/t/graph-with-stored-data/5956/3 "2018-12-20T11:27:54Z")

</div>

Ok, i know which format i should use, the point is that i do not understand how to convert the format i have to the one i have to have to feed the chart! I should switch from number array to 'object' array? Or? I've tried everything..  
Thank's

---

<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:** [20 December 2018 16:24 UTC](https://discourse.nodered.org/t/graph-with-stored-data/5956/4 "2018-12-20T16:24:58Z")

</div>

Show us what have you tried. Share the function or flow where you try to manage your data into correct format for chart.  
Also, there is many discussions have been done about same topic. Have you searched and read them? Many of them have almost ready to use solutions

---

<div class="post-metadata">

**Author:** ![kapusticka](https://avatars.discourse-cdn.com/v4/letter/k/b4bc9f/32.png) [@kapusticka](https://discourse.nodered.org/u/kapusticka)\
**Post date:** [25 October 2020 06:24 UTC](https://discourse.nodered.org/t/graph-with-stored-data/5956/5 "2020-10-25T06:24:48Z")

</div>

Hi everyone. Can you help me please?First i am sorry for my english. 🙂

I would like to create a graph from my "smart home unit Athom" Homey. I successfully create a json file. but i have a trouble with reading of this file to graph. Can you help how can i do it or where is my issue? Debugger gives me a error: "ReferenceError: data is not defined (line 9, col 42)".  
Thanks for your help.

 ![Snímka obrazovky 2020-10-25 o 8.22.43](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/9/6/96f4d4055cd3625a2eb9872a92d0daa2972e9f12.jpeg) ![Snímka obrazovky 2020-10-25 o 8.22.34](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/9/c/9c15582dca829b09ee3cc53f1b1844ac434a299d.png)

Here is my nodes:

```auto
[{"id":"57fda489.419f3c","type":"mqtt in","z":"dc26b425.e05be8","name":"coffeeplug/measure-power","topic":"homie/homey-5ac5f38e42b2c4296e150d77/coffeeplug/measure-power","qos":"2","datatype":"auto","broker":"f18ffc79.bc2648","x":260,"y":600,"wires":[["c44b087.0631e78","4aee7d24.6bc194","73880317.157a24"]]},{"id":"73880317.157a24","type":"function","z":"dc26b425.e05be8","name":"Modify Payload","func":"var today = new Date();\nvar date = today.getFullYear()+'-'+(today.getMonth()+1)+'-'+today.getDate()+',';\nvar time = today.getHours() + \":\" + today.getMinutes() + \":\" + today.getSeconds();\nvar dateTime = date+' '+time;\nvar data=[];\nvar series=[\"Data\"];\nvar labels=[\"Labels\"];\nvar values = ({\n \"dateTime\": dateTime,\n \"payload\": msg.payload,\n}); \n\nmsg.payload = [{series,values,labels}];\nreturn msg;","outputs":1,"noerr":0,"x":790,"y":590,"wires":[["c6ec3305.53a418"]]},{"id":"c6ec3305.53a418","type":"json","z":"dc26b425.e05be8","name":"","property":"dateTime,payload","action":"","pretty":false,"x":950,"y":590,"wires":[["5ba76edf.d9686"]]},{"id":"5ba76edf.d9686","type":"file","z":"dc26b425.e05be8","name":"","filename":"/home/pi/logs/test.log","appendNewline":true,"createDir":true,"overwriteFile":"false","encoding":"none","x":1120,"y":590,"wires":[["3b46a832.6825a"]]},{"id":"3b46a832.6825a","type":"change","z":"dc26b425.e05be8","name":"Data Array","rules":[{"t":"set","p":"data","pt":"msg","to":"$.values.{\"dateTime\":dateTime, \"payload\":data}","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":1320,"y":590,"wires":[["8983f082.d731d8"]]},{"id":"8983f082.d731d8","type":"function","z":"dc26b425.e05be8","name":"Setup payload","func":"series = [];\npayload = [];\nlabels = [];\n\nseries.push(\"Data\");\npayload.push(\"Values\");\nlabels.push(\"Label\");\n\nmsg.payload = [{\"series\":series,\"Values\":data,\"labels\":labels}];\n\nreturn msg;","outputs":1,"noerr":0,"x":1510,"y":590,"wires":[["e8d22e12.54e158","b723c505.8152a8"]]},{"id":"e8d22e12.54e158","type":"debug","z":"dc26b425.e05be8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","x":1730,"y":540,"wires":[]},{"id":"b723c505.8152a8","type":"ui_chart","z":"dc26b425.e05be8","name":"","group":"2cdaed12.b6920a","order":3,"width":0,"height":0,"label":"payload","chartType":"line","legend":"false","xformat":"HH:mm","interpolate":"linear","nodata":"","dot":true,"ymin":"","ymax":"","removeOlder":"1","removeOlderPoints":"","removeOlderUnit":"3600","cutout":0,"useOneColor":false,"useUTC":false,"colors":["#1f77b4","#aec7e8","#ff7f0e","#2ca02c","#98df8a","#d62728","#ff9896","#9467bd","#c5b0d5"],"useOldStyle":false,"outputs":1,"x":1710,"y":610,"wires":[[]]},{"id":"f18ffc79.bc2648","type":"mqtt-broker","z":"","name":"Homey MQTT","broker":"192.168.1.4","port":"1883","tls":"","clientid":"","usetls":true,"compatmode":true,"keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthRetain":"false","birthPayload":"","closeTopic":"","closeQos":"0","closeRetain":"false","closePayload":"","willTopic":"","willQos":"0","willRetain":"false","willPayload":""},{"id":"2cdaed12.b6920a","type":"ui_group","z":"","name":"Coffee","tab":"57d4c334.8436d4","order":5,"disp":true,"width":4,"collapse":false},{"id":"57d4c334.8436d4","type":"ui_tab","z":"","name":"Energy","icon":"fa-1x fa-bolt","order":3,"disabled":false,"hidden":false}]

```

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [25 October 2020 08:31 UTC](https://discourse.nodered.org/t/graph-with-stored-data/5956/6 "2020-10-25T08:31:47Z")

</div>

Hi @kapusticka welcome to the forum.

First things first, in order to make code more readable and importable it is important to surround your code with three backticks  
`````  
`like this`  
`````

You can edit and correct your post by clicking the pencil icon.

See this post for more details - [How to share code or flow json](https://discourse.nodered.org/t/how-to-share-code-or-flow-json/506)

> [@kapusticka](#):
>
> data is not defined (line 9, col 42)".

Pretty much as the error says, `data` is undefined yet you attempt to assign`data` to "values"

If you are passing data into the function then it's probably in msg.data or msg.payload.

Add a debug node (set to show complete message) BEFORE the function where the error occurs. Have a look for where your data is.

Ps, as you are new to node red, I recommend watching this playlist: [Node-RED Essentials](https://www.youtube.com/playlist?list=PLyNBB9VCLmo1hyO-4fIZ08gqFcXBkHy-6). The videos are done by the developers of node-red. They're nice & short and to the point. You will understand a whole lot more in about 1 hour. A small investment for a lot of gain.

---

<div class="post-metadata">

**Author:** ![kapusticka](https://avatars.discourse-cdn.com/v4/letter/k/b4bc9f/32.png) [@kapusticka](https://discourse.nodered.org/u/kapusticka)\
**Post date:** [25 October 2020 08:46 UTC](https://discourse.nodered.org/t/graph-with-stored-data/5956/7 "2020-10-25T08:46:16Z")

</div>

i have been correct my "code". if you can, can you edit my code and post node to this forum? thanks a lot.

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [25 October 2020 08:49 UTC](https://discourse.nodered.org/t/graph-with-stored-data/5956/8 "2020-10-25T08:49:21Z")

</div>

Did you add debug node?

> [@Steve-Mcl](#):
>
> Add a debug node (set to show complete message) BEFORE the function where the error occurs

Show us your data in the debug message.

---

<div class="post-metadata">

**Author:** ![kapusticka](https://avatars.discourse-cdn.com/v4/letter/k/b4bc9f/32.png) [@kapusticka](https://discourse.nodered.org/u/kapusticka)\
**Post date:** [25 October 2020 08:55 UTC](https://discourse.nodered.org/t/graph-with-stored-data/5956/9 "2020-10-25T08:55:12Z")

</div>

![Snímka obrazovky 2020-10-25 o 9.54.31](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/9/c/9c0228413005c45795c2fd73ddc4f347f3389023.png)

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [25 October 2020 09:06 UTC](https://discourse.nodered.org/t/graph-with-stored-data/5956/10 "2020-10-25T09:06:54Z")

</div>

I can't see any data in those messages. Where is the graph data? I assume you are sending the graph data into the function where you are getting the error? Can you show me only the debug message for the node BEFORE

PS, please give names or numbers to those debug nodes so I can see which one is which in the debug panel. Ta.

---

<div class="post-metadata">

**Author:** ![kapusticka](https://avatars.discourse-cdn.com/v4/letter/k/b4bc9f/32.png) [@kapusticka](https://discourse.nodered.org/u/kapusticka)\
**Post date:** [25 October 2020 09:09 UTC](https://discourse.nodered.org/t/graph-with-stored-data/5956/11 "2020-10-25T09:09:04Z")

</div>

may i send you a nodes link again? it can helps.

---

<div class="post-metadata">

**Author:** ![kapusticka](https://avatars.discourse-cdn.com/v4/letter/k/b4bc9f/32.png) [@kapusticka](https://discourse.nodered.org/u/kapusticka)\
**Post date:** [25 October 2020 09:10 UTC](https://discourse.nodered.org/t/graph-with-stored-data/5956/12 "2020-10-25T09:10:08Z")

</div>

graph data are saved in /home/log/.test.log on my raspberry pi. in the middle of my picture

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [25 October 2020 09:10 UTC](https://discourse.nodered.org/t/graph-with-stored-data/5956/13 "2020-10-25T09:10:44Z")

</div>

For now, I only need to see what comes out of the debug node that comes from the "data array" node

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [25 October 2020 09:16 UTC](https://discourse.nodered.org/t/graph-with-stored-data/5956/15 "2020-10-25T09:16:10Z")

</div>

I am not at a computer so can only help you if you provide certain information.

As I said several times now...

> [@Steve-Mcl](#):
>
> I only need to see what comes out of the debug node that comes from the "data array" node

---

<div class="post-metadata">

**Author:** ![kapusticka](https://avatars.discourse-cdn.com/v4/letter/k/b4bc9f/32.png) [@kapusticka](https://discourse.nodered.org/u/kapusticka)\
**Post date:** [25 October 2020 09:20 UTC](https://discourse.nodered.org/t/graph-with-stored-data/5956/16 "2020-10-25T09:20:55Z")

</div>

okay. now i understand. this comes out from data array.

1. 
  1. 2020, 10:17:02[node: 5fb71f4f.cde0a](http://192.168.1.12:1880/#)homie/homey-5ac5f38e42b2c4296e150d77/coffeeplug/measure-power : msg.payload : array[1]

array[1]

0: object

series: array[1]

0: "Data"

values: object

dateTime: "2020-10-25, 9:17:2"

payload: "0.9"

labels: array[1]

0: "Labels"

 ![Snímka obrazovky 2020-10-25 o 10.17.56](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/e/4/e400d054e3459ef3d6e0f850f7af2d1eb04d97e1.png)

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [25 October 2020 09:30 UTC](https://discourse.nodered.org/t/graph-with-stored-data/5956/17 "2020-10-25T09:30:30Z")

</div>

As i said earler,

> [@Steve-Mcl](#):
>
> If you are passing data into the function then it's probably in msg.data

Proof...

#### here you move data into `msg.data`

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

#### so in the next function you should use `msg.data`

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

---

<div class="post-metadata">

**Author:** ![kapusticka](https://avatars.discourse-cdn.com/v4/letter/k/b4bc9f/32.png) [@kapusticka](https://discourse.nodered.org/u/kapusticka)\
**Post date:** [25 October 2020 09:40 UTC](https://discourse.nodered.org/t/graph-with-stored-data/5956/18 "2020-10-25T09:40:24Z")

</div>

now i receive bug from payload graph "bad data injection"

 ![Snímka obrazovky 2020-10-25 o 10.38.18](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/b/e/be9cafd1ddca5a5604178bd974213529e5e2dd1c.png) ![Snímka obrazovky 2020-10-25 o 10.36.48](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/1/d/1d0502b9819226e754915ec2b9722703111bd4d8.png)

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [25 October 2020 09:42 UTC](https://discourse.nodered.org/t/graph-with-stored-data/5956/19 "2020-10-25T09:42:10Z")

</div>

On a slightly different note, I am not convinced your chart JSON format is correct.

Did you read the built in help and [this](https://github.com/node-red/node-red-dashboard/blob/master/Charts.md)

Your chart data should look like this..

```auto
[{
"series": ["A", "B", "C"],
"data": [
    [{ "x": 1504029632890, "y": 5 },
     { "x": 1504029636001, "y": 4 },
     { "x": 1504029638656, "y": 2 }
    ],
    [{ "x": 1504029633514, "y": 6 },
     { "x": 1504029636622, "y": 7 },
     { "x": 1504029639539, "y": 6 }
    ],
    [{ "x": 1504029634400, "y": 7 },
     { "x": 1504029637959, "y": 7 },
     { "x": 1504029640317, "y": 7 }
    ]
],
"labels": [""]
}]

```

but you seem to be adding `series` `Values` and `labels` to the payload object when it should be `series` `data` and `labels` according to the documentation.

You should change your function node `"Values" : msg.data` to `"data" : msg.data`

---

<div class="post-metadata">

**Author:** ![kapusticka](https://avatars.discourse-cdn.com/v4/letter/k/b4bc9f/32.png) [@kapusticka](https://discourse.nodered.org/u/kapusticka)\
**Post date:** [25 October 2020 10:34 UTC](https://discourse.nodered.org/t/graph-with-stored-data/5956/20 "2020-10-25T10:34:32Z")

</div>

still having errors. 25. 10. 2020, 11:32:38[node: Setup payload](http://192.168.1.12:1880/#)function : (error)

"ReferenceError: data is not defined (line 6, col 1)"

 ![Snímka obrazovky 2020-10-25 o 11.33.52](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/0/2/0286eccf99e93042576eaa3bd396e8a4d29a11b2.png) ![Snímka obrazovky 2020-10-25 o 11.33.42](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/e/9/e9b3b4a0ad99b0b21419d14b6bf6bb7a09cdb285.jpeg)

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [25 October 2020 10:42 UTC](https://discourse.nodered.org/t/graph-with-stored-data/5956/21 "2020-10-25T10:42:43Z")

</div>

> [@kapusticka](#):
>
> "ReferenceError: data is not defined (line 6, col 1)"

You fixed this once all ready.

Any way, as i said before....

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/2/1/2132bb69d5adfa2e2495a41c1514cc81734e0611.png)

note the missing **`msg.`** part

[Next page](https://discourse.nodered.org/t/graph-with-stored-data/5956.md?page=2)
