Retrieving JSON data to make a chart

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

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

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.

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

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

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

 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

1 Like

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

image

^ 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...

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

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]]

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

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

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