# UI Chart: struggling to plot two lines

**URL:** <https://discourse.nodered.org/t/ui-chart-struggling-to-plot-two-lines/52510>\
**Category:** Dashboard\
**Created:** [21 October 2021 12:46 UTC](https://discourse.nodered.org/t/ui-chart-struggling-to-plot-two-lines/52510 "2021-10-21T12:46:56Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sensors](https://avatars.discourse-cdn.com/v4/letter/s/3ec8ea/32.png) [@Sensors](https://discourse.nodered.org/u/Sensors)\
**Post date:** [21 October 2021 12:46 UTC](https://discourse.nodered.org/t/ui-chart-struggling-to-plot-two-lines/52510/1 "2021-10-21T12:46:56Z")

</div>

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:

```auto
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?

---

<div class="post-metadata">

**Author:** ![marcus-j-davies](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/marcus-j-davies/32/103435_2.png) [@marcus-j-davies](https://discourse.nodered.org/u/marcus-j-davies)\
**Post date:** [21 October 2021 13:23 UTC](https://discourse.nodered.org/t/ui-chart-struggling-to-plot-two-lines/52510/2 "2021-10-21T13:23:22Z")

</div>

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.

```auto
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.

---

<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:** [21 October 2021 13:37 UTC](https://discourse.nodered.org/t/ui-chart-struggling-to-plot-two-lines/52510/3 "2021-10-21T13:37:45Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Razio](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/razio/32/52407_2.png) [@Razio](https://discourse.nodered.org/u/Razio)\
**Post date:** [21 October 2021 13:49 UTC](https://discourse.nodered.org/t/ui-chart-struggling-to-plot-two-lines/52510/4 "2021-10-21T13:49:45Z")

</div>

That's how I would handle your example.

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

```

---

<div class="post-metadata">

**Author:** ![Sensors](https://avatars.discourse-cdn.com/v4/letter/s/3ec8ea/32.png) [@Sensors](https://discourse.nodered.org/u/Sensors)\
**Post date:** [27 October 2021 14:55 UTC](https://discourse.nodered.org/t/ui-chart-struggling-to-plot-two-lines/52510/5 "2021-10-27T14:55:35Z")

</div>

Ah, I was so close. Thank you!

---

<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:** [10 November 2021 14:56 UTC](https://discourse.nodered.org/t/ui-chart-struggling-to-plot-two-lines/52510/6 "2021-11-10T14:56:09Z")

</div>

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