Help Function for multi line chart

Hello,

Im trying to get data from influx and put in multi line chart, the problem is if i get a huge array i got error or if i inject the message using the node i get error.

Error:
function : (error)
TypeError: Cannot read property '0' of undefined"

Below i provide the fucntion code and flow.

Idk...if i using correctly the Json.parse.

//
// Format the InfluxDB results to match the charts JSON format
//

var series = ["1","2","3","4","5"];
var labels = ["Data Values"];
var jsondata = [];
var data =[];
var thetime = "";
var val="";


data = '[[';
var arrSize = msg.payload.results[0].series[0].values[0].length;
var arrValueSize = msg.payload.results[0].series[0].columns.length;

node.warn("arrSize="+arrSize);
node.warn("arrValueSize="+arrValueSize);

for (var j = 1; j < arrValueSize; j++) {
    for (var i = 0; i < arrSize; i++) { 
        
        thetime = Number(msg.payload.results[0].series[0].values[i][0]); 
        val = Number(msg.payload.results[0].series[0].values[i][j].toFixed(2));
        
        data +='{ "x":' + thetime + ', "y":' + val + '}';
        
        if (i < (arrSize - 1)) {
            data += ",";
        }
    }
    if (j < (arrSize - 1)) {
        data += '],[';
    } else {
        data += ']]';
    }
}
node.warn("data="+data);

jsondata = JSON.parse(data);

flow.set("jsondata",jsondata);

node.warn("jsondata="+jsondata);


msg.payload = [{ "series": series, "data": jsondata, "labels": labels }];
msg.playload = data;
//msg.teste = jsondata;
return msg;

Flow

