I am needing help trying to figure out why my function node isn't separating the time, date and TC data correctly. My code is below. Any help would be greatly appreciated.
[
{
"id": "73e4e16.4d9742",
"type": "inject",
"z": "f5c39bc78c9f43a9",
"name": "Inject",
"props": [
{
"p": "payload"
},
{
"p": "topic",
"vt": "str"
}
],
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"topic": "",
"payload": "[{\"Date\":\"2023-09-03\",\"Time\":\"12:37:43\",\"TC1\":7.814468887624555,\"TC2\":9.010489315422356,\"TC3\":2.2051948357794204,\"TC4\":4.634575718286296},{\"Date\":\"2023-09-03\",\"Time\":\"12:40:42\",\"TC1\":1.2247009897949532,\"TC2\":4.502620787639197,\"TC3\":4.220188281544026,\"TC4\":1.9340397044971718},{\"Date\":\"2023-09-03\",\"Time\":\"14:18:02\",\"TC1\":2.5243351824265963,\"TC2\":6.036543260510911,\"TC3\":6.538703425751857,\"TC4\":3.7277151250599543}]",
"payloadType": "jsonata",
"x": 350,
"y": 200,
"wires": [
[
"90ed51dc.dcc71"
]
]
},
{
"id": "90ed51dc.dcc71",
"type": "csv",
"z": "f5c39bc78c9f43a9",
"name": "",
"sep": ",",
"hdrin": true,
"hdrout": "once",
"multi": "mult",
"ret": "\\n",
"temp": "",
"skip": "1",
"strings": true,
"include_empty_strings": false,
"include_null_values": false,
"x": 530,
"y": 200,
"wires": [
[
"9aace6e7.adc538",
"b05f7f856d809326"
]
]
},
{
"id": "9aace6e7.adc538",
"type": "debug",
"z": "f5c39bc78c9f43a9",
"name": "",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "true",
"targetType": "full",
"statusVal": "",
"statusType": "auto",
"x": 670,
"y": 140,
"wires": []
},
{
"id": "137d11d9.8c82ee",
"type": "ui_chart",
"z": "f5c39bc78c9f43a9",
"name": "",
"group": "a649fab2.daf3d8",
"order": 7,
"width": 18,
"height": 6,
"label": "Temperature Chart",
"chartType": "line",
"legend": "false",
"xformat": "auto",
"interpolate": "linear",
"nodata": "",
"dot": false,
"ymin": "",
"ymax": "",
"removeOlder": 1,
"removeOlderPoints": "",
"removeOlderUnit": "3600",
"cutout": 0,
"useOneColor": false,
"useUTC": false,
"colors": [
"#1f77b4",
"#aec7e8",
"#ff7f0e",
"#2ca02c",
"#98df8a",
"#d62728",
"#ff9896",
"#9467bd",
"#c5b0d5"
],
"outputs": 1,
"useDifferentColor": false,
"className": "",
"x": 1010,
"y": 340,
"wires": [
[]
]
},
{
"id": "b05f7f856d809326",
"type": "function",
"z": "f5c39bc78c9f43a9",
"name": "DateTime_Data_Split",
"func": "function toTimestamp(strDate) {\n var datum = Date.parse(strDate);\n return datum / 1000;\n}\n\nvar payload = msg.payload;\n\nvar data_out = [];\nvar a1 = [];\nvar a2 = [];\nvar a3 = [];\nvar a4 = [];\n\nfor (let i = 0; i < payload.length; i++) {\n if (payload[i].Date) {\n console.log(\"Date:\", payload[i].Date);\n console.log(\"Time:\", payload[i].Time);\n var Data = payload[i].Date.split(\"-\");\n var t = Data[2] + \"/\" + Data[1] + \"/\" + Data[0];\n var timestamp = toTimestamp(t + \" \" + payload[i].Time);\n\n var temp1 = { \"x\": timestamp, \"y\": parseFloat(payload[i].TC1) };\n var temp2 = { \"x\": timestamp, \"y\": parseFloat(payload[i].TC2) };\n var temp3 = { \"x\": timestamp, \"y\": parseFloat(payload[i].TC3) };\n var temp4 = { \"x\": timestamp, \"y\": parseFloat(payload[i].TC4) };\n\n a1.push(temp1);\n a2.push(temp2);\n a3.push(temp3);\n a4.push(temp4);\n\n console.log(\"temp1:\", temp1);\n console.log(\"temp2:\", temp2);\n console.log(\"temp3:\", temp3);\n console.log(\"temp4:\", temp4);\n }\n}\n\ndata_out = [a1, a2, a3, a4];\n\nmsg.payload = [{\n \"series\": [\"TC1\", \"TC2\", \"TC3\", \"TC4\"],\n \"data\": data_out,\n \"labels\": [\"TC1\", \"TC2\", \"TC3\", \"TC4\"]\n}];\n\nreturn msg;\n",
"outputs": 1,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 740,
"y": 340,
"wires": [
[
"137d11d9.8c82ee",
"b27011309a3a3080"
]
]
},
{
"id": "b27011309a3a3080",
"type": "debug",
"z": "f5c39bc78c9f43a9",
"name": "",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "false",
"x": 970,
"y": 200,
"wires": []
},
{
"id": "a649fab2.daf3d8",
"type": "ui_group",
"name": "File Browser",
"tab": "75e4e587.f4c0ac",
"order": 1,
"disp": true,
"width": "18",
"collapse": false
},
{
"id": "75e4e587.f4c0ac",
"type": "ui_tab",
"name": "Files",
"icon": "dashboard",
"disabled": false,
"hidden": false
}
]