UI Chart: struggling to plot two lines

Hello all,

I've got a python script that kicks out two values from some sensors as a string in the format "[float] [float]". I'd like to plot both of these on the same chart, but am struggling.

The documentation indicates that to do this all I have to do is provide the ui_chart node two message objects with unique topics and the value in the payload, but doing this gives me an error:
"TypeError: Cannot read property 'x' of undefined"

Here is my function node that takes the sensor output string:

if(msg.payload != "END"){
   
    var msg1 = {};
 
    // Payload example "23.51 34.24"
    // Split this into the two values
    temps = msg.payload.split(" ");
    
    var timestamp = Date.now();
    
    // block.timestamp = timestamp;
    msg.payload = parseFloat(temps[0]);
    msg.topic = 'Block';
    
    // outlet.timestamp = timestamp;
    msg1.payload = parseFloat(temps[1]);
    msg1.topic = 'Outlet';
    
    // Return both messages
    return [msg, msg1];
}

What am I doing wrong here?

If I am not mistaken, the way you're pushing out your payloads, expects 2 outputs from the function node.
Have you set the function node to have multiple outputs, both going to the graph node?

if not, try this instead.

if(msg.payload != "END"){
   
    let Block = {};
    let Outlet = {};
    let temps = msg.payload.split(" ");
    
    Block.payload = parseFloat(temps[0]);
    Block.topic = 'Block';
    node.send(Block);

    Outlet.payload = parseFloat(temps[1]);
    Outlet.topic = 'Outlet';
    node.send(Outlet);

}

node.send is async, allowing you to send another message further down, where as [msg,msg] will attempt to split the array of messages out of each pin.

You are almost there, you are returning to two separate outputs. You need to return to one
return [[msg, msg1]];

That's how I would handle your example.

[
    {
        "id": "86a1b0e1d13ffcc0",
        "type": "function",
        "z": "1c8960f1ef8ff51e",
        "name": "asign topic",
        "func": "if(msg.payload != \"END\"){\n\n    if(msg.parts.index==0)\n    {\n        msg.topic = \"Block\";\n    }\n    if(msg.parts.index==1)\n    {\n        msg.topic = \"Outlet\";\n    }\n    return msg;\n}",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 570,
        "y": 680,
        "wires": [
            [
                "18d2532010da2c12"
            ]
        ]
    },
    {
        "id": "f8bc38ee2a8ad1d8",
        "type": "inject",
        "z": "1c8960f1ef8ff51e",
        "name": "",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "topic",
                "vt": "str"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": true,
        "onceDelay": "1",
        "topic": "",
        "payload": "23.51 34.24",
        "payloadType": "str",
        "x": 190,
        "y": 660,
        "wires": [
            [
                "129c1cfe8c462f50"
            ]
        ]
    },
    {
        "id": "18d2532010da2c12",
        "type": "ui_chart",
        "z": "1c8960f1ef8ff51e",
        "name": "",
        "group": "d54cb1d933ea62fe",
        "order": 2,
        "width": 0,
        "height": 0,
        "label": "chart",
        "chartType": "line",
        "legend": "true",
        "xformat": "HH:mm:ss",
        "interpolate": "linear",
        "nodata": "",
        "dot": false,
        "ymin": "",
        "ymax": "",
        "removeOlder": 1,
        "removeOlderPoints": "",
        "removeOlderUnit": "3600",
        "cutout": 0,
        "useOneColor": false,
        "useUTC": false,
        "colors": [
            "#1f77b4",
            "#fd0808",
            "#ff7f0e",
            "#2ca02c",
            "#98df8a",
            "#d62728",
            "#ff9896",
            "#9467bd",
            "#c5b0d5"
        ],
        "outputs": 1,
        "useDifferentColor": false,
        "className": "",
        "x": 710,
        "y": 680,
        "wires": [
            []
        ]
    },
    {
        "id": "d9fbd5348830bb15",
        "type": "inject",
        "z": "1c8960f1ef8ff51e",
        "name": "",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "topic",
                "vt": "str"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": true,
        "onceDelay": "2",
        "topic": "",
        "payload": "24.62 38.43",
        "payloadType": "str",
        "x": 190,
        "y": 720,
        "wires": [
            [
                "129c1cfe8c462f50"
            ]
        ]
    },
    {
        "id": "129c1cfe8c462f50",
        "type": "split",
        "z": "1c8960f1ef8ff51e",
        "name": "",
        "splt": " ",
        "spltType": "str",
        "arraySplt": 1,
        "arraySpltType": "len",
        "stream": false,
        "addname": "",
        "x": 390,
        "y": 680,
        "wires": [
            [
                "86a1b0e1d13ffcc0"
            ]
        ]
    },
    {
        "id": "d54cb1d933ea62fe",
        "type": "ui_group",
        "name": "Algemeen",
        "tab": "b0f210370ce49ef3",
        "order": 1,
        "disp": true,
        "width": "6",
        "collapse": false,
        "className": ""
    },
    {
        "id": "b0f210370ce49ef3",
        "type": "ui_tab",
        "name": "Home",
        "icon": "dashboard",
        "disabled": false,
        "hidden": false
    }
]

Ah, I was so close. Thank you!

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