Plotting array wont work

Hello everyone,

i am trying to plot this array (which i think is correct) but it wont work...

[{"series":["Frequentie","Totaal_Vermogen","Spanning_L1","Spanning_L2","Spanning_L3","Stroom_L1net","Stroom_L2net","Stroom_L3net","Stroom_L1auto","Stroom_L2auto","Stroom_L3auto"],"data":[[{"x":"\"2022-05-09T13:50:14.000Z\"","y":50.01},{"x":"\"2022-05-09T13:50:15.000Z\"","y":50},{"x":"\"2022-05-09T13:50:16.000Z\"","y":50},{"x":"\"2022-05-09T13:50:17.000Z\"","y":49.99},{"x":"\"2022-05-09T13:50:18.000Z\"","y":50},{"x":"\"2022-05-09T13:50:19.000Z\"","y":49.99},{"x":"\"2022-05-09T13:50:20.000Z\"","y":49.99},{"x":"\"2022-05-09T13:50:21.000Z\"","y":49.99},{"x":"\"2022-05-09T13:50:22.000Z\"","y":49.99},{"x":"\"2022-05-09T13:50:23.000Z\"","y":49.99}],[{"x":"\"2022-05-09T13:50:14.000Z\"","y":11},{"x":"\"2022-05-09T13:50:15.000Z\"","y":11},{"x":"\"2022-05-09T13:50:16.000Z\"","y":11},{"x":"\"2022-05-09T13:50:17.000Z\"","y":11},{"x":"\"2022-05-09T13:50:18.000Z\"","y":11},{"x":"\"2022-05-09T13:50:19.000Z\"","y":10},{"x":"\"2022-05-09T13:50:20.000Z\"","y":11},{"x":"\"2022-05-09T13:50:21.000Z\"","y":11},{"x":"\"2022-05-09T13:50:22.000Z\"","y":11},{"x":"\"2022-05-09T13:50:23.000Z\"","y":11}],[{"x":"\"2022-05-09T13:50:14.000Z\"","y":241},{"x":"\"2022-05-09T13:50:15.000Z\"","y":241},{"x":"\"2022-05-09T13:50:16.000Z\"","y":241},{"x":"\"2022-05-09T13:50:17.000Z\"","y":241},{"x":"\"2022-05-09T13:50:18.000Z\"","y":241},{"x":"\"2022-05-09T13:50:19.000Z\"","y":241},{"x":"\"2022-05-09T13:50:20.000Z\"","y":241},{"x":"\"2022-05-09T13:50:21.000Z\"","y":241},{"x":"\"2022-05-09T13:50:22.000Z\"","y":241},{"x":"\"2022-05-09T13:50:23.000Z\"","y":241}],[{"x":"\"2022-05-09T13:50:14.000Z\"","y":242},{"x":"\"2022-05-09T13:50:15.000Z\"","y":241},{"x":"\"2022-05-09T13:50:16.000Z\"","y":241},{"x":"\"2022-05-09T13:50:17.000Z\"","y":241},{"x":"\"2022-05-09T13:50:18.000Z\"","y":241},{"x":"\"2022-05-09T13:50:19.000Z\"","y":241},{"x":"\"2022-05-09T13:50:20.000Z\"","y":241},{"x":"\"2022-05-09T13:50:21.000Z\"","y":241},{"x":"\"2022-05-09T13:50:22.000Z\"","y":241},{"x":"\"2022-05-09T13:50:23.000Z\"","y":241}],[{"x":"\"2022-05-09T13:50:14.000Z\"","y":242},{"x":"\"2022-05-09T13:50:15.000Z\"","y":242},{"x":"\"2022-05-09T13:50:16.000Z\"","y":241},{"x":"\"2022-05-09T13:50:17.000Z\"","y":242},{"x":"\"2022-05-09T13:50:18.000Z\"","y":242},{"x":"\"2022-05-09T13:50:19.000Z\"","y":242},{"x":"\"2022-05-09T13:50:20.000Z\"","y":241},{"x":"\"2022-05-09T13:50:21.000Z\"","y":241},{"x":"\"2022-05-09T13:50:22.000Z\"","y":241},{"x":"\"2022-05-09T13:50:23.000Z\"","y":241}],[{"x":"\"2022-05-09T13:50:14.000Z\"","y":1},{"x":"\"2022-05-09T13:50:15.000Z\"","y":1},{"x":"\"2022-05-09T13:50:16.000Z\"","y":1},{"x":"\"2022-05-09T13:50:17.000Z\"","y":1},{"x":"\"2022-05-09T13:50:18.000Z\"","y":1},{"x":"\"2022-05-09T13:50:19.000Z\"","y":1},{"x":"\"2022-05-09T13:50:20.000Z\"","y":1},{"x":"\"2022-05-09T13:50:21.000Z\"","y":1},{"x":"\"2022-05-09T13:50:22.000Z\"","y":1},{"x":"\"2022-05-09T13:50:23.000Z\"","y":1}],[{"x":"\"2022-05-09T13:50:14.000Z\"","y":0},{"x":"\"2022-05-09T13:50:15.000Z\"","y":0},{"x":"\"2022-05-09T13:50:16.000Z\"","y":0},{"x":"\"2022-05-09T13:50:17.000Z\"","y":0},{"x":"\"2022-05-09T13:50:18.000Z\"","y":0},{"x":"\"2022-05-09T13:50:19.000Z\"","y":0},{"x":"\"2022-05-09T13:50:20.000Z\"","y":0},{"x":"\"2022-05-09T13:50:21.000Z\"","y":0},{"x":"\"2022-05-09T13:50:22.000Z\"","y":0},{"x":"\"2022-05-09T13:50:23.000Z\"","y":0}],[{"x":"\"2022-05-09T13:50:14.000Z\"","y":0},{"x":"\"2022-05-09T13:50:15.000Z\"","y":0},{"x":"\"2022-05-09T13:50:16.000Z\"","y":0},{"x":"\"2022-05-09T13:50:17.000Z\"","y":0},{"x":"\"2022-05-09T13:50:18.000Z\"","y":0},{"x":"\"2022-05-09T13:50:19.000Z\"","y":0},{"x":"\"2022-05-09T13:50:20.000Z\"","y":0},{"x":"\"2022-05-09T13:50:21.000Z\"","y":0},{"x":"\"2022-05-09T13:50:22.000Z\"","y":0},{"x":"\"2022-05-09T13:50:23.000Z\"","y":0}],[{"x":"\"2022-05-09T13:50:14.000Z\"","y":0},{"x":"\"2022-05-09T13:50:15.000Z\"","y":0},{"x":"\"2022-05-09T13:50:16.000Z\"","y":0},{"x":"\"2022-05-09T13:50:17.000Z\"","y":0},{"x":"\"2022-05-09T13:50:18.000Z\"","y":0},{"x":"\"2022-05-09T13:50:19.000Z\"","y":0},{"x":"\"2022-05-09T13:50:20.000Z\"","y":0},{"x":"\"2022-05-09T13:50:21.000Z\"","y":0},{"x":"\"2022-05-09T13:50:22.000Z\"","y":0},{"x":"\"2022-05-09T13:50:23.000Z\"","y":0}],[{"x":"\"2022-05-09T13:50:14.000Z\"","y":0},{"x":"\"2022-05-09T13:50:15.000Z\"","y":0},{"x":"\"2022-05-09T13:50:16.000Z\"","y":0},{"x":"\"2022-05-09T13:50:17.000Z\"","y":0},{"x":"\"2022-05-09T13:50:18.000Z\"","y":0},{"x":"\"2022-05-09T13:50:19.000Z\"","y":0},{"x":"\"2022-05-09T13:50:20.000Z\"","y":0},{"x":"\"2022-05-09T13:50:21.000Z\"","y":0},{"x":"\"2022-05-09T13:50:22.000Z\"","y":0},{"x":"\"2022-05-09T13:50:23.000Z\"","y":0}],[{"x":"\"2022-05-09T13:50:14.000Z\"","y":0},{"x":"\"2022-05-09T13:50:15.000Z\"","y":0},{"x":"\"2022-05-09T13:50:16.000Z\"","y":0},{"x":"\"2022-05-09T13:50:17.000Z\"","y":0},{"x":"\"2022-05-09T13:50:18.000Z\"","y":0},{"x":"\"2022-05-09T13:50:19.000Z\"","y":0},{"x":"\"2022-05-09T13:50:20.000Z\"","y":0},{"x":"\"2022-05-09T13:50:21.000Z\"","y":0},{"x":"\"2022-05-09T13:50:22.000Z\"","y":0},{"x":"\"2022-05-09T13:50:23.000Z\"","y":0}]],"labels":[""]}]

