I'm learning a little about plotly for dashboard charts, and found it very easy to load their CDN library via a ui_template node, and display some dummy data.
However I've found using real data is not quite straightforward, as can be seen in the example flow below.
Hardcoding the data in a ui_template node works fine;
x:[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12],
y:[28.8, 28.5, 37, 56.8, 69.7, 79.7, 78.5, 77.8, 74.1, 62.6, 45.3, 39.9],
whilst altering the above to;
x:[{{payload.time}}],
y:[{{payload.temp}}],
and injecting it like;
var temp = [21.7, 28.5, 37, 56.8, 69.7, 79.7, 78.5, 77.8, 74.1, 62.6, 45.3, 39.9];
var time = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12];
msg.payload = {"temp":temp,"time":time};
return msg;
Does not render the chart, and I can't work out why not, what am I missing (apart from the obvious answer )
[{"id":"20f3fd4b.940ca2","type":"ui_template","z":"a444a9ff.e7a408","group":"f93124ac.7c74c8","name":"Load Plotly CDN","order":17,"width":0,"height":0,"format":"<script src=\"https://cdn.plot.ly/plotly-latest.min.js\"></script>\n","storeOutMessages":true,"fwdInMessages":true,"resendOnRefresh":true,"templateScope":"global","x":590,"y":2760,"wires":[[]]},{"id":"d1949ed6.d25ce","type":"function","z":"a444a9ff.e7a408","name":"Chart data","func":"var temp = [21.7, 28.5, 37, 56.8, 69.7, 79.7, 78.5, 77.8, 74.1, 62.6, 45.3, 39.9];\nvar time = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12];\nmsg.payload = {\"temp\":temp,\"time\":time};\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":410,"y":2800,"wires":[["8e1615b9.9af318"]]},{"id":"a348ec63.82885","type":"inject","z":"a444a9ff.e7a408","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"str","x":260,"y":2800,"wires":[["d1949ed6.d25ce"]]},{"id":"8e1615b9.9af318","type":"ui_template","z":"a444a9ff.e7a408","group":"61d2dced.3db8f4","name":"Plotly chart","order":45,"width":0,"height":0,"format":"<body>\n\n <div id=\"myDiv\"><!-- Plotly chart will be drawn inside this DIV --></div>\n <script>\n\nvar trace1 = {\n \n// This works\n x:[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12],\n y:[28.8, 28.5, 37, 56.8, 69.7, 79.7, 78.5, 77.8, 74.1, 62.6, 45.3, 39.9],\n \n// This doesn't work!\n// x:[{{payload.time}}],\n// y:[{{payload.temp}}],\n\n name: 'temperature',\n //mode: 'lines',\n connectgaps: true\n};\n\nvar data = [trace1];\n\nvar layout = {\n title: 'Example plotly chart',\n plot_bgcolor: '#ffffff',\n paper_bgcolor: '#ffffff',\n 'yaxis': {\n title: 'Temperature'\n },\n\n //See https://community.plotly.com/t/how-to-make-the-messy-date-ticks-organized/7477\n// 'xaxis': {\n// 'tickformat': '%X'\n// }\n};\n\nPlotly.newPlot('myDiv', data, layout, {displayModeBar: false}, {displaylogo: false},);\n\n</script>\n</body>\n\n","storeOutMessages":true,"fwdInMessages":true,"resendOnRefresh":true,"templateScope":"local","x":580,"y":2800,"wires":[[]]},{"id":"f93124ac.7c74c8","type":"ui_group","z":"","name":"Chart","tab":"6cb7ce21.162a1","order":1,"disp":false,"width":"10","collapse":false},{"id":"61d2dced.3db8f4","type":"ui_group","z":0,"name":"flowtest","tab":"3c94630c.13381c","order":1,"disp":true,"width":16,"collapse":false},{"id":"6cb7ce21.162a1","type":"ui_tab","z":"","name":"Realtime Power","icon":"dashboard","order":1,"disabled":false,"hidden":false},{"id":"3c94630c.13381c","type":"ui_tab","z":0,"name":"Test","icon":"dashboard","order":9}]