# Retrieving JSON data to make a chart

**URL:** https://discourse.nodered.org/t/retrieving-json-data-to-make-a-chart/40660
**Category:** Dashboard
**Created:** [9 February 2021 09:29 UTC](https://discourse.nodered.org/t/retrieving-json-data-to-make-a-chart/40660 "2021-02-09T09:29:00Z")
**Posts on this page:** 9
**Page:** 1

<div class="post-metadata">

### Author: ![Student00](https://avatars.discourse-cdn.com/v4/letter/s/b77776/32.png) [@Student00](https://discourse.nodered.org/u/Student00)
#### Post date: [9 February 2021 09:29 UTC](https://discourse.nodered.org/t/retrieving-json-data-to-make-a-chart/40660/1 "2021-02-09T09:29:00Z")

</div>

Hello, I'm trying to insert a JSON data into a dashboard ui\_chart using a function and I don't know where I'm wrong exactly. My chart isn't appearing even though I can see the data with my debug node and by using a ui\_text node as a test. I'm retrieving the data sent by an API and then converting them into Javascript object with a JSON node. Here are my nodes

```auto
[
    {
        "id": "e43af624.9ee788",
        "type": "solaredge",
        "z": "5dbb879.bcc5978",
        "site": "5991542f.eb3d6c",
        "interval": "900",
        "command": "overview",
        "x": 140,
        "y": 680,
        "wires": [
            [
                "e92a335d.cd04b"
            ]
        ]
    },
    {
        "id": "e92a335d.cd04b",
        "type": "json",
        "z": "5dbb879.bcc5978",
        "name": "",
        "property": "payload",
        "action": "obj",
        "pretty": false,
        "x": 330,
        "y": 680,
        "wires": [
            [
                "d99af8cf.cf04e8",
                "b93a08fd.791f78"
            ]
        ]
    },
    {
        "id": "d99af8cf.cf04e8",
        "type": "debug",
        "z": "5dbb879.bcc5978",
        "name": "",
        "active": false,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "payload",
        "targetType": "msg",
        "statusVal": "",
        "statusType": "auto",
        "x": 440,
        "y": 760,
        "wires": []
    },
    {
        "id": "b93a08fd.791f78",
        "type": "function",
        "z": "5dbb879.bcc5978",
        "name": "",
        "func": "var o = msg.payload.overview.currentPower;\nmsg.payload.overview.currentPower = o.power;\nreturn msg;",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "x": 530,
        "y": 680,
        "wires": [
            [
                "c65db3fc.2232"
            ]
        ]
    },
    {
        "id": "c65db3fc.2232",
        "type": "ui_chart",
        "z": "5dbb879.bcc5978",
        "name": "",
        "group": "d4527e47.57c2a",
        "order": 1,
        "width": 6,
        "height": 4,
        "label": "Evolution de la production d'énergie",
        "chartType": "line",
        "legend": "false",
        "xformat": "HH:mm:ss",
        "interpolate": "linear",
        "nodata": "",
        "dot": false,
        "ymin": "",
        "ymax": "",
        "removeOlder": "15",
        "removeOlderPoints": "",
        "removeOlderUnit": "60",
        "cutout": 0,
        "useOneColor": false,
        "useUTC": false,
        "colors": [
            "#1f77b4",
            "#aec7e8",
            "#ff7f0e",
            "#2ca02c",
            "#98df8a",
            "#d62728",
            "#ff9896",
            "#9467bd",
            "#c5b0d5"
        ],
        "outputs": 1,
        "useDifferentColor": false,
        "x": 760,
        "y": 680,
        "wires": [
            []
        ]
    },
    {
        "id": "5991542f.eb3d6c",
        "type": "solaredge-site",
        "siteid": "1370275",
        "apikey": "PBIS51AQK3RJ1DWUEDPEXF68TW2H96SN"
    },
    {
        "id": "d4527e47.57c2a",
        "type": "ui_group",
        "name": "Production",
        "tab": "f5384d3d.fa18a",
        "order": 5,
        "disp": true,
        "width": "6",
        "collapse": false
    },
    {
        "id": "f5384d3d.fa18a",
        "type": "ui_tab",
        "name": "SolarEdge",
        "icon": "dashboard",
        "disabled": false,
        "hidden": false
    }
]

```

And here is the data sent by my debug node ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/5/0/50246f9d88e85ec45439ab61cd4b4607cb4a7903.png)

---

