Problem With Multipe Line in Function

Hi All,

I'm trying to create function in each line and works fine. But, try to combine them with different topic make chart some delay and only display one line. After that, i'm try to create function to make it run in one function but still not working.

Maybe some one can help me and have some issued with me.

Here's my code

[
    {
        "id": "3a76e817.9d1648",
        "type": "function",
        "z": "8590f0c4.ddce88",
        "name": "Down-UP",
        "func": "\nvar cons = flow.get(\"cons\");\n var series =[\"Load (Lbs) - UP\",\"Load (Lbs) - DOWN\"];\n//var labels = [\"00\", \"01\", \"02\", \"03\", \"04\", \"05\", \"06\",\"07\", \"08\", \"09\", \"10\", \"11\", \"12\", \"13\",\"14\", \"15\", \"16\", \"17\", \"18\", \"19\", \"20\", \"21\", \"22\", \"23\",\"24\",\"25\",\"26\",\"27\",\"28\",\"29\",\"30\",\"31\", \"32\", \"33\",\"34\",\"35\",\"36\",\"37\",\"38\",\"39\",\"40\",\n//               \"41\", \"42\", \"43\",\"44\",\"45\",\"46\",\"47\",\"48\",\"49\",\"50\",\"51\", \"52\", \"53\",\"54\",\"55\",\"56\",\"57\",\"58\",\"59\",\"60\",\n //                 \"61\", \"62\", \"63\",\"64\",\"65\",\"66\",\"67\",\"68\",\"69\",\"70\",\"71\", \"72\", \"73\",\"74\",\"75\",\"76\",\"77\",\"78\",\"79\",\"80\",\n  //                      \"81\", \"82\", \"83\",\"84\",\"85\",\"86\",\"87\",\"88\",\"89\",\"90\",\"91\", \"92\", \"93\",\"94\",\"95\",\"96\",\"97\",\"98\",\"99\",\"100\",\n//                        \"101\", \"102\", \"103\",\"104\",\"105\",\"106\",\"107\",\"108\",\"109\",\"110\",\"111\", \"112\", \"113\",\"114\",\"115\",\"116\",\"117\",\"118\",\"119\",\"120\",\n //                               \"121\", \"122\", \"123\",\"124\",\"125\",\"126\",\"127\",\"128\",\"129\",\"130\",];\n \n var labels = ['100','80','60','40','20','0'];\n\n//---Data Down \n var data = [];\n\n var i, len, string;\n\nfor (i = 0, len = msg.payload.length/2, string = \"\"; i < len; i++) {\n  data.push({\n            \"x\":(Number(msg.payload[i].stroke)*cons), \n            \"y\":(Number(msg.payload[i].load)*cons)\n      \n  });\n}\n\n//data up\nvar a, len2, string2;\nfor (a = (msg.payload.length/2), len2 = msg.payload.length, string2 = \"\"; a < len2; a++) {\ndata2.push({\n        \"x\":(Number(msg.payload[a].stroke)*cons), \n        \"y\":(Number(msg.payload[a].load)*cons)\n  \n});\n}\n\n\ndata = [data,data2];\n\nmsg.payload = [{series, data, labels}];\nmsg.topic = 'Line';\n\n////---Data UP\n//var data2 = [];\n\n\n//data2 = [data2];\n//node.warn(\"data2\");\n//msg1.payload = [{series, data2, labels}];\n//msg1.topic = 'UP';\n\nreturn msg;\n\n\n",
        "outputs": 2,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "x": 1540,
        "y": 1580,
        "wires": [
            [
                "5e42ed7b.3ccee4"
            ],
            [
                "5e42ed7b.3ccee4"
            ]
        ]
    },
    {
        "id": "18b8ea2c.904bf6",
        "type": "ui_chart",
        "z": "8590f0c4.ddce88",
        "name": "",
        "group": "3a504f67.45898",
        "order": 4,
        "width": "10",
        "height": "14",
        "label": "Test - 01 - Field Test",
        "chartType": "line",
        "legend": "true",
        "xformat": "x",
        "interpolate": "linear",
        "nodata": "",
        "dot": false,
        "ymin": "",
        "ymax": "",
        "removeOlder": "24",
        "removeOlderPoints": "1000000",
        "removeOlderUnit": "3600",
        "cutout": 0,
        "useOneColor": false,
        "useUTC": false,
        "colors": [
            "#ffff00",
            "#ffa200",
            "#0000ff",
            "#0000ff",
            "#00ffff",
            "#ff0000",
            "#ffffff",
            "#9467bd",
            "#c5b0d5"
        ],
        "useOldStyle": false,
        "outputs": 1,
        "x": 1920,
        "y": 1440,
        "wires": [
            []
        ]
    },
    {
        "id": "b64271fa.a4507",
        "type": "function",
        "z": "8590f0c4.ddce88",
        "name": "up",
        "func": "// var msg ={};\n// var msg1 ={};\nvar cons = flow.get(\"cons\");\n var series =[\"Load (Lbs)\"];\n//var labels = [\"00\", \"01\", \"02\", \"03\", \"04\", \"05\", \"06\",\"07\", \"08\", \"09\", \"10\", \"11\", \"12\", \"13\",\"14\", \"15\", \"16\", \"17\", \"18\", \"19\", \"20\", \"21\", \"22\", \"23\",\"24\",\"25\",\"26\",\"27\",\"28\",\"29\",\"30\",\"31\", \"32\", \"33\",\"34\",\"35\",\"36\",\"37\",\"38\",\"39\",\"40\",\n//               \"41\", \"42\", \"43\",\"44\",\"45\",\"46\",\"47\",\"48\",\"49\",\"50\",\"51\", \"52\", \"53\",\"54\",\"55\",\"56\",\"57\",\"58\",\"59\",\"60\",\n //                 \"61\", \"62\", \"63\",\"64\",\"65\",\"66\",\"67\",\"68\",\"69\",\"70\",\"71\", \"72\", \"73\",\"74\",\"75\",\"76\",\"77\",\"78\",\"79\",\"80\",\n  //                      \"81\", \"82\", \"83\",\"84\",\"85\",\"86\",\"87\",\"88\",\"89\",\"90\",\"91\", \"92\", \"93\",\"94\",\"95\",\"96\",\"97\",\"98\",\"99\",\"100\",\n//                        \"101\", \"102\", \"103\",\"104\",\"105\",\"106\",\"107\",\"108\",\"109\",\"110\",\"111\", \"112\", \"113\",\"114\",\"115\",\"116\",\"117\",\"118\",\"119\",\"120\",\n //                               \"121\", \"122\", \"123\",\"124\",\"125\",\"126\",\"127\",\"128\",\"129\",\"130\",];\n \n var labels = ['100','80','60','40','20','0'];\n \n var data = [];\n \n\n var i, len, string;\n\n for (i = (msg.payload.length/2), len = msg.payload.length, string = \"\"; i < len; i++) {\n  data.push({\n            \"x\":(Number(msg.payload[i].stroke)*cons), \n            \"y\":(Number(msg.payload[i].load)*cons)\n      \n  });\n }\n\n data = [data];\n\nmsg.payload = [{series, data, labels}];\nmsg.topic = 'UP';\n\n// msg1.payload = [{\n//     \"data\" : [[\n//         {\"x\":100, \"y\":0},\n//         {\"x\":80, \"y\":0},\n//         {\"x\":60, \"y\":0},\n//         {\"x\":40, \"y\":0},\n//         {\"x\":20, \"y\":0},\n//         {\"x\":0, \"y\":0},\n//         ]]\n// }];\n// msg1.topic = 'Line1';\n// return [msg1,msg];\nreturn msg;",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "x": 1530,
        "y": 1500,
        "wires": [
            [
                "18b8ea2c.904bf6"
            ]
        ]
    },
    {
        "id": "bcd0a0d8.16b2",
        "type": "function",
        "z": "8590f0c4.ddce88",
        "name": "Down",
        "func": "//var msg ={};\n\nvar cons = flow.get(\"cons\");\n var series =[\"Load (Lbs)\"];\n//var labels = [\"00\", \"01\", \"02\", \"03\", \"04\", \"05\", \"06\",\"07\", \"08\", \"09\", \"10\", \"11\", \"12\", \"13\",\"14\", \"15\", \"16\", \"17\", \"18\", \"19\", \"20\", \"21\", \"22\", \"23\",\"24\",\"25\",\"26\",\"27\",\"28\",\"29\",\"30\",\"31\", \"32\", \"33\",\"34\",\"35\",\"36\",\"37\",\"38\",\"39\",\"40\",\n//               \"41\", \"42\", \"43\",\"44\",\"45\",\"46\",\"47\",\"48\",\"49\",\"50\",\"51\", \"52\", \"53\",\"54\",\"55\",\"56\",\"57\",\"58\",\"59\",\"60\",\n //                 \"61\", \"62\", \"63\",\"64\",\"65\",\"66\",\"67\",\"68\",\"69\",\"70\",\"71\", \"72\", \"73\",\"74\",\"75\",\"76\",\"77\",\"78\",\"79\",\"80\",\n  //                      \"81\", \"82\", \"83\",\"84\",\"85\",\"86\",\"87\",\"88\",\"89\",\"90\",\"91\", \"92\", \"93\",\"94\",\"95\",\"96\",\"97\",\"98\",\"99\",\"100\",\n//                        \"101\", \"102\", \"103\",\"104\",\"105\",\"106\",\"107\",\"108\",\"109\",\"110\",\"111\", \"112\", \"113\",\"114\",\"115\",\"116\",\"117\",\"118\",\"119\",\"120\",\n //                               \"121\", \"122\", \"123\",\"124\",\"125\",\"126\",\"127\",\"128\",\"129\",\"130\",];\n \n var labels = ['100','80','60','40','20','0'];\n\n//---Data Down \n var data = [];\n\n var i, len, string;\n\nfor (i = 0, len = msg.payload.length/2, string = \"\"; i < len; i++) {\n  data.push({\n            \"x\":(Number(msg.payload[i].stroke)*cons), \n            \"y\":(Number(msg.payload[i].load)*cons)\n      \n  });\n}\n\ndata = [data];\n\nmsg.payload = [{series, data, labels}];\nmsg.topic = 'Down';\n\n\nreturn msg;",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "x": 1530,
        "y": 1540,
        "wires": [
            [
                "75b25464.ea10dc"
            ]
        ]
    },
    {
        "id": "75b25464.ea10dc",
        "type": "ui_chart",
        "z": "8590f0c4.ddce88",
        "name": "",
        "group": "3a504f67.45898",
        "order": 4,
        "width": "10",
        "height": "14",
        "label": "Test - 01 - Field Test",
        "chartType": "line",
        "legend": "true",
        "xformat": "x",
        "interpolate": "linear",
        "nodata": "",
        "dot": false,
        "ymin": "",
        "ymax": "",
        "removeOlder": "24",
        "removeOlderPoints": "1000000",
        "removeOlderUnit": "3600",
        "cutout": 0,
        "useOneColor": false,
        "useUTC": false,
        "colors": [
            "#ffff00",
            "#ffa200",
            "#0000ff",
            "#0000ff",
            "#00ffff",
            "#ff0000",
            "#ffffff",
            "#9467bd",
            "#c5b0d5"
        ],
        "useOldStyle": false,
        "outputs": 1,
        "x": 1920,
        "y": 1480,
        "wires": [
            []
        ]
    },
    {
        "id": "5e42ed7b.3ccee4",
        "type": "debug",
        "z": "8590f0c4.ddce88",
        "name": "",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "false",
        "statusVal": "",
        "statusType": "auto",
        "x": 1740,
        "y": 1580,
        "wires": []
    },
    {
        "id": "3a504f67.45898",
        "type": "ui_group",
        "name": "Chart",
        "tab": "e647361f.7a4908",
        "order": 2,
        "disp": false,
        "width": "20",
        "collapse": false
    },
    {
        "id": "e647361f.7a4908",
        "type": "ui_tab",
        "name": "HPU-01",
        "icon": "dashboard",
        "disabled": false,
        "hidden": false
    }
]

This picture with individual function:

Thank you very much for all,

rizky

PS, as you can see ↑, this type of error is immediately obvious if you use Monaco editor in node-red v2.x

Hi @Steve-Mcl ,

Thank you for your advices. I'll try changes this error.

Thank you for your correction, Sir!

God blessing you

Regards,
Rizky

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