# Problem in Chart sensor data

**URL:** <https://discourse.nodered.org/t/problem-in-chart-sensor-data/23920>\
**Category:** General\
**Created:** [30 March 2020 19:16 UTC](https://discourse.nodered.org/t/problem-in-chart-sensor-data/23920 "2020-03-30T19:16:57Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![tarahi](https://avatars.discourse-cdn.com/v4/letter/t/9de053/32.png) [@tarahi](https://discourse.nodered.org/u/tarahi)\
**Post date:** [30 March 2020 19:16 UTC](https://discourse.nodered.org/t/problem-in-chart-sensor-data/23920/1 "2020-03-30T19:16:57Z")

</div>

Hi friend,  
I want to show my sensor data in a chart, x axis is time and y axis is temperature.  
the simplified flow is this :

```auto
[{"id":"4b14130c.2a0eec","type":"tab","label":"Chart","disabled":false,"info":""},{"id":"207dfb39.fb8b34","type":"ui_chart","z":"4b14130c.2a0eec","name":"Chart","group":"b5de326a.9358d","order":1,"width":20,"height":7,"label":"chart","chartType":"line","legend":"false","xformat":"HH:mm:ss","interpolate":"linear","nodata":"","dot":false,"ymin":"","ymax":"","removeOlder":1,"removeOlderPoints":"","removeOlderUnit":"86400","cutout":0,"useOneColor":false,"colors":["#1f77b4","#aec7e8","#ff7f0e","#2ca02c","#98df8a","#d62728","#ff9896","#9467bd","#c5b0d5"],"useOldStyle":false,"outputs":1,"x":610,"y":60,"wires":[[]]},{"id":"34364967.3b9266","type":"inject","z":"4b14130c.2a0eec","name":"Select","topic":"SELECT temp1,time FROM DHT2","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":110,"y":100,"wires":[["45fe79fe.4f9348"]]},{"id":"45fe79fe.4f9348","type":"sqlite","z":"4b14130c.2a0eec","mydb":"4cea1d08.1b70d4","sqlquery":"msg.topic","sql":"","name":"Database","x":260,"y":60,"wires":[["7dc120d8.fd01e"]]},{"id":"7dc120d8.fd01e","type":"function","z":"4b14130c.2a0eec","name":"Fill Chart Array","func":"var chart={};\ndata=msg.payload[0];\nchart.labels = [\"Temperature (˚c)\"];\nchart.series = [''];\nchart.data = [\n [data.temp1],\n [data.time],\n ];\nmsg.payload = [{\n \"series\": [\"A\"],\n \"labels\": [\"temp\"],\n \"data\": [[{\n \"x\": data.time,\n \"y\": data.temp1\n \n }]]\n}]\nreturn {payload:[chart]};","outputs":1,"noerr":0,"x":420,"y":100,"wires":[["207dfb39.fb8b34","8f6c5c9e.bbdec"]]},{"id":"8f6c5c9e.bbdec","type":"debug","z":"4b14130c.2a0eec","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":630,"y":140,"wires":[]},{"id":"b5de326a.9358d","type":"ui_group","z":"","name":"Result","tab":"4ef1815c.0f197","order":2,"disp":true,"width":20,"collapse":false},{"id":"4cea1d08.1b70d4","type":"sqlitedb","z":"","db":"/home/pi/Documents/Sqlite DB/dht2-tbl","mode":"RWC"},{"id":"4ef1815c.0f197","type":"ui_tab","z":"","name":"Chart","icon":"dashboard","order":7,"disabled":false,"hidden":false}]

```

 ![Untitled](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/6/a/6a31c23484aa60b477cd6bb66c17dc6ffe9411d4.jpeg)

I see noting in chart ... so what's the problem ?!

---

<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:** [30 March 2020 20:18 UTC](https://discourse.nodered.org/t/problem-in-chart-sensor-data/23920/2 "2020-03-30T20:18:40Z")

</div>

See this link for how the data should be formatted. The `data` array should have one entry for each series, and each of those elements is itself an array of data points containing x and y values.

> <https://github.com/node-red/node-red-dashboard/blob/master/Charts.md>

---

<div class="post-metadata">

**Author:** ![tarahi](https://avatars.discourse-cdn.com/v4/letter/t/9de053/32.png) [@tarahi](https://discourse.nodered.org/u/tarahi)\
**Post date:** [31 March 2020 08:34 UTC](https://discourse.nodered.org/t/problem-in-chart-sensor-data/23920/3 "2020-03-31T08:34:58Z")

</div>

According to this topic :  
[https://discourse.nodered.org/t/json-data-to-dashboard-chart/3792/2](https://discourse.nodered.org/t/json-data-to-dashboard-chart/3792/2)  
now I have this flow :

```auto
[{"id":"49e47d1f.99ea34","type":"tab","label":"Flow 1","disabled":false,"info":""},{"id":"d238570a.1d0888","type":"ui_chart","z":"49e47d1f.99ea34","name":"","group":"bca4ac1c.3f733","order":0,"width":0,"height":0,"label":"{{msg.label}}","chartType":"line","legend":"true","xformat":"HH:mm:ss","interpolate":"linear","nodata":"","dot":false,"ymin":"","ymax":"","removeOlder":"1","removeOlderPoints":"","removeOlderUnit":"3600","cutout":0,"useOneColor":false,"colors":["#1f77b4","#aec7e8","#ff7f0e","#2ca02c","#98df8a","#d62728","#ff9896","#9467bd","#c5b0d5"],"useOldStyle":false,"outputs":1,"x":630,"y":200,"wires":[[]]},{"id":"6a7e00a4.eff91","type":"inject","z":"49e47d1f.99ea34","name":"","topic":"","payload":"[]","payloadType":"json","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":150,"y":380,"wires":[["d238570a.1d0888"]]},{"id":"89f5c3c3.aa0e8","type":"function","z":"49e47d1f.99ea34","name":"Setup payload","func":"series = [];\ndata = [];\nlabels = [];\nseries.push(\"temp1\",\"temp2\",\"humi1\");\nlabels.push(\"\");\ndata.push(msg.temp1,msg.temp2,msg.humi1);\nmsg.payload = [{\"series\":series, \"data\":data,\"labels\":labels}];\nreturn msg;","outputs":1,"noerr":0,"x":420,"y":140,"wires":[["569a324d.551c3c","d238570a.1d0888"]]},{"id":"b6042792.40d0b8","type":"inject","z":"49e47d1f.99ea34","name":"Select","topic":"SELECT temp1,temp2,humi1,humi2,time FROM DHT2 desc limit 10","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":150,"y":40,"wires":[["7b4e1b7.d090ce4"]]},{"id":"7b4e1b7.d090ce4","type":"sqlite","z":"49e47d1f.99ea34","mydb":"4cea1d08.1b70d4","sqlquery":"msg.topic","sql":"","name":"Database","x":320,"y":60,"wires":[["497d78eb.846c98"]]},{"id":"569a324d.551c3c","type":"debug","z":"49e47d1f.99ea34","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":650,"y":160,"wires":[]},{"id":"9c2b3a27.990668","type":"function","z":"49e47d1f.99ea34","name":"","func":"var chart = [{\n \"series\":[\"A\",\"B\",\"C\"],\n \"data\":[[\n {\"x\":1504029632890,\"y\":5},\n {\"x\":1504029636001,\"y\":4},\n {\"x\":1504029638656,\"y\":2}],\n [{\"x\":1504029633514,\"y\":6},\n {\"x\":1504029636622,\"y\":7},\n {\"x\":1504029639539,\"y\":6}],\n [{\"x\":1504029634400,\"y\":7},\n {\"x\":1504029637959,\"y\":9},\n {\"x\":1504029640317,\"y\":7}\n]],\n \"labels\":[\"\"]\n}];\nmsg.payload = chart;\n\nreturn msg;","outputs":1,"noerr":0,"x":390,"y":220,"wires":[["d238570a.1d0888","569a324d.551c3c"]]},{"id":"87335dd7.cf916","type":"inject","z":"49e47d1f.99ea34","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":160,"y":280,"wires":[["9c2b3a27.990668"]]},{"id":"497d78eb.846c98","type":"change","z":"49e47d1f.99ea34","name":"Data Array","rules":[{"t":"set","p":"temp1","pt":"msg","to":"$.payload.{\"x\":time,\"y\":temp1}","tot":"jsonata"},{"t":"set","p":"temp2","pt":"msg","to":"$.payload.{\"x\":time,\"y\":temp2}","tot":"jsonata"},{"t":"set","p":"humi1","pt":"msg","to":"$.payload.{\"x\":time,\"y\":humi1}","tot":"jsonata"},{"t":"set","p":"humi2","pt":"msg","to":"$.payload.{\"x\":time,\"y\":humi2}","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":490,"y":40,"wires":[["89f5c3c3.aa0e8"]]},{"id":"bca4ac1c.3f733","type":"ui_group","z":"","name":"Group 1","tab":"ea6b703e.6d4bf","disp":true,"width":"12","collapse":false},{"id":"4cea1d08.1b70d4","type":"sqlitedb","z":"","db":"/home/pi/Documents/Sqlite DB/dht2-tbl","mode":"RWC"},{"id":"ea6b703e.6d4bf","type":"ui_tab","z":"","name":"Tab1","icon":"dashboard"}]

```

The 1st is mine and the 2nd is according to sample.  
Now why the chart is :  
 ![1](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/d/b/db951bb6312a77ee3b2a666c3d6b3e7469700944.png)  
???  
The only difference between 2 flows is :

 ![Untitled](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/b/7/b7494df3d5f3be725c38dd10dd51fbeee412f1d9.png)  
How can I solve the problem ?!

---

<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:** [31 March 2020 08:39 UTC](https://discourse.nodered.org/t/problem-in-chart-sensor-data/23920/4 "2020-03-31T08:39:42Z")

</div>

> [@tarahi](#):
>
> How can I solve the problem ?!

The data from your Setup Payload node is not connected to the chart.

---

<div class="post-metadata">

**Author:** ![tarahi](https://avatars.discourse-cdn.com/v4/letter/t/9de053/32.png) [@tarahi](https://discourse.nodered.org/u/tarahi)\
**Post date:** [31 March 2020 08:49 UTC](https://discourse.nodered.org/t/problem-in-chart-sensor-data/23920/5 "2020-03-31T08:49:03Z")

</div>

Of Course !  
But how can it be solved ?!  
I found the problem is that my data is in string format.  
I solve the second -temp1- but don't know how to solve the first -time- !

```auto
$.payload.{"x":time,"y":$number(temp1)}

```

any idea ?!

---

<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:** [31 March 2020 08:53 UTC](https://discourse.nodered.org/t/problem-in-chart-sensor-data/23920/6 "2020-03-31T08:53:47Z")

</div>

What type is the time column in the database? It should be Timestamp.

---

<div class="post-metadata">

**Author:** ![tarahi](https://avatars.discourse-cdn.com/v4/letter/t/9de053/32.png) [@tarahi](https://discourse.nodered.org/u/tarahi)\
**Post date:** [31 March 2020 08:56 UTC](https://discourse.nodered.org/t/problem-in-chart-sensor-data/23920/7 "2020-03-31T08:56:36Z")

</div>

It's text ,But I have no problem with it till now !  
Do You mean I cant use or convert it ?

---

<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:** [31 March 2020 09:08 UTC](https://discourse.nodered.org/t/problem-in-chart-sensor-data/23920/8 "2020-03-31T09:08:52Z")

</div>

It would be better to make it Timestamp. Otherwise you can write some javascript to convert the string to a timestamp. [Date.parse](https://developer.mozilla.org/en-US/docs/web/javascript/reference/global_objects/date/parse) might do it, but you might have to add the timezone on the end first.

---

<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:** [30 May 2020 09:13 UTC](https://discourse.nodered.org/t/problem-in-chart-sensor-data/23920/9 "2020-05-30T09:13:57Z")

</div>

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