Problem in Chart sensor data

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 :

[{"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}]

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

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.

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

[{"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
???
The only difference between 2 flows is :


How can I solve the problem ?!

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

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- !

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

any idea ?!

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

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

It would be better to make it Timestamp. Otherwise you can write some javascript to convert the string to a timestamp. Date.parse might do it, but you might have to add the timezone on the end first.

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