Hi,
I'm new to Node-Red and I was hoping I can get some help. I have a random generated array that I coded up using the function block that outputs 5 values.
I would like to plot each value from the generated array after a delay. At the moment, upon injection, it plots out all 5 data points in one go. I'd like it to plot 1 data point after every two seconds instead of all the 5 data points in a single go. I've tried to use the split and delay block, but I can't seem to get it to work.
My plan is to use the same block of code and output a random array of 100 values where each point in that random array is plotted after a delay of 2 seconds.
Thank you.
Code:
[{"id":"609bd1f48eb65be2","type":"tab","label":"Array to Chart with Delay","disabled":false,"info":"","env":[]},{"id":"c82a8c828ad12f1f","type":"comment","z":"609bd1f48eb65be2","name":"Charting an Array","info":"Simple example of how to chart values in an array","x":260,"y":160,"wires":[]},{"id":"4394cd6b6ac74c99","type":"function","z":"609bd1f48eb65be2","name":"Charting Array","func":"let data = [];\nlet labels = [];\n\n// Create the data\nfor (var i = 0; i < 5; i++)\n{\n \n data[i] = Math.round(Math.random() * 100);\n labels[i] = i+1;\n\n}\n\n// format it nicely for node-red\nvar chart = [{\n \"series\": [\"X\"],\n \"data\": [data],\n \"labels\": labels\n}];\n\nmsg.payload = chart;\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":460,"y":220,"wires":[["a5d42321065c9f99","658cc8fd571581b6"]]},{"id":"a5d42321065c9f99","type":"ui_chart","z":"609bd1f48eb65be2","name":"Chart: Array Data","group":"07dfaaf31abffa87","order":1,"width":"8","height":"6","label":"Engine Bay Temperature <i class=\"fa fa-thermometer-empty\" style=\"font-size:46px\"></i>","chartType":"line","legend":"false","xformat":"Data Point","interpolate":"linear","nodata":"","dot":true,"ymin":"0","ymax":"100","removeOlder":1,"removeOlderPoints":"","removeOlderUnit":"3600","cutout":0,"useOneColor":false,"useUTC":false,"colors":["#ff0059","#aec7e8","#ff7f0e","#2ca02c","#98df8a","#d62728","#ff9896","#9467bd","#c5b0d5"],"outputs":1,"useDifferentColor":false,"className":"","x":750,"y":240,"wires":[[]]},{"id":"658cc8fd571581b6","type":"debug","z":"609bd1f48eb65be2","name":"Array Output","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":730,"y":160,"wires":[]},{"id":"2c409302fd9d1c32","type":"inject","z":"609bd1f48eb65be2","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":280,"y":220,"wires":[["4394cd6b6ac74c99"]]},{"id":"07dfaaf31abffa87","type":"ui_group","name":"Chart Example of an Array","tab":"01c5a8f39d591610","order":1,"disp":false,"width":"8","collapse":false,"className":""},{"id":"01c5a8f39d591610","type":"ui_tab","name":"ARRAYS","icon":"web_asset","order":2,"disabled":false,"hidden":false}]
Image: Block Code
Image: Function Script