Hello,
I am trying to create a bar chart from a query from my InfluxDB using the max values of several days. Unfortunately, I am not able to do this.
After converting using function node, it looks like this:
This is the flow:
[
{
"id": "b84ff6a83df2a030",
"type": "inject",
"z": "aff59ea3f84b5123",
"name": "Select * from opendtu",
"props": [
{
"p": "payload"
},
{
"p": "query",
"v": "SELECT max(\"value\") from mqtt_consumer WHERE (topic='open/dtu/114184019984/0/yieldday') and (time >= now() - 9d) Group by time(1d)",
"vt": "str"
}
],
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"topic": "",
"payload": "",
"payloadType": "date",
"x": 760,
"y": 2540,
"wires": [
[
"326357f7bb7c5fcb"
]
]
},
{
"id": "326357f7bb7c5fcb",
"type": "influxdb in",
"z": "aff59ea3f84b5123",
"influxdb": "69cee814.fcbdb8",
"name": "OpenDTU",
"query": "",
"rawOutput": false,
"precision": "",
"retentionPolicy": "",
"org": "organisation",
"x": 1080,
"y": 2540,
"wires": [
[
"aa14700c096b3e10",
"61752de52dbefa60"
]
]
},
{
"id": "0cddcc96761b211a",
"type": "ui_chart",
"z": "aff59ea3f84b5123",
"name": "",
"group": "dd5579511605b911",
"order": 2,
"width": 0,
"height": 0,
"label": "chart",
"chartType": "bar",
"legend": "false",
"xformat": "HH:mm:ss",
"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": 1470,
"y": 2540,
"wires": [
[]
]
},
{
"id": "61752de52dbefa60",
"type": "debug",
"z": "aff59ea3f84b5123",
"name": "debug 1",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "false",
"statusVal": "",
"statusType": "auto",
"x": 1220,
"y": 2620,
"wires": []
},
{
"id": "aa14700c096b3e10",
"type": "function",
"z": "aff59ea3f84b5123",
"name": "function 9",
"func": "// Assuming msg.payload contains your data array\nvar data = msg.payload.map(function(item) {\n return { x: new Date(item.time), y: item.max };\n});\n\nmsg.payload = {\n series: ['Max'],\n data: [data]\n};\n\nreturn msg;",
"outputs": 1,
"timeout": 0,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 1300,
"y": 2540,
"wires": [
[
"0cddcc96761b211a",
"9114a63405a9dd1c"
]
]
},
{
"id": "9114a63405a9dd1c",
"type": "debug",
"z": "aff59ea3f84b5123",
"name": "debug 2",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "false",
"statusVal": "",
"statusType": "auto",
"x": 1480,
"y": 2620,
"wires": []
},
{
"id": "69cee814.fcbdb8",
"type": "influxdb",
"hostname": "192.168.178.10",
"port": "8086",
"protocol": "http",
"database": "opendtu",
"name": "",
"usetls": false,
"tls": "",
"influxdbVersion": "1.x",
"url": "http://localhost:8086",
"rejectUnauthorized": false
},
{
"id": "dd5579511605b911",
"type": "ui_group",
"name": "Group 1",
"tab": "f1504e48476c784c",
"order": 1,
"disp": true,
"width": 6
},
{
"id": "f1504e48476c784c",
"type": "ui_tab",
"name": "Test",
"icon": "dashboard",
"order": 9,
"disabled": false,
"hidden": false
}
]
What is my mistake?
Ralf