Bar graph not generated

I have these format of data,
"msg.payload : array[2]=
[
{"DATE":"2023-12-29","daily_energy_consumption":4687},
{"DATE":"2023-12-30","daily_energy_consumption":100}
]"

and I want to generate bar-graph using these data.
array size will be flexible,it will be change according to the selected time frame.

You need to transform the data to the correct format as described here node-red-dashboard/Charts.md at master · node-red/node-red-dashboard · GitHub

this format

[{
    "series": [ "X" ],
    "data": [ [5,6,9] ],
    "labels": [ "Jan", "Feb", "Mar" ]
}]

This example uses JSONata to transform an array of objects.

[{"id":"9b29541e01b1841c","type":"change","z":"bf510de9c34b4fc2","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"[\t    {\t        \"series\": [\"daily_energy_consumption\"],\t        \"data\": [[$$.payload.daily_energy_consumption]],\t        \"labels\":[$$.payload.DATE]\t    }\t]","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":780,"y":500,"wires":[["45f8780d2b96637e","b6b418c74d07e908"]]},{"id":"598c7975d9b21f16","type":"inject","z":"bf510de9c34b4fc2","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"[{\"DATE\":\"2023-12-29\",\"daily_energy_consumption\":4687},{\"DATE\":\"2023-12-30\",\"daily_energy_consumption\":100}]","payloadType":"json","x":630,"y":500,"wires":[["9b29541e01b1841c"]]},{"id":"45f8780d2b96637e","type":"debug","z":"bf510de9c34b4fc2","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":930,"y":500,"wires":[]},{"id":"b6b418c74d07e908","type":"ui_chart","z":"bf510de9c34b4fc2","name":"","group":"4f791fdc1745d3d9","order":2,"width":0,"height":0,"label":"chart","chartType":"bar","legend":"false","xformat":"HH:mm:ss","interpolate":"linear","nodata":"","dot":false,"ymin":"","ymax":"","removeOlder":1,"removeOlderPoints":"","removeOlderUnit":"3600","cutout":0,"useOneColor":false,"useUTC":false,"colors":["#1f77b4","#aec7e8","#ff7f0e","#2ca02c","#98df8a","#d62728","#ff9896","#9467bd","#c5b0d5"],"outputs":1,"useDifferentColor":false,"className":"","x":930,"y":540,"wires":[[]]},{"id":"4f791fdc1745d3d9","type":"ui_group","name":"micro","tab":"c954274bbed7292e","order":1,"disp":false,"width":"18","collapse":false,"className":""},{"id":"c954274bbed7292e","type":"ui_tab","name":"Solar","icon":"dashboard","order":1,"disabled":false,"hidden":false}]

Expression

[
    {
        "series": ["daily_energy_consumption"],
        "data": [[$$.payload.daily_energy_consumption]],
        "labels":[$$.payload.DATE]
    }
]
1 Like

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