Hi ,
I am fairly new to Node-Red but think it is a great tool. Once you get the hang of using messages . . . it is amazing!
I have created charts in Node-Red using the node-red-contrib-chartjs. The charts I have created are more complicated than this example, but I am really stuck with this simple bar chart.
(This is my first post. I hope I am inserting code and pictures properly in this forum - so please let me know if I am not).
Below is the chart I am trying to create along with the flow.
I have created a simplified flow to show the problem. In the first node I generate a simple payload. The second moustache template node runs the chart.js script and the 3rd node sends it to the dashboard.
The problem is with the second node and how it "reads" the payload. When I "hardcode" the "labels" and "data" it works fine. However when I try to read this info from the payload, it does not work (currently commented out). I realize that this is quite simple, but I just can't figure it out? Other more complicated charts work very well! I also realize that I can use the the built in Node-Red charts, but all the other more complicated charts already use the node-red-contrib-chartjs, so I would really like to get this to work with chart.js and understand what I am missing here. Thanks for your help!
[{"id":"54df4d0a.317e64","type":"ui_template","z":"f341b612.8a1718","group":"90d07240.50d4f","name":"OEE Bar Chart (dynamic)","order":3,"width":"6","height":"5","format":"This will be ignored","storeOutMessages":true,"fwdInMessages":true,"templateScope":"local","x":910,"y":280,"wires":[[]]},{"id":"e80d0b3f.377338","type":"function","z":"f341b612.8a1718","name":"OEE BarChtCalc","func":"\n\nmsg.payload = { \n data: [20.1, 40.2, 55.9, 98.3],\n labels: ['\"Avail\"', '\"Perf\"', '\"Qual\"', '\"OEE\"']};\n\nreturn msg;","outputs":1,"noerr":0,"x":390,"y":280,"wires":[["f0d60e98.1757e","b0cd2350.7b882"]]},{"id":"f0d60e98.1757e","type":"debug","z":"f341b612.8a1718","name":"Msg00","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":630,"y":240,"wires":[]},{"id":"b0cd2350.7b882","type":"template","z":"f341b612.8a1718","name":"OEE Bar Cht Template","field":"template","fieldType":"msg","format":"html","syntax":"mustache","template":"<canvas id=\"barOEE\" width=\"1\" height=\"1\"></canvas>\n\n<script>\nnew Chart(document.getElementById(\"barOEE\"), {\n type: \"bar\",\n data: {\n //labels: [{{{msg.payload.labels}}}],\n labels: [\"Avail\", \"Perf\", \"Qual\", \"OEE\"],\n datasets: \n [{\n //data: [{{{msg.payload.data}}}],\n data: [10.2,20.4,50.3,92.9],\n backgroundColor: 'rgba(0,0,255,1)'\n //borderColor: 'rgba(0,0,255,1)',\n //borderWidth: 0,\n //hoverBackgroundColor: 'rgba(0,255,0,1)',\n //hoverBorderColor: 'rgba(0,255,0,1)'\n \t}]\n },\n \n options: {\n animation: {duration: 0},\n \n title: {\n responsive: true,\n display: true,\n text: \"OEE Chart (%)\",\n fontColor: 'rgb(255,255,255)'\n },\n \n legend: {\n display: false,\n },\n \n maintainAspectRatio: false,\n \n scales: {\n yAxes: [{\n stacked: true,\n gridLines: {\n display: true\n },\n ticks: {\n beginAtZero: true,\n fontColor: 'white'\n }\n }],\n \n xAxes: [{\n stacked: true,\n gridLines: {\n display: false\n },\n ticks: {\n fontColor: 'white',\n autoSkip: false\n }\n }]\n } \n \n } \n\n});\n</script>","output":"str","x":680,"y":280,"wires":[["54df4d0a.317e64"]]},{"id":"9e63afbd.52e0f","type":"inject","z":"f341b612.8a1718","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":180,"y":280,"wires":[["e80d0b3f.377338"]]},{"id":"90d07240.50d4f","type":"ui_group","z":"","name":"Test Space","tab":"49f2883.aa81678","order":1,"disp":true,"width":"6","collapse":false},{"id":"49f2883.aa81678","type":"ui_tab","z":"","name":"Other Line","icon":"dashboard","order":2,"disabled":false,"hidden":false}]