# Json in Bar-Chart

**URL:** <https://discourse.nodered.org/t/json-in-bar-chart/33931>\
**Category:** Dashboard\
**Created:** [8 October 2020 10:26 UTC](https://discourse.nodered.org/t/json-in-bar-chart/33931 "2020-10-08T10:26:31Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ataraxial](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ataraxial/32/41138_2.png) [@Ataraxial](https://discourse.nodered.org/u/Ataraxial)\
**Post date:** [8 October 2020 10:26 UTC](https://discourse.nodered.org/t/json-in-bar-chart/33931/1 "2020-10-08T10:26:31Z")

</div>

good morning

I am working with a series of data from the API of a website, I have transformed them to JSON, remaining in this format.

```auto
[
    {
        "value": 104.61,
        "hora": "00"
    },
    {
        "value": 104.33,
        "hora": "01"
    },
    {
        "value": 103.2,
        "hora": "02"
    },
    {
        "value": 101.28,
        "hora": "03"
    },
    {
        "value": 99.34,
        "hora": "04"
    }]

```

They are electricity prices by hourly sections, so for example, the vaule value of the first is the price in € and hor, it is the hour range.

I have tried to make a bar graph but the node does not accept it.  
Any idea where to go?

Thanks and a greeting

---

<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:** [8 October 2020 11:46 UTC](https://discourse.nodered.org/t/json-in-bar-chart/33931/2 "2020-10-08T11:46:24Z")

</div>

You need to format the data for the bar chart.  
An example.

```auto
[{"id":"5d07e053.195108","type":"inject","z":"8d5be6f9.bc3cb","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"[{\"value\":104.61,\"hora\":\"00\"},{\"value\":104.33,\"hora\":\"01\"},{\"value\":103.2,\"hora\":\"02\"},{\"value\":101.28,\"hora\":\"03\"},{\"value\":99.34,\"hora\":\"04\"}]","payloadType":"json","x":170,"y":220,"wires":[["683b728f.63125c"]]},{"id":"683b728f.63125c","type":"change","z":"8d5be6f9.bc3cb","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"[\t {\t \"series\": [\"X\"],\t \"data\": [[$map(payload,function($v){$v.value})]],\t \"labels\": $map(payload,function($v){$v.hora})\t \t }\t\t]","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":370,"y":240,"wires":[["a5067d02.810618","c9ce5686.f560f"]]},{"id":"a5067d02.810618","type":"ui_chart","z":"8d5be6f9.bc3cb","name":"","group":"165e1e1a.e752fa","order":1,"width":0,"height":0,"label":"","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"],"useOldStyle":false,"outputs":1,"x":610,"y":300,"wires":[[]]},{"id":"c9ce5686.f560f","type":"debug","z":"8d5be6f9.bc3cb","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":610,"y":60,"wires":[]},{"id":"165e1e1a.e752fa","type":"ui_group","z":"","name":"Default","tab":"f9b58883.fa613","order":1,"disp":true,"width":"12","collapse":false},{"id":"f9b58883.fa613","type":"ui_tab","z":"","name":"Home","icon":"dashboard","order":1,"disabled":false,"hidden":false}]

```

---

<div class="post-metadata">

**Author:** ![Ataraxial](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ataraxial/32/41138_2.png) [@Ataraxial](https://discourse.nodered.org/u/Ataraxial)\
**Post date:** [8 October 2020 12:17 UTC](https://discourse.nodered.org/t/json-in-bar-chart/33931/3 "2020-10-08T12:17:52Z")

</div>

you are a genious! the first time it has worked! I had something similar but mine was not working for me.

I take advantage, is it possible that in that function it returns all the values ​​of "value" divided by 1000?  
Thank you very much for the help! very thankful!

---

<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:** [8 October 2020 12:27 UTC](https://discourse.nodered.org/t/json-in-bar-chart/33931/4 "2020-10-08T12:27:36Z")

</div>

```auto
[{"id":"683b728f.63125c","type":"change","z":"8d5be6f9.bc3cb","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"[\t {\t \"series\": [\"X\"],\t \"data\": [[$map(payload,function($v){$round($v.value /1000, 4)})]],\t \"labels\": $map(payload,function($v){$v.hora})\t \t }\t\t]","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":370,"y":240,"wires":[["a5067d02.810618","c9ce5686.f560f"]]}]

```

---

<div class="post-metadata">

**Author:** ![Ataraxial](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ataraxial/32/41138_2.png) [@Ataraxial](https://discourse.nodered.org/u/Ataraxial)\
**Post date:** [20 October 2020 10:59 UTC](https://discourse.nodered.org/t/json-in-bar-chart/33931/5 "2020-10-20T10:59:09Z")

</div>

Is perfect!

Thanks!!

---

<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:** [3 November 2020 10:59 UTC](https://discourse.nodered.org/t/json-in-bar-chart/33931/6 "2020-11-03T10:59:24Z")

</div>

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