Dashboard Graph from Sqlite3 data

Hi,
I 'm trying to plot a Graph from Sqlite3 data, so far so good.

This is working:

var dataout = [];
var a1 = [];
var payload = msg.payload
for (let i = 0; i < payload.length; i++) 
{
--->>>  var yy = payload[i].powerdc
  var temp1 = { "x": i, "y": yy }
  a1.push(temp1);
}
dataout = [ a1 ];

msg.payload = [{
  "series": [ "A" ],
  "data": dataout,
  "labels": ["B"]
}];
msg.topic = null
return msg;

This not:

var dataout = [];
var a1 = [];
var payload = msg.payload
for (let i = 0; i < payload.length; i++) 
{
--->>  var temp1 = { "x": i, "y": payload[i].powerdc }
  a1.push(temp1);
}
dataout = [ a1 ];

msg.payload = [{
  "series": [ "A" ],
  "data": dataout,
  "labels": ["B"]
}];
msg.topic = null
return msg;

does somebody knows the answer, thank you in advance.

r/Detlef

works for me

[{"id":"e96d996e7afed4b4","type":"inject","z":"b9860b4b9de8c8da","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"[{\"powerdc\":1}]","payloadType":"json","x":580,"y":240,"wires":[["0e1fcd0a05e4da11"]]},{"id":"0e1fcd0a05e4da11","type":"function","z":"b9860b4b9de8c8da","name":"function 22","func":"\nvar dataout = [];\nvar a1 = [];\nvar payload = msg.payload\nfor (let i = 0; i < payload.length; i++) \n{\n var temp1 = { \"x\": i, \"y\": payload[i].powerdc }\n  a1.push(temp1);\n}\ndataout = [ a1 ];\n\nmsg.payload = [{\n  \"series\": [ \"A\" ],\n  \"data\": dataout,\n  \"labels\": [\"B\"]\n}];\nmsg.topic = null\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":770,"y":240,"wires":[["aa16fb7889d3fdae"]]},{"id":"aa16fb7889d3fdae","type":"debug","z":"b9860b4b9de8c8da","name":"debug 329","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":950,"y":240,"wires":[]}]

but try not to use var and define temp1 outside loop


let dataout = [];
let a1 = [];
let payload = msg.payload
let temp1 = {}
for (let i = 0; i < payload.length; i++) {
  temp1 = { "x": i, "y": payload[i].powerdc }
  a1.push(temp1);
}
dataout = [ a1 ];

msg.payload = [{
  "series": [ "A" ],
  "data": dataout,
  "labels": ["B"]
}];
msg.topic = null
return msg;

Thank You for your hint !

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