does anyone see what i am doing wrong ?

Olivia

Youe x times are not correct
"x": "\"2022-05-09T13:50:14.000Z\"",
you need to remove the \"'s, how is the object created?

This code reads the data from a CSV file

DATA:

[{"Tijd":"\"2022-05-09T13:50:14.000Z\"","Frequentie":50.01,"Totaal_vermogen":11,"Spanning_L1":241,"Spanning_L2":242,"Spanning_L3":242,"Stroom_L1net":1,"Stroom_L2net":0,"Stroom_L3net":0,"Stroom_L1auto":0,"Stroom_L2auto":0,"Stroom_L3auto":0},{"Tijd":"\"2022-05-09T13:50:15.000Z\"","Frequentie":50,"Totaal_vermogen":11,"Spanning_L1":241,"Spanning_L2":241,"Spanning_L3":242,"Stroom_L1net":1,"Stroom_L2net":0,"Stroom_L3net":0,"Stroom_L1auto":0,"Stroom_L2auto":0,"Stroom_L3auto":0},{"Tijd":"\"2022-05-09T13:50:16.000Z\"","Frequentie":50,"Totaal_vermogen":11,"Spanning_L1":241,"Spanning_L2":241,"Spanning_L3":241,"Stroom_L1net":1,"Stroom_L2net":0,"Stroom_L3net":0,"Stroom_L1auto":0,"Stroom_L2auto":0,"Stroom_L3auto":0},{"Tijd":"\"2022-05-09T13:50:17.000Z\"","Frequentie":49.99,"Totaal_vermogen":11,"Spanning_L1":241,"Spanning_L2":241,"Spanning_L3":242,"Stroom_L1net":1,"Stroom_L2net":0,"Stroom_L3net":0,"Stroom_L1auto":0,"Stroom_L2auto":0,"Stroom_L3auto":0},{"Tijd":"\"2022-05-09T13:50:18.000Z\"","Frequentie":50,"Totaal_vermogen":11,"Spanning_L1":241,"Spanning_L2":241,"Spanning_L3":242,"Stroom_L1net":1,"Stroom_L2net":0,"Stroom_L3net":0,"Stroom_L1auto":0,"Stroom_L2auto":0,"Stroom_L3auto":0},{"Tijd":"\"2022-05-09T13:50:19.000Z\"","Frequentie":49.99,"Totaal_vermogen":10,"Spanning_L1":241,"Spanning_L2":241,"Spanning_L3":242,"Stroom_L1net":1,"Stroom_L2net":0,"Stroom_L3net":0,"Stroom_L1auto":0,"Stroom_L2auto":0,"Stroom_L3auto":0},{"Tijd":"\"2022-05-09T13:50:20.000Z\"","Frequentie":49.99,"Totaal_vermogen":11,"Spanning_L1":241,"Spanning_L2":241,"Spanning_L3":241,"Stroom_L1net":1,"Stroom_L2net":0,"Stroom_L3net":0,"Stroom_L1auto":0,"Stroom_L2auto":0,"Stroom_L3auto":0},{"Tijd":"\"2022-05-09T13:50:21.000Z\"","Frequentie":49.99,"Totaal_vermogen":11,"Spanning_L1":241,"Spanning_L2":241,"Spanning_L3":241,"Stroom_L1net":1,"Stroom_L2net":0,"Stroom_L3net":0,"Stroom_L1auto":0,"Stroom_L2auto":0,"Stroom_L3auto":0},{"Tijd":"\"2022-05-09T13:50:22.000Z\"","Frequentie":49.99,"Totaal_vermogen":11,"Spanning_L1":241,"Spanning_L2":241,"Spanning_L3":241,"Stroom_L1net":1,"Stroom_L2net":0,"Stroom_L3net":0,"Stroom_L1auto":0,"Stroom_L2auto":0,"Stroom_L3auto":0},{"Tijd":"\"2022-05-09T13:50:23.000Z\"","Frequentie":49.99,"Totaal_vermogen":11,"Spanning_L1":241,"Spanning_L2":241,"Spanning_L3":241,"Stroom_L1net":1,"Stroom_L2net":0,"Stroom_L3net":0,"Stroom_L1auto":0,"Stroom_L2auto":0,"Stroom_L3auto":0}]