[{"id":"24452d0f.268b22","type":"tab","label":"Flow 1","disabled":false,"info":""},{"id":"b57671b6.63cb3","type":"ui_chart","z":"24452d0f.268b22","name":"ui chart HTF L3 Boiler Side","group":"fde15ac0.f452c8","order":1,"width":23,"height":6,"label":"","chartType":"line","legend":"true","xformat":"auto","interpolate":"cubic","nodata":"","dot":false,"ymin":"","ymax":"","removeOlder":"0","removeOlderPoints":"","removeOlderUnit":"3600","cutout":0,"useOneColor":false,"useUTC":false,"colors":["#1f77b4","#aec7e8","#ff7f0e","#2ca02c","#98df8a","#d62728","#ff9896","#9467bd","#c5b0d5"],"useOldStyle":false,"outputs":1,"x":760,"y":760,"wires":[[]]},{"id":"7e4ea3a5.42b12c","type":"influxdb in","z":"24452d0f.268b22","influxdb":"f60a0ee9.cecd2","name":"teste","query":"","rawOutput":true,"precision":"s","retentionPolicy":"","x":750,"y":640,"wires":[["8662189b.2efbf8"]]},{"id":"8662189b.2efbf8","type":"change","z":"24452d0f.268b22","name":"to JSONata","rules":[{"t":"set","p":"payload","pt":"msg","to":"payload.results.[\t    {\t        \"series\": [\"Temp.CW (ºC)\",\"Press.CW (Bar)\",\"Press.CCW (Bar)\",\"Temp.CCW (ºC)\"],\t        \"labels\": [\t            series[0].values.$fromMillis($[0]*1000, '[D01] [H1]:[M01]:[s01]','+0100')\t        ],\t        \"data\": [\t            [series.values.($boolean($[1])?$round($[1],2):$[1])],\t            [series.values.($boolean($[2])?$round($[2],2):$[2])],\t            [series.values.($boolean($[3])?$round($[3],2):$[3])],\t            [series.values.($boolean($[4])?$round($[4],2):$[4])]\t         ]\t    }\t \t]","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":750,"y":700,"wires":[["b57671b6.63cb3"]],"info":"payload.results.[ \n   {\n       \"series\": [\"Temp\",\"Humd\"],\n       \"labels\": [series.columns[1],series.columns[2]],\n       \"data\": [\n       \n               [series.values.{\"x\": $[0]*1000,\"y\": $round($[1], 2)}],\n               [series.values.{\"x\": $[0]*1000,\"y\": $round($[2], 2)}]\n           \n       ]\n    \n\n   \n   }\n\n]"},{"id":"b5f5d69b.fc2d48","type":"function","z":"24452d0f.268b22","name":"Select","func":"//Var's\nvar TimePrecision = \"\";\nvar FillType=\"null\";\n\n//Select Precision\nswitch (msg.payload) {\n    case \"Actual\":\n        TimePrecision = \"10s\";\n        break;\n    case \"1m\":\n        TimePrecision = \"10s\";\n        break;\n    case \"5m\":\n        TimePrecision = \"20s\";\n        break;\n    case \"10m\":\n        TimePrecision = \"30s\";\n        break;\n    case \"15m\":\n        TimePrecision = \"45s\";\n        break;\n    case \"30m\":\n        TimePrecision = \"45s\";\n        break;\n    case \"1h\":\n        TimePrecision =\"1m\";\n        break;\n    case \"2h\":\n        TimePrecision = \"2m\";\n        break;\n    case \"4h\":\n        TimePrecision = \"5m\";\n        break;\n    case \"8h\":\n        TimePrecision = \"10m\";\n        break;\n    case \"16h\":\n        TimePrecision = \"30m\";\n        break;\n    case \"24h\":\n        TimePrecision = \"1h\";\n        break;\n    case \"48h\":\n        TimePrecision = \"2h\";\n        break;\n}\n\n\n\nmsg.query = \"SELECT mean(HTF_L3_INLET_Temp_BoilerSd) AS mean_HTF_L3_INLET_Temp_BoilerSd, mean(HTF_L3_INLET_Pressure_BoilerSd) AS mean_HTF_L3_INLET_Pressure_BoilerSd, mean(HTF_L3_OUTLET_Pressure_BoilerSd) AS mean_HTF_L3_OUTLET_Pressure_BoilerSd, mean(HTF_L3_OUTLET_Temp_BoilerSd) AS mean_HTF_L3_OUTLET_Temp_BoilerSd FROM Boiler3 WHERE time > now() - \" + msg.payload + \" AND time < now() AND Grp='HTF_L3' AND Side='BOILER3' GROUP BY time(\" + TimePrecision + \") FILL(\" + FillType + \")\";\n\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":750,"y":580,"wires":[["7e4ea3a5.42b12c"]]},{"id":"17176a49.ea63e6","type":"ui_chart","z":"24452d0f.268b22","name":"ui chart HTF L3 SA Side","group":"2df10b90.0ed104","order":1,"width":"23","height":6,"label":"","chartType":"line","legend":"true","xformat":"auto","interpolate":"cubic","nodata":"","dot":false,"ymin":"","ymax":"","removeOlder":"0","removeOlderPoints":"","removeOlderUnit":"3600","cutout":0,"useOneColor":false,"useUTC":false,"colors":["#1f77b4","#aec7e8","#ff7f0e","#2ca02c","#98df8a","#d62728","#ff9896","#9467bd","#c5b0d5"],"useOldStyle":false,"outputs":1,"x":710,"y":1180,"wires":[[]]},{"id":"f6866dd5.89133","type":"influxdb in","z":"24452d0f.268b22","influxdb":"f60a0ee9.cecd2","name":"teste","query":"","rawOutput":true,"precision":"ms","retentionPolicy":"","x":690,"y":1060,"wires":[["e0f7e43a.dd6cb8"]]},{"id":"e0f7e43a.dd6cb8","type":"change","z":"24452d0f.268b22","name":"to JSONata","rules":[{"t":"set","p":"payload","pt":"msg","to":"payload.results.[\t    {\t        \"series\": [\"Temp.CW (ºC)\",\"Press.CW (Bar)\",\"Press.CCW (Bar)\",\"Temp.CCW (ºC)\",\"Flow (m3/h)\"],\t        \"labels\": [\t            series[0].values.$fromMillis($[0], '[D01] [H1]:[M01]:[s01]','+0100')\t        ],\t        \"data\": [\t            [series.values.($boolean($[1])?$round($[1],2):$[1])],\t            [series.values.($boolean($[2])?$round($[2],2):$[2])],\t            [series.values.($boolean($[3])?$round($[3],2):$[3])],\t            [series.values.($boolean($[4])?$round($[4],2):$[4])],\t            [series.values.($boolean($[5])?$round($[5],2):$[5])]\t         ]\t    }\t \t]","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":690,"y":1120,"wires":[["17176a49.ea63e6"]],"info":"payload.results.[ \n   {\n       \"series\": [\"Temp\",\"Humd\"],\n       \"labels\": [series.columns[1],series.columns[2]],\n       \"data\": [\n       \n               [series.values.{\"x\": $[0]*1000,\"y\": $round($[1], 2)}],\n               [series.values.{\"x\": $[0]*1000,\"y\": $round($[2], 2)}]\n           \n       ]\n    \n\n   \n   }\n\n]"},{"id":"87ddfb23.d11598","type":"function","z":"24452d0f.268b22","name":"Select","func":"//Var's\nvar TimePrecision = \"\";\nvar FillType=\"null\";\n\n//Select Precision\nswitch (msg.payload) {\n    case \"Actual\":\n        TimePrecision = \"10s\";\n        break;\n    case \"1m\":\n        TimePrecision = \"10s\";\n        break;\n    case \"5m\":\n        TimePrecision = \"20s\";\n        break;\n    case \"10m\":\n        TimePrecision = \"30s\";\n        break;\n    case \"15m\":\n        TimePrecision = \"45s\";\n        break;\n    case \"30m\":\n        TimePrecision = \"45s\";\n        break;\n    case \"1h\":\n        TimePrecision =\"1m\";\n        break;\n    case \"2h\":\n        TimePrecision = \"2m\";\n        break;\n    case \"4h\":\n        TimePrecision = \"5m\";\n        break;\n    case \"8h\":\n        TimePrecision = \"10m\";\n        break;\n    case \"16h\":\n        TimePrecision = \"30m\";\n        break;\n    case \"24h\":\n        TimePrecision = \"1h\";\n        break;\n    case \"48h\":\n        TimePrecision = \"2h\";\n        break;\n}\n\n\nmsg.query = \"SELECT mean(HTF_L3_INLET_Temp) AS mean_HTF_L3_INLET_Temp, mean(HTF_L3_INLET_Pressure) AS mean_HTF_L3_INLET_Pressure, mean(HTF_L3_OUTLET_Pressure) AS mean_HTF_L3_OUTLET_Pressure, mean(HTF_L3_OUTLET_Temp) AS mean_HTF_L3_OUTLET_Temp, mean(HTF_L3_Flow) AS mean_HTF_L3_Flow FROM Boiler3 WHERE time > now() - \" + msg.payload + \" AND time < now() AND Grp='HTF_L3' AND Side='SA' GROUP BY time(\" + TimePrecision + \") FILL(\" + FillType + \")\";\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":690,"y":1000,"wires":[["f6866dd5.89133"]]},{"id":"e46f69fe.02c9b8","type":"comment","z":"24452d0f.268b22","name":"HTF L3","info":"","x":550,"y":120,"wires":[]},{"id":"ead17b10.7d5718","type":"comment","z":"24452d0f.268b22","name":"HTF L3 - Boiler Side","info":"","x":750,"y":440,"wires":[]},{"id":"98ec2ec8.6ccad","type":"ui_dropdown","z":"24452d0f.268b22","name":"ui DropDown Select Time","label":"Last","tooltip":"","place":"24 Hours","group":"178e454e.d8d41b","order":1,"width":24,"height":1,"passthru":false,"multiple":false,"options":[{"label":"Actual","value":"Actual","type":"str"},{"label":"1 Minute","value":"1m","type":"str"},{"label":"5 Minutes","value":"5m","type":"str"},{"label":"10 Minutes","value":"10m","type":"str"},{"label":"15 Minutes","value":"15m","type":"str"},{"label":"30 Minutes","value":"30m","type":"str"},{"label":"1 Hour","value":"1h","type":"str"},{"label":"2 Hours","value":"2h","type":"str"},{"label":"4 Hours","value":"4h","type":"str"},{"label":"8 Hours","value":"8h","type":"str"},{"label":"16 Hours","value":"16h","type":"str"},{"label":"24 Hours","value":"24h","type":"str"},{"label":"48 Hours","value":"48h","type":"str"}],"payload":"","topic":"","x":470,"y":220,"wires":[["2fd45be1.215a14"]]},{"id":"ceda63a6.6b39f","type":"function","z":"24452d0f.268b22","name":"Select","func":"Data = {\n    \"TagField\": [\"HTF_L3_INLET_Temp_BoilerSd\", \"HTF_L3_INLET_Pressure_BoilerSd\",\"HTF_L3_OUTLET_Temp_BoilerSd\",\"HTF_L3_OUTLET_Pressure_BoilerSd\"],\n    \"NameField\": []\n};\n\nvar Query =\"\";\nvar VarName = \"\";\n\nif (msg.payload == \"Actual\") {\n    //Query = \"SELECT last(\" + VarName + \") FROM Boiler3 WHERE Grp='HTF_L3' AND Side='BOILER3' FILL(none)\";\n} else {\n    Query += \"SELECT\";\n    for (var i in Data.TagField) {\n        Query += \" mean(\" + Data.TagField[i] + \"),\";\n        Query += \" max(\" + Data.TagField[i] + \"), \";\n        Query += \" min(\" + Data.TagField[i] + \"), \";\n        Query += \" max(\" + Data.TagField[i] + \") - min(\" + Data.TagField[i] + \")\";\n        if (i < (Data.TagField.length - 1)) {\n            Query += \",\";\n        }\n    }\n    Query += \" FROM Boiler3 WHERE time > now() - \" + msg.payload + \" AND time < now() AND Grp='HTF_L3' AND Side='BOILER3' FILL(none)\";\n}\nmsg.query = Query;\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":490,"y":620,"wires":[["702a8ad0.0417a4"]]},{"id":"702a8ad0.0417a4","type":"influxdb in","z":"24452d0f.268b22","influxdb":"f60a0ee9.cecd2","name":"teste","query":"","rawOutput":true,"precision":"","retentionPolicy":"","x":490,"y":680,"wires":[["1f7af228.6d81de"]]},{"id":"2fd45be1.215a14","type":"link out","z":"24452d0f.268b22","name":"UiDropSelectTimeHTF111","links":["1d59b90.386fd47","23fff9f5.e93856","2a76012a.0ab16e","45be5c0.624d2a4","72ed23e8.26619c","77221d9f.0fa764","7b872f96.b899f","7ed1ec55.869234","ae44bfdd.e35c8","ae97f509.7aa638","c2443802.4a5848","c529c381.38dc2","d25199af.9e64e8","dd22ecee.9ea41","ef2abca9.b672a"],"x":655,"y":220,"wires":[]},{"id":"c529c381.38dc2","type":"link in","z":"24452d0f.268b22","name":"","links":["2fd45be1.215a14"],"x":495,"y":560,"wires":[["ceda63a6.6b39f"]]},{"id":"ae97f509.7aa638","type":"link in","z":"24452d0f.268b22","name":"","links":["2fd45be1.215a14"],"x":755,"y":520,"wires":[["b5f5d69b.fc2d48"]]},{"id":"6a316ba0.23cf34","type":"comment","z":"24452d0f.268b22","name":"HTF L3 - SA Side","info":"","x":740,"y":880,"wires":[]},{"id":"2f7e9f8d.ee356","type":"function","z":"24452d0f.268b22","name":"Select ","func":"Data = {\n    \"TagField\": [\"HTF_L3_INLET_Temp\", \"HTF_L3_INLET_Pressure\",\"HTF_L3_OUTLET_Temp\",\"HTF_L3_OUTLET_Pressure\"],\n    \"NameField\": []\n};\n\nvar Query =\"\";\nvar VarName = \"\";\n\nif (msg.payload == \"Actual\") {\n    //Query = \"SELECT last(\" + VarName + \") FROM Boiler3 WHERE Grp='HTF_L3' AND Side='BOILER3' FILL(none)\";\n} else {\n    Query += \"SELECT\";\n    for (var i in Data.TagField) {\n        Query += \" mean(\" + Data.TagField[i] + \"),\";\n        Query += \" max(\" + Data.TagField[i] + \"), \";\n        Query += \" min(\" + Data.TagField[i] + \"), \";\n        Query += \" max(\" + Data.TagField[i] + \") - min(\" + Data.TagField[i] + \")\";\n        if (i < (Data.TagField.length - 1)) {\n            Query += \",\";\n        }\n    }\n    Query += \" FROM Boiler3 WHERE time > now() - \" + msg.payload + \" AND time < now() AND Grp='HTF_L3' AND Side='SA' FILL(none)\";\n}\nmsg.query = Query;\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":410,"y":1040,"wires":[["5262053d.2d0bfc"]]},{"id":"5262053d.2d0bfc","type":"influxdb in","z":"24452d0f.268b22","influxdb":"f60a0ee9.cecd2","name":"teste","query":"","rawOutput":true,"precision":"s","retentionPolicy":"","x":410,"y":1100,"wires":[["65d91156.dd45f"]]},{"id":"dd22ecee.9ea41","type":"link in","z":"24452d0f.268b22","name":"","links":["2fd45be1.215a14"],"x":415,"y":980,"wires":[["2f7e9f8d.ee356"]]},{"id":"72ed23e8.26619c","type":"link in","z":"24452d0f.268b22","name":"","links":["2fd45be1.215a14"],"x":695,"y":940,"wires":[["87ddfb23.d11598"]]},{"id":"1f7af228.6d81de","type":"ui_template","z":"24452d0f.268b22","group":"fde15ac0.f452c8","name":"Press","order":3,"width":7,"height":5,"format":"<style>\n#customers1 {\n    /*width: 600px;*/ \n    border-collapse: collapse; \n    margin: 1px auto;\n}\n\n#customers1 td, #customers1 th {\n    padding: 5px;  /*height rectangle with value*/\n    font-weight: bold; \n    text-align: right;\n    /*width: 800px;*/\n    font-size: 12px; /*font size*/\n    white-space: nowrap;\n    overflow: hidden;\n}\n\n#customers1 tr:nth-child(even){\n    background: #eee; \n}\n\n#customers1 tr:hover {\n    background-color: #ddd;\n}\n\n#customers1 th {\n    background: #414c6a; \n    color: white; \n    font-weight: bold; \n    text-align: center; \n}\n\n</style>\n<div id=\"customers1\">\n    <table id=\"t02\" class=\"mytable2\" ng-repeat=\"res in msg.payload.results\" >\n\n        <tr>\n            <th> Tag. </th>\n            <th> Mean. </th>\n            <th><font color= #fd625e><i class=\"fa fa-arrow-up\" aria-hidden=\"true\"></i></font> Max. </th>\n            <th><font color= #f2c80f><i class=\"fa fa-arrow-down\" aria-hidden=\"true\"></i></font> Mix. </th>\n            <th><font color= #FF7F0E><i class=\"fa fa-play fa-rotate-270\" aria-hidden=\"true\"></i></font> Delta </th>\n        </tr>\n        <tr ng-repeat=\"x in msg.payload.results[0].series[0].values\">\n            <td font-size=10px;>Temp. Cw</td>\n            <td>{{(msg.payload.results[0].series[0].values[$index][1]).toFixed(2)}} ºC</td>\n            <td>{{(msg.payload.results[0].series[0].values[$index][2]).toFixed(2)}} ºC</td>\n            <td>{{(msg.payload.results[0].series[0].values[$index][3]).toFixed(2)}} ºC</td>\n            <td>{{(msg.payload.results[0].series[0].values[$index][4]).toFixed(2)}} ºC</td>\n        </tr>\n        <tr>\n            <td>Press. Cw</td>\n            <td>{{(msg.payload.results[0].series[0].values[$index][5]).toFixed(2)}} Bar</td>\n            <td>{{(msg.payload.results[0].series[0].values[$index][6]).toFixed(2)}} Bar</td>\n            <td>{{(msg.payload.results[0].series[0].values[$index][7]).toFixed(2)}} Bar</td>\n            <td>{{(msg.payload.results[0].series[0].values[$index][8]).toFixed(2)}} Bar</td>\n        </tr>\n        <tr>\n            <td>Press. Ccw</td>\n            <td>{{(msg.payload.results[0].series[0].values[$index][9]).toFixed(2)}} Bar</td>\n            <td>{{(msg.payload.results[0].series[0].values[$index][10]).toFixed(2)}} Bar</td>\n            <td>{{(msg.payload.results[0].series[0].values[$index][11]).toFixed(2)}} Bar</td>\n            <td>{{(msg.payload.results[0].series[0].values[$index][12]).toFixed(2)}} Bar</td>\n        </tr>\n        <tr>\n            <td>Temp. Ccw</td>\n            <td>{{(msg.payload.results[0].series[0].values[$index][13]).toFixed(2)}} ºC</td>\n            <td>{{(msg.payload.results[0].series[0].values[$index][14]).toFixed(2)}} ºC</td>\n            <td>{{(msg.payload.results[0].series[0].values[$index][15]).toFixed(2)}} ºC</td>\n            <td>{{(msg.payload.results[0].series[0].values[$index][16]).toFixed(2)}} ºC</td>\n        </tbody>\n    </table>\n</div>\n\n\n\n\n","storeOutMessages":true,"fwdInMessages":false,"resendOnRefresh":true,"templateScope":"local","x":490,"y":740,"wires":[[]],"info":" <tr ng-repeat=\"row in msg.payload\" >\n <td ng-repeat=\"item in row\" bgcolor=lightgrey>{{item}}</td>"},{"id":"65d91156.dd45f","type":"ui_template","z":"24452d0f.268b22","group":"2df10b90.0ed104","name":"Press","order":4,"width":"7","height":"5","format":"<style>\n#customers1 {\n    /*width: 600px;*/ \n    border-collapse: collapse; \n    margin: 1px auto;\n}\n\n#customers1 td, #customers1 th {\n    padding: 5px;  /*height rectangle with value*/\n    /*font-weight: bold; */\n    text-align: right;\n    /*width: 800px;*/\n    font-size: 12px; /*font size*/\n    margin: 1px;\n    white-space: nowrap;\n    overflow: hidden;\n}\n\n#customers1 tr:nth-child(even){\n    background: #eee; \n}\n\n#customers1 tr:hover {\n    background-color: #ddd;\n}\n\n#customers1 th {\n    background: #414c6a; \n    color: white; \n    font-weight: bold; \n    text-align: center; \n}\n</style>\n<div id=\"customers1\">\n    <table id=\"t02\" class=\"mytable2\" ng-repeat=\"res in msg.payload.results\" >\n\n        <tr>\n            <th> Tag. </th>\n            <th> Mean. </th>\n            <th><font color= #fd625e><i class=\"fa fa-arrow-up\" aria-hidden=\"true\"></i></font> Max. </th>\n            <th><font color= #f2c80f><i class=\"fa fa-arrow-down\" aria-hidden=\"true\"></i></font> Mix. </th>\n            <th><font color= #FF7F0E><i class=\"fa fa-play fa-rotate-270\" aria-hidden=\"true\"></i></font> Delta </th>\n        </tr>\n        <tr ng-repeat=\"x in msg.payload.results[0].series[0].values\">\n            <td font-size=10px;>Temp. Cw</td>\n            <td>{{(msg.payload.results[0].series[0].values[$index][1]).toFixed(2)}} ºC</td>\n            <td>{{(msg.payload.results[0].series[0].values[$index][2]).toFixed(2)}} ºC</td>\n            <td>{{(msg.payload.results[0].series[0].values[$index][3]).toFixed(2)}} ºC</td>\n            <td>{{(msg.payload.results[0].series[0].values[$index][4]).toFixed(2)}} ºC</td>\n        </tr>\n        <tr>\n            <td>Press. Cw</td>\n            <td>{{(msg.payload.results[0].series[0].values[$index][5]).toFixed(2)}} Bar</td>\n            <td>{{(msg.payload.results[0].series[0].values[$index][6]).toFixed(2)}} Bar</td>\n            <td>{{(msg.payload.results[0].series[0].values[$index][7]).toFixed(2)}} Bar</td>\n            <td>{{(msg.payload.results[0].series[0].values[$index][8]).toFixed(2)}} Bar</td>\n        </tr>\n        <tr>\n            <td>Press. Ccw</td>\n            <td>{{(msg.payload.results[0].series[0].values[$index][9]).toFixed(2)}} Bar</td>\n            <td>{{(msg.payload.results[0].series[0].values[$index][10]).toFixed(2)}} Bar</td>\n            <td>{{(msg.payload.results[0].series[0].values[$index][11]).toFixed(2)}} Bar</td>\n            <td>{{(msg.payload.results[0].series[0].values[$index][12]).toFixed(2)}} Bar</td>\n        </tr>\n        <tr>\n            <td>Temp. Ccw</td>\n            <td>{{(msg.payload.results[0].series[0].values[$index][13]).toFixed(2)}} ºC</td>\n            <td>{{(msg.payload.results[0].series[0].values[$index][14]).toFixed(2)}} ºC</td>\n            <td>{{(msg.payload.results[0].series[0].values[$index][15]).toFixed(2)}} ºC</td>\n            <td>{{(msg.payload.results[0].series[0].values[$index][16]).toFixed(2)}} ºC</td>\n        </tbody>\n    </table>\n</div>\n\n\n\n\n","storeOutMessages":true,"fwdInMessages":true,"resendOnRefresh":true,"templateScope":"local","x":410,"y":1160,"wires":[[]]},{"id":"2b8b50b4.2b844","type":"debug","z":"24452d0f.268b22","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":1020,"y":320,"wires":[]},{"id":"208510f5.7a2ce","type":"influxdb in","z":"24452d0f.268b22","influxdb":"f60a0ee9.cecd2","name":"Query Influx","query":"","rawOutput":false,"precision":"","retentionPolicy":"","x":430,"y":1640,"wires":[["7ee9cf8f.79bb7"]]},{"id":"37e2a919.b8ac56","type":"ui_dropdown","z":"24452d0f.268b22","name":"","label":"Measurements","tooltip":"","place":"Select option","group":"63fb94a1.41009c","order":2,"width":"8","height":"1","passthru":true,"multiple":false,"options":[{"label":"","value":"","type":"str"}],"payload":"","topic":"","x":420,"y":1760,"wires":[["1d028e5f.41a442"]]},{"id":"7ee9cf8f.79bb7","type":"function","z":"24452d0f.268b22","name":"Load Measu. in Box","func":"//as per info panel, the data needs to be formatted\n//as [ \"Choice 1\", \"Choice 2\", {\"Choice 3\":\"3\"} ]\n//and sent in msg.options.\nmsg.options = [];//create empty array\nfor(let i = 0; i < msg.payload.length; i++){\n    let row = msg.payload[i]; //get the row\n    let opt = {};//make new opt object\n    opt[row.name] = row.name;  //add a propery to object called row[0] & set its value to row[1]\n    msg.options.push(opt);//add the opt to array    \n}\nreturn msg;//pass the msg (containing our options) to the next node","outputs":1,"noerr":0,"initialize":"","finalize":"","x":440,"y":1700,"wires":[["37e2a919.b8ac56"]]},{"id":"436a326b.22d53c","type":"ui_dropdown","z":"24452d0f.268b22","name":"","label":"Area","tooltip":"","place":"Select Area","group":"63fb94a1.41009c","order":1,"width":"8","height":"1","passthru":false,"multiple":false,"options":[{"label":"TermoFluído","value":"Termofluido","type":"str"},{"label":"Caldeira","value":"Boiler3","type":"str"},{"label":"Secador 3","value":"Dryer3","type":"str"},{"label":"Secador 2","value":"Dryer2","type":"str"},{"label":"Refinador 1","value":"Refiner1","type":"str"},{"label":"Refinador 2","value":"Refiner2","type":"str"},{"label":"Condensados","value":"Condensados","type":"str"},{"label":"Gases Quentes","value":"GasesQuentes","type":"str"}],"payload":"","topic":"","x":410,"y":1520,"wires":[["90545656.96c3d8"]]},{"id":"90545656.96c3d8","type":"function","z":"24452d0f.268b22","name":"Select Area","func":"\nmsg.query = \"SHOW MEASUREMENTS ON Sonae WHERE Area='\"+msg.payload+\"'\";\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":430,"y":1580,"wires":[["208510f5.7a2ce"]]},{"id":"1d028e5f.41a442","type":"function","z":"24452d0f.268b22","name":"","func":"\n//Var's\nvar TimePrecision = \"10m\";\nvar FillType=\"none\";\n//var Lb3= \"\\\"Flow (Ton/h)\\\"\";\nvar teste=\"\";\nteste+=\"\\\"\"+msg.payload+\"\\\"\";\n\n\nmsg.query = \"SELECT mean(*) FROM \" + teste + \" WHERE time > now() - 1h AND time < now() GROUP BY time(\" + TimePrecision + \") FILL(\" + FillType + \")\";\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":400,"y":1820,"wires":[["f7a9a124.758dd"]]},{"id":"7d5912b8.c9dfcc","type":"ui_chart","z":"24452d0f.268b22","name":"ui chart HTF L3 SA Side","group":"63fb94a1.41009c","order":1,"width":"23","height":6,"label":"","chartType":"line","legend":"true","xformat":"auto","interpolate":"cubic","nodata":"","dot":false,"ymin":"","ymax":"","removeOlder":"0","removeOlderPoints":"","removeOlderUnit":"3600","cutout":0,"useOneColor":false,"useUTC":false,"colors":["#1f77b4","#aec7e8","#ff7f0e","#2ca02c","#98df8a","#d62728","#ff9896","#9467bd","#c5b0d5"],"useOldStyle":false,"outputs":1,"x":410,"y":2000,"wires":[[]]},{"id":"f7a9a124.758dd","type":"influxdb in","z":"24452d0f.268b22","influxdb":"f60a0ee9.cecd2","name":"teste","query":"","rawOutput":true,"precision":"ms","retentionPolicy":"","x":390,"y":1880,"wires":[["2464335e.0526cc","9c434593.a3a838","9c7c8879.8c86f8"]]},{"id":"2464335e.0526cc","type":"change","z":"24452d0f.268b22","name":"to JSONata","rules":[{"t":"set","p":"payload","pt":"msg","to":"payload.results.[\t    {\t        \"series\": [\"Temp.CW (ºC)\",\"Press.CW (Bar)\",\"Press.CCW (Bar)\",\"Temp.CCW (ºC)\",\"Flow (m3/h)\"],\t        \"labels\": [\t            series[0].values.$fromMillis($[0], '[D01] [H1]:[M01]:[s01]','+0100')\t        ],\t        \"data\": [\t            [series.values.($boolean($[1])?$round($[1],2):$[1])],\t            [series.values.($boolean($[2])?$round($[2],2):$[2])],\t            [series.values.($boolean($[3])?$round($[3],2):$[3])],\t            [series.values.($boolean($[4])?$round($[4],2):$[4])],\t            [series.values.($boolean($[5])?$round($[5],2):$[5])]\t         ]\t    }\t \t]","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":390,"y":1940,"wires":[["7d5912b8.c9dfcc"]],"info":"payload.results.[ \n   {\n       \"series\": [\"Temp\",\"Humd\"],\n       \"labels\": [series.columns[1],series.columns[2]],\n       \"data\": [\n       \n               [series.values.{\"x\": $[0]*1000,\"y\": $round($[1], 2)}],\n               [series.values.{\"x\": $[0]*1000,\"y\": $round($[2], 2)}]\n           \n       ]\n    \n\n   \n   }\n\n]"},{"id":"9c7c8879.8c86f8","type":"debug","z":"24452d0f.268b22","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":640,"y":1860,"wires":[]},{"id":"9c434593.a3a838","type":"function","z":"24452d0f.268b22","name":"","func":"//\n// Format the InfluxDB results to match the charts JSON format\n//\n\nvar series = [\"1\",\"2\",\"3\",\"4\",\"5\"];\nvar labels = [\"Data Values\"];\nvar jsondata = [];\nvar data =[];\nvar thetime = \"\";\nvar val=\"\";\n\n\ndata = '[[';\nvar arrSize = msg.payload.results[0].series[0].values[0].length;\nvar arrValueSize = msg.payload.results[0].series[0].columns.length;\n\nnode.warn(\"arrSize=\"+arrSize);\nnode.warn(\"arrValueSize=\"+arrValueSize);\n\nfor (var j = 1; j < arrValueSize; j++) {\n    for (var i = 0; i < arrSize; i++) { \n        \n        thetime = Number(msg.payload.results[0].series[0].values[i][0]); \n        val = Number(msg.payload.results[0].series[0].values[i][j].toFixed(2));\n        \n        data +='{ \"x\":' + thetime + ', \"y\":' + val + '}';\n        \n        if (i < (arrSize - 1)) {\n            data += \",\";\n        }\n    }\n    if (j < (arrSize - 1)) {\n        data += '],[';\n    } else {\n        data += ']]';\n    }\n}\nnode.warn(\"data=\"+data);\n\njsondata = JSON.parse(data);\n\nflow.set(\"jsondata\",jsondata);\n\nnode.warn(\"jsondata=\"+jsondata);\n\n\nmsg.payload = [{ \"series\": series, \"data\": jsondata, \"labels\": labels }];\nmsg.playload = data;\n//msg.teste = jsondata;\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":740,"y":2100,"wires":[["81236a2a.706fa8","12b64a18.598326"]]},{"id":"12b64a18.598326","type":"ui_chart","z":"24452d0f.268b22","name":"ui chart HTF L3 SA Side","group":"63fb94a1.41009c","order":1,"width":"23","height":6,"label":"bj j hj","chartType":"line","legend":"true","xformat":"auto","interpolate":"cubic","nodata":"","dot":false,"ymin":"","ymax":"","removeOlder":"0","removeOlderPoints":"","removeOlderUnit":"3600","cutout":0,"useOneColor":false,"useUTC":false,"colors":["#1f77b4","#aec7e8","#ff7f0e","#2ca02c","#98df8a","#d62728","#ff9896","#9467bd","#c5b0d5"],"useOldStyle":false,"outputs":1,"x":1050,"y":2100,"wires":[[]]},{"id":"81236a2a.706fa8","type":"debug","z":"24452d0f.268b22","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":950,"y":1960,"wires":[]},{"id":"1c35a5d1.e6bd1a","type":"inject","z":"24452d0f.268b22","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"{\"payload\":{\"results\":[{\"series\":[{\"name\":\"57M41\",\"columns\":[\"time\",\"mean_HTF_L3_B2_Amp\",\"mean_HTF_L3_B2_Bearing_Temp\",\"mean_HTF_L3_B2_Mode\",\"mean_HTF_L3_B2_Pressure\",\"mean_HTF_L3_B2_Speed\",\"mean_HTF_L3_B2_Status\"],\"values\":[[1598926800000,-369.78,23.607499999999998,8,0,-118.52,2],[1598927400000,-369.77999999999986,23.543333333333337,8,0,-118.52000000000018,2],[1598928000000,-369.77999999999986,23.59050000000001,8,0,-118.52000000000018,2],[1598928600000,-369.77999999999986,23.584999999999997,8,0,-118.52000000000018,2],[1598929200000,-369.77999999999986,23.41666666666667,8,0,-118.52000000000018,2],[1598929800000,-369.77999999999986,23.445333333333355,8,0,-118.52000000000018,2],[1598930400000,-369.7799999999999,23.319285714285705,8,0,-118.52000000000017,2]]}]}]},\"socketid\":\"7aOltWVj5cOqdcHNAABX\",\"_msgid\":\"362c6dc3.1c8e22\",\"query\":\"SELECT mean(*) FROM \\\"57M41\\\" WHERE time > now() - 1h AND time < now() GROUP BY time(10m) FILL(none)\"}","payloadType":"json","x":490,"y":2120,"wires":[["9c434593.a3a838"]]},{"id":"fde15ac0.f452c8","type":"ui_group","z":"","name":"Boiler Side","tab":"8b9dbe71.c2868","order":2,"disp":true,"width":"30","collapse":true},{"id":"f60a0ee9.cecd2","type":"influxdb","z":"","hostname":"127.0.0.1","port":"8086","protocol":"http","database":"Sonae","name":"InfluxSonaeSv08","usetls":false,"tls":""},{"id":"2df10b90.0ed104","type":"ui_group","z":"","name":"Sa Side","tab":"8b9dbe71.c2868","order":3,"disp":true,"width":"30","collapse":true},{"id":"178e454e.d8d41b","type":"ui_group","z":"","name":"Group 1","tab":"8b9dbe71.c2868","order":1,"disp":false,"width":"30","collapse":false},{"id":"63fb94a1.41009c","type":"ui_group","z":"","name":"Group 1","tab":"87612ece.28db9","order":1,"disp":true,"width":"24","collapse":false},{"id":"8b9dbe71.c2868","type":"ui_tab","z":"","name":"Teste","icon":"dashboard","order":7,"disabled":false,"hidden":false},{"id":"87612ece.28db9","type":"ui_tab","z":"","name":"Tab 3","icon":"dashboard","order":9,"disabled":false,"hidden":false}]

Hi Christiano,

You defined data as an array yet you try to add objects to that array like a string with

data +='{ "x":' + thetime + ', "y":' + val + '}';

shouldnt that be data.push({ .. your object ...});
example on push()

hello

ty for the help, i tried and now sometimes i get this msg ""TypeError: Cannot read property '0' of undefined"" but the function works.

Maybe its because of [0]

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