<div class="post-metadata">

### Author: ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)
#### Post date: [9 February 2021 09:34 UTC](https://discourse.nodered.org/t/retrieving-json-data-to-make-a-chart/40660/2 "2021-02-09T09:34:10Z")

</div>

Have you read the built in help for the chart node (on the sidebar)?

You either send single values in payload (usually with a topic) or format the data as per the linked to documentation.

The data you are sending to the chart is neither of these formats.

---

<div class="post-metadata">

### Author: ![Student00](https://avatars.discourse-cdn.com/v4/letter/s/b77776/32.png) [@Student00](https://discourse.nodered.org/u/Student00)
#### Post date: [9 February 2021 09:39 UTC](https://discourse.nodered.org/t/retrieving-json-data-to-make-a-chart/40660/3 "2021-02-09T09:39:38Z")

</div>

But isn't the data I'm sending a payload? I'm trying to only send the value of the data "power"

```auto
var o = msg.payload.overview.currentPower;
msg.payload.overview.currentPower = o.power;
return msg;

```

---

<div class="post-metadata">

### Author: ![leftymuller](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/leftymuller/32/102326_2.png) [@leftymuller](https://discourse.nodered.org/u/leftymuller)
#### Post date: [9 February 2021 09:41 UTC](https://discourse.nodered.org/t/retrieving-json-data-to-make-a-chart/40660/4 "2021-02-09T09:41:19Z")

</div>

Just recently doing this youll need to write a function that pulls the JSON object you want to send to the chart.

something like this

```auto
 var msg1 = {};
 var msg2 = {};

 msg1.payload = msg.payload.overview.lastMonthData.energy;
 msg2.payload = msg.payload.overview.lastDayData.energy;

  msg1.topic = 'Last Month';
  msg2.topic = 'Last Day';
 return [msg1,msg2]; 

```

Hope this help.. im no expert!

This what I get from my 2 PV's

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/a/4/a4678650f16070766ca93b028ee61afdcf225b8e.png)

---

<div class="post-metadata">

### Author: ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)
#### Post date: [9 February 2021 09:47 UTC](https://discourse.nodered.org/t/retrieving-json-data-to-make-a-chart/40660/5 "2021-02-09T09:47:42Z")

</div>

> [@Student00](#):
>
> But isn't the data I'm sending a payload?

yes, but it is an object. It needs to be a value. Read the docs.

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/f/5/f51985e5c7a43b4a1e751abcbc4b2f9c8a77d946.png)

^ how would the chart know to drill down into an object to find your value in `msg.payload.overview.currentPower`?

@leftymuller's demo is a good demonstration - follow that.

clue...

```auto
msg.payload = msg.payload.overview.currentPower.power; //put only the VALUE in payload
msg.topic = "power";
return msg;

```

---

<div class="post-metadata">

### Author: ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)
#### Post date: [9 February 2021 09:56 UTC](https://discourse.nodered.org/t/retrieving-json-data-to-make-a-chart/40660/6 "2021-02-09T09:56:50Z")

</div>

> [@leftymuller](#):
>
> `return [msg1,msg2];`

That is not quite right, that assumes the function has two outputs and it will send one on each output. To get both to be sent one after the other use  
`return [[msg1,msg2]]`

---

<div class="post-metadata">

### Author: ![Student00](https://avatars.discourse-cdn.com/v4/letter/s/b77776/32.png) [@Student00](https://discourse.nodered.org/u/Student00)
#### Post date: [9 February 2021 10:05 UTC](https://discourse.nodered.org/t/retrieving-json-data-to-make-a-chart/40660/7 "2021-02-09T10:05:48Z")

</div>

Thank you guys for answering I now got it working! I'm a newbie at Node-RED so I took so long for such an easy task

---

<div class="post-metadata">

### Author: ![leftymuller](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/leftymuller/32/102326_2.png) [@leftymuller](https://discourse.nodered.org/u/leftymuller)
#### Post date: [9 February 2021 10:22 UTC](https://discourse.nodered.org/t/retrieving-json-data-to-make-a-chart/40660/8 "2021-02-09T10:22:50Z")

</div>

> [@Colin](#):
>
> That is not quite right,

You are correct.. I am using it like that.. I should of stated that

---

<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: [23 February 2021 10:23 UTC](https://discourse.nodered.org/t/retrieving-json-data-to-make-a-chart/40660/9 "2021-02-23T10:23:11Z")

</div>

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