CODE:

[{"id":"f74b1aecf9517dc2","type":"function","z":"5984625998a10b6e","name":"Format data for chart","func":"var chart = [{\n    \"series\":[\"Frequentie\",\"Totaal_Vermogen\",\"Spanning_L1\",\"Spanning_L2\",\"Spanning_L3\",\"Stroom_L1net\",\"Stroom_L2net\",\"Stroom_L3net\",\"Stroom_L1auto\",\"Stroom_L2auto\",\"Stroom_L3auto\"],\n    \"data\":[],\n    \"labels\":[\"\"]\n}];\n\n\nvar Frequentie = [];\nvar Totaal_vermogen = [];\nvar Spanning_L1 = [];\nvar Spanning_L2 = [];\nvar Spanning_L3 = [];\nvar Stroom_L1net = [];\nvar Stroom_L2net = [];\nvar Stroom_L3net = [];\nvar Stroom_L1auto = [];\nvar Stroom_L2auto = [];\nvar Stroom_L3auto = [];\n\nfor (var i=0; i<msg.payload.length; i++) {\n    Frequentie.push({\"x\":msg.payload[i].Tijd, \"y\":msg.payload[i].Frequentie});\n    Totaal_vermogen.push({\"x\":msg.payload[i].Tijd, \"y\":msg.payload[i].Totaal_vermogen});\n    Spanning_L1.push({\"x\":msg.payload[i].Tijd, \"y\":msg.payload[i].Spanning_L1});\n    Spanning_L2.push({\"x\":msg.payload[i].Tijd, \"y\":msg.payload[i].Spanning_L2});\n    Spanning_L3.push({\"x\":msg.payload[i].Tijd, \"y\":msg.payload[i].Spanning_L3});\n    Stroom_L1net.push({\"x\":msg.payload[i].Tijd, \"y\":msg.payload[i].Stroom_L1net});\n    Stroom_L2net.push({\"x\":msg.payload[i].Tijd, \"y\":msg.payload[i].Stroom_L2net});\n    Stroom_L3net.push({\"x\":msg.payload[i].Tijd, \"y\":msg.payload[i].Stroom_L3net});\n    Stroom_L1auto.push({\"x\":msg.payload[i].Tijd, \"y\":msg.payload[i].Stroom_L1auto});\n    Stroom_L2auto.push({\"x\":msg.payload[i].Tijd, \"y\":msg.payload[i].Stroom_L2auto});\n    Stroom_L3auto.push({\"x\":msg.payload[i].Tijd, \"y\":msg.payload[i].Stroom_L3auto});\n\n\n\n}\nchart[0].data.push(Frequentie);\nchart[0].data.push(Totaal_vermogen);\nchart[0].data.push(Spanning_L1);\nchart[0].data.push(Spanning_L2);\nchart[0].data.push(Spanning_L3);\nchart[0].data.push(Stroom_L1net);\nchart[0].data.push(Stroom_L2net);\nchart[0].data.push(Stroom_L3net);\nchart[0].data.push(Stroom_L1auto);\nchart[0].data.push(Stroom_L2auto);\nchart[0].data.push(Stroom_L3auto);\n\n\nmsg.payload = chart;\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":800,"y":1260,"wires":[["c2ceb9d12d353fe8","2baf02e24f629799"]]}]

