# Bar graph not generated

**URL:** <https://discourse.nodered.org/t/bar-graph-not-generated/84126>\
**Category:** Dashboard\
**Created:** [30 December 2023 08:39 UTC](https://discourse.nodered.org/t/bar-graph-not-generated/84126 "2023-12-30T08:39:49Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![PRABHAKAR82](https://avatars.discourse-cdn.com/v4/letter/p/e47c2d/32.png) [@PRABHAKAR82](https://discourse.nodered.org/u/PRABHAKAR82)\
**Post date:** [30 December 2023 08:39 UTC](https://discourse.nodered.org/t/bar-graph-not-generated/84126/1 "2023-12-30T08:39:49Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)\
**Post date:** [30 December 2023 09:03 UTC](https://discourse.nodered.org/t/bar-graph-not-generated/84126/2 "2023-12-30T09:03:43Z")

</div>

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](https://github.com/node-red/node-red-dashboard/blob/master/Charts.md)

this format

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

```

This example uses JSONata to transform an array of objects.

```auto
[{"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

```auto
[
    {
        "series": ["daily_energy_consumption"],
        "data": [[$$.payload.daily_energy_consumption]],
        "labels":[$$.payload.DATE]
    }
]

```

---

<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:** [13 January 2024 09:04 UTC](https://discourse.nodered.org/t/bar-graph-not-generated/84126/3 "2024-01-13T09:04:23Z")

</div>

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