Signal not create chart

Helleo,

I would like to get help, I have signals:
Timestamp: 1645194537028
Temp: 58.44097137451172
Light: 15
Humidity: 58.44097137451172
would like to have a chart based on them, not display a line to me.
I wanted to get a chart of 3 values,
For the graph to be readable, I would like to see, for example, the last 500 samples

[{"id":"485c8d35.d133b4","type":"function","z":"80c6e8a8.692a38","name":"DB Data to Chart data","func":"/* DB Data\n[\n    {\n        \"Timestamp\": \"2020-11-18 18:25:48.906\",\n        \"Temp\": 21.3,\n        \"Light\": 15,\n        \"Pressure\": 18100.2,\n        \"Humidity\": 31.2\n    },\n]\n*/\n/* Desired format\n[{\n\"series\": [\"temp\", \"humidity\"],\n\"data\": [\n    [{ \"x\": 1504029632890, \"y\": 5 }, //series 1 data\n     { \"x\": 1504029636001, \"y\": 4 },\n    ],\n    [{ \"x\": 1504029633514, \"y\": 6 }, //series 2 data\n     { \"x\": 1504029636622, \"y\": 7 },\n    ],\n],\n\"labels\": [\"\"]\n}]\n*/\n\nvar series = [];\nvar data = msg.payload;\nif (!data || !Array.isArray(data) || !data.length) {\n    node.warn(\"expected an array of data with at least 1 element\");\n    return null;\n    //alternatively return the msg with a null payload to clear graph\n}\n\nconst tsField = \"Timestamp\";\nvar _f = Object.keys(data[0]);\nvar fields = [];\nvar fi = 0;\n_f.forEach(function(elem) {\n    if (elem != tsField) {\n        fields.push(elem);\n        series[fi++] = [];\n    }\n});\n\n//loop each row and build an array in the required format\nfor (let index = 0; index < msg.payload.length; index++) {\n    const row = msg.payload[index];\n    var t = new Date(row[tsField]).valueOf()\n    var i = 0;\n    for (let f = 0; f < fields.length; f++ ) {\n        let field = fields[f];\n        series[f].push({ \"x\": t, \"y\": row[field] })\n    }\n}\n\n\nmsg.payload = [\n    {\n        \"series\": fields,\n        \"data\": series,\n        \"labels\": [\"\"]\n    }\n];\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":640,"y":560,"wires":[["9c0c0c8.bc26ff","e109c141.4a4f3"]]},{"id":"9c0c0c8.bc26ff","type":"debug","z":"80c6e8a8.692a38","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":850,"y":560,"wires":[]},{"id":"e109c141.4a4f3","type":"ui_chart","z":"80c6e8a8.692a38","name":"","group":"350652e2.78041e","order":1,"width":0,"height":0,"label":"mySQL data","chartType":"line","legend":"true","xformat":"HH:mm:ss","interpolate":"bezier","nodata":"","dot":false,"ymin":"","ymax":"","removeOlder":"2","removeOlderPoints":"1000","removeOlderUnit":"3600","cutout":0,"useOneColor":false,"useUTC":false,"colors":["#1f77b4","#aec7e8","#ff7f0e","#2ca02c","#98df8a","#d62728","#ff9896","#9467bd","#c5b0d5"],"outputs":1,"useDifferentColor":false,"x":770,"y":660,"wires":[[]]},{"id":"e1464650.dc6688","type":"function","z":"80c6e8a8.692a38","name":"NewName_SK","func":" const myObj = msg.payload;\n const text = myObj.tagName;\n\n    \n\t\tif(text.startsWith(\"0#\") == true){\n\t\t\n\t\t\t//aby wyswietlac dane tylko z danego sterownika do MQTT\n\t\t\t    const restText = text.substr(\"0#\".length);\n\t\t    myObj.tagName = restText;\n\t\t\tmyObj.value = myObj.value/1;\n\t\t\tmsg.payload = [{\"Timestamp\":myObj.timestamp,\"Temp\": myObj.value,\"Light\":15,\"Humidity\":myObj.value}];\n\t\t\tnode.status({fill:\"blue\",shape:\"dot\",text: (myObj.value)});\n\t\t    return msg;\n\t\t\t}\n        else if(text.startsWith(\"1#\") == true){\n\t\t\n\t\t\t//aby wyswietlac dane tylko z danego sterownika do MQTT\n\t\t    \tconst restText = text.substr(\"1#\".length);\n\t\t    myObj.tagName = restText;\n\t\t\tmyObj.value = myObj.value/10;\n\t\t\tmsg.payload = myObj.value;\n\t\t\tnode.status({fill:\"blue\",shape:\"dot\",text: (myObj.value)});\n\t\t    return msg;\n\t\t\t}\n\t\telse if(text.startsWith(\"2#\") == true){\n\t\t\n\t\t\t//aby wyswietlac dane tylko z danego sterownika do MQTT\n\t\t    \tconst restText = text.substr(\"2#\".length);\n\t\t    myObj.tagName = restText;\n\t\t\tmyObj.value = myObj.value/100;\n\t\t\tmsg.payload = myObj.value;\n\t\t\tnode.status({fill:\"blue\",shape:\"dot\",text: (myObj.value)});\n\t\t    return msg;\n\t\t\t}\n\t\telse if(text.startsWith(\"3#\") == true){\n\t\t\n\t\t\t//aby wyswietlac dane tylko z danego sterownika do MQTT\n\t\t    \tconst restText = text.substr(\"3#\".length);\n\t\t    myObj.tagName = restText;\n\t\t\tmyObj.value = myObj.value/1000;\n\t\t\tmsg.payload = myObj.value;\n\t\t\tnode.status({fill:\"blue\",shape:\"dot\",text: (myObj.value)});\n\t\t    return msg;\n\t\t\t}\n\t\telse if(text.startsWith(\"#\", 1 ) == false){\n\t\t\n\t\t\t//aby wyswietlac to co przyszło\n\t\t    msg.payload = myObj.value;\n\t\t    node.status({fill:\"blue\",shape:\"dot\",text: (myObj.value)});\n\t\t    return msg;\n\t\t    \t\t\t\n\t\t    }","outputs":1,"noerr":0,"initialize":"","finalize":"","x":540,"y":480,"wires":[["3d94f656.c42eca","485c8d35.d133b4"]]},{"id":"57ab889b.e70af8","type":"json","z":"80c6e8a8.692a38","name":"JSON to Object","property":"payload","action":"obj","pretty":false,"x":320,"y":480,"wires":[["5bd608d8.617698","e1464650.dc6688"]]},{"id":"395a8409.df492c","type":"Datahub Subscribe","z":"80c6e8a8.692a38","name":"T_Lutowania C3H2","natc":"d16b4f91.27069","topicname":"devicehub.raw.49D9941E-8915-44E2-BCC9-0A0D0652389F.372B29A5-9C0A-46B4-9421-7F7B0E1529FB","x":130,"y":480,"wires":[["57ab889b.e70af8"]]},{"id":"3d94f656.c42eca","type":"debug","z":"80c6e8a8.692a38","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":770,"y":480,"wires":[]},{"id":"5bd608d8.617698","type":"debug","z":"80c6e8a8.692a38","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":570,"y":640,"wires":[]},{"id":"350652e2.78041e","type":"ui_group","name":"DB Data to Chart data","tab":"f859ce5d.fc0ba","order":2,"disp":false,"width":"14","collapse":false},{"id":"d16b4f91.27069","type":"Datahub Connect","ipadd":"127.0.0.1","port":"4222"},{"id":"f859ce5d.fc0ba","type":"ui_tab","name":"Question - How to display 2 different dimension arrays on Line Chart correctly","icon":"dashboard","disabled":false,"hidden":false}]

Dear Cysoz

Your question is a little unclear to me. Could you explain your problem and request a bit more in-depth?

Can you show us a few samples of the data as it arrives from your "Datahub Subscribe" node?

In my sensors i send:
msg.payload = [{"Timestamp":myObj.timestamp,"Temp": myObj.value,"Light":15,"Humidity":myObj.value}];

funcion should read this payload and send to chart

var series = [];
var data = msg.payload;
if (!data || !Array.isArray(data) || !data.length) {
    node.warn("expected an array of data with at least 1 element");
    return null;
    //alternatively return the msg with a null payload to clear graph

I have only information:
expected an array of data with at least 1 elemen

I have no idea what I should do.

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