you will need to replace the ".
or sort the csv to not use quotes around timestamp.

var chart = [{
    "series":["Frequentie","Totaal_Vermogen","Spanning_L1","Spanning_L2","Spanning_L3","Stroom_L1net","Stroom_L2net","Stroom_L3net","Stroom_L1auto","Stroom_L2auto","Stroom_L3auto"],
    "data":[],
    "labels":[""]
}];


var Frequentie = [];
var Totaal_vermogen = [];
var Spanning_L1 = [];
var Spanning_L2 = [];
var Spanning_L3 = [];
var Stroom_L1net = [];
var Stroom_L2net = [];
var Stroom_L3net = [];
var Stroom_L1auto = [];
var Stroom_L2auto = [];
var Stroom_L3auto = [];

for (var i=0; i<msg.payload.length; i++) {
    Frequentie.push({"x":msg.payload[i].Tijd.replace(/"/g,''), "y":msg.payload[i].Frequentie});
    Totaal_vermogen.push({"x":msg.payload[i].Tijd.replace(/"/g,''), "y":msg.payload[i].Totaal_vermogen});
    Spanning_L1.push({"x":msg.payload[i].Tijd.replace(/"/g,''), "y":msg.payload[i].Spanning_L1});
    Spanning_L2.push({"x":msg.payload[i].Tijd.replace(/"/g,''), "y":msg.payload[i].Spanning_L2});
    Spanning_L3.push({"x":msg.payload[i].Tijd.replace(/"/g,''), "y":msg.payload[i].Spanning_L3});
    Stroom_L1net.push({"x":msg.payload[i].Tijd.replace(/"/g,''), "y":msg.payload[i].Stroom_L1net});
    Stroom_L2net.push({"x":msg.payload[i].Tijd.replace(/"/g,''), "y":msg.payload[i].Stroom_L2net});
    Stroom_L3net.push({"x":msg.payload[i].Tijd.replace(/"/g,''), "y":msg.payload[i].Stroom_L3net});
    Stroom_L1auto.push({"x":msg.payload[i].Tijd.replace(/"/g,''), "y":msg.payload[i].Stroom_L1auto});
    Stroom_L2auto.push({"x":msg.payload[i].Tijd.replace(/"/g,''), "y":msg.payload[i].Stroom_L2auto});
    Stroom_L3auto.push({"x":msg.payload[i].Tijd.replace(/"/g,''), "y":msg.payload[i].Stroom_L3auto});



}
chart[0].data.push(Frequentie);
chart[0].data.push(Totaal_vermogen);
chart[0].data.push(Spanning_L1);
chart[0].data.push(Spanning_L2);
chart[0].data.push(Spanning_L3);
chart[0].data.push(Stroom_L1net);
chart[0].data.push(Stroom_L2net);
chart[0].data.push(Stroom_L3net);
chart[0].data.push(Stroom_L1auto);
chart[0].data.push(Stroom_L2auto);
chart[0].data.push(Stroom_L3auto);


msg.payload = chart;

return msg;
1 Like

Thanks, it works now !

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