mySQL > Bar Chart

50 views
Skip to first unread message

Helmuth Rieger

unread,
Apr 30, 2018, 3:37:03 PM4/30/18
to Node-RED
I'd like to show data from mySQL on a bar chart.
After searching in the web I found a format script.
Also Jasonata tests were succesfull but the chart is not showing.
Do you know what is wrong?

Thanks Helmuth

[{"id":"7368e206.c56acc","type":"ui_chart","z":"cee0fd99.19843","name":"","group":"59178b76.5e20d4","order":0,"width":0,"height":0,"label":"Bar Chart","chartType":"bar","legend":"false","xformat":"auto","interpolate":"linear","nodata":"","dot":false,"ymin":"","ymax":"","removeOlder":1,"removeOlderPoints":"","removeOlderUnit":"3600","cutout":0,"useOneColor":true,"colors":["#00b000","#aec7e8","#ff7f0e","#2ca02c","#98df8a","#d62728","#ff9896","#9467bd","#c5b0d5"],"useOldStyle":false,"x":660,"y":160,"wires":[[],[]]},{"id":"db428778.3c2ab8","type":"inject","z":"cee0fd99.19843","name":"from mySQL","topic":"","payload":"[{\"x\":\"22\",\"y\":1989.441462},{\"x\":\"23\",\"y\":1537.207469}]","payloadType":"json","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":270,"y":160,"wires":[["96f0d95f.77c208"]]},{"id":"96f0d95f.77c208","type":"change","z":"cee0fd99.19843","name":"Format data","rules":[{"t":"set","p":"payload","pt":"msg","to":"[{\t\"series\": [\"kWh\"],\t\"data\": [[$.y]],\t\"labels\": [$.x]\t}]","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":470,"y":160,"wires":[["7368e206.c56acc"]]},{"id":"59178b76.5e20d4","type":"ui_group","z":"","name":"Caravan Control","tab":"715aac9d.b8b934","disp":false,"width":"7","collapse":false},{"id":"715aac9d.b8b934","type":"ui_tab","z":"","name":"Home","icon":"dashboard"}]

steve rickus

unread,
Apr 30, 2018, 5:45:26 PM4/30/18
to Node-RED
Yes, your data is being passed to the change node in msg.payload, but your JSONata expression does not refer to 'payload' at all (only $, which represents the current context, or in this case the 'msg' object). Try changing your expression to this:

[
   
{
       
"series": ["kWh"],
       
"data": [[payload.y]],
       
"labels": [payload.x]
   
}
]

When you are writing your JSONata expression, it helps to use the "Test" tab to see what the result will be. Just make sure to substitute your mySQL raw JSON data in place of the "hello world" string as the payload to be tested. Here you can see what it should look like:


--
Steve

Helmuth Rieger

unread,
Apr 30, 2018, 5:53:26 PM4/30/18
to Node-RED
It works! You are great!
Thank you very much!
Reply all
Reply to author
Forward
0 new messages