I have a working bar chart with below function code feeding the chart.
i have one more series of data to be added in the same chart, msg.payload.Count
.
i have tried several ways, but no success. if i make "data" as an array with two series data, nothing is shown on the graph.
what changes in the below function should i do to get it right ?
i also want the data labels on the bars,
i have added a small sample data in below flow.
let mname = flow.get("dt_code1")
let dataC = [[]];
let dataLabels = [];
for (let X in msg.payload) {
dataLabels[X] = msg.payload[X].machine;
dataC[0][X] = msg.payload[X].Duration;
}
var m = {
"series": [{mname}],
"data": dataC,
"labels": dataLabels
};
return { payload: [m] };
flow with sample data.
[{"id":"714dacca9f798ed7","type":"inject","z":"a0eee751005e0e89","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"[{\"Date\":\"14-June-C Shift\",\"Duration\":123,\"Count\":2},{\"Date\":\"15-June-C Shift\",\"Duration\":96,\"Count\":4},{\"Date\":\"16-June-A Shift\",\"Duration\":227,\"Count\":4},{\"Date\":\"17-June-B Shift\",\"Duration\":47,\"Count\":1},{\"Date\":\"18-June-A Shift\",\"Duration\":67,\"Count\":2}]","payloadType":"json","x":1840,"y":2400,"wires":[["5e3c61d37f0ebfe9"]]},{"id":"5e3c61d37f0ebfe9","type":"function","z":"a0eee751005e0e89","name":"Prepare Bar Graph Data","func":"let mname = flow.get(\"dt_code1\")\nlet dataC = [[]];\nlet dataC1 = [[]];\nlet dataLabels = [];\n\nfor (let X in msg.payload) {\n dataLabels[X] = msg.payload[X].Date;\n dataC[0][X] = msg.payload[X].Duration;\n dataC1[0][X] = msg.payload[X].Count;\n }\n\nvar m = {\n \"series\": [{mname}],\n \"data\": dataC,\n \"labels\": dataLabels\n};\n\nreturn { payload: [m] };","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":1995,"y":2400,"wires":[["69c92bb74e936b1a","e18781def7d9297d"]],"l":false},{"id":"69c92bb74e936b1a","type":"change","z":"a0eee751005e0e89","name":"Set Graph Title","rules":[{"t":"set","p":"mname","pt":"msg","to":"'Chart Title'","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":2085,"y":2400,"wires":[["38aef9b45e99c257"]],"l":false},{"id":"38aef9b45e99c257","type":"ui_chart","z":"a0eee751005e0e89","name":"Bar Chart","group":"aa8eec0d5014b069","order":1,"width":"20","height":"9","label":"{{mname}}","chartType":"horizontalBar","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":2190,"y":2400,"wires":[[]]},{"id":"e18781def7d9297d","type":"debug","z":"a0eee751005e0e89","name":"debug 368","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":2120,"y":2310,"wires":[]},{"id":"aa8eec0d5014b069","type":"ui_group","name":"second","tab":"4f903fa3c7ed98d8","order":2,"disp":true,"width":"20","collapse":false,"className":""},{"id":"4f903fa3c7ed98d8","type":"ui_tab","name":"Dashboard2","icon":"dashboard","order":1,"disabled":false,"hidden":false}]