Hi everyone, I am using eCharts with UI builder and vuejs for graphics. I use and caching function also because I want to see the graphic from different clients/browsers. My problem is that the arrays that i use for X and Y axes get doubles when the browser is refreshed.
Here is my flow:
[{"id":"75668888.8cd508","type":"debug","z":"3aecfa59.984b76","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":990,"y":140,"wires":[]},{"id":"6334513b.b5fb2","type":"debug","z":"3aecfa59.984b76","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":1070,"y":300,"wires":[]},{"id":"2a25f279.c41bfe","type":"uibuilder","z":"3aecfa59.984b76","name":"","topic":"","url":"chartEcharts","fwdInMessages":false,"allowScripts":false,"allowStyles":false,"copyIndex":true,"showfolder":false,"x":810,"y":200,"wires":[["75668888.8cd508"],["6334513b.b5fb2","f1b1f460.632128"]]},{"id":"38b1eb76.194b14","type":"link in","z":"3aecfa59.984b76","name":"echart-replay","links":["f1b1f460.632128"],"x":495,"y":200,"wires":[["60868209.24110c"]]},{"id":"f1b1f460.632128","type":"link out","z":"3aecfa59.984b76","name":"echart-controls","links":["38b1eb76.194b14"],"x":915,"y":280,"wires":[]},{"id":"5622596c.b04448","type":"influxdb in","z":"3aecfa59.984b76","influxdb":"6f1ec63.91ef438","name":"select total power","query":"select * from \"sm-0001\" ORDER BY desc LIMIT 2","rawOutput":false,"precision":"s","retentionPolicy":"","x":170,"y":140,"wires":[["30d51a09.c50f26","a730a2a1.03487"]]},{"id":"9b77f2ca.28907","type":"inject","z":"3aecfa59.984b76","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":120,"y":220,"wires":[["5622596c.b04448"]]},{"id":"30d51a09.c50f26","type":"function","z":"3aecfa59.984b76","name":"","func":"\nvar myArr = []\nvar valueArr = []\n\nfor (i = 0; i < msg.payload.length; i++ )\n{\n valueArr.push(msg.payload[i].value)\n}\nmsg.topic = \"test1/test1\"\n\nmsg.payload = valueArr\nreturn msg;\n","outputs":1,"noerr":0,"initialize":"","finalize":"","x":380,"y":160,"wires":[["60868209.24110c"]]},{"id":"a730a2a1.03487","type":"function","z":"3aecfa59.984b76","name":"","func":"\nvar myArr = []\nvar valueArr = []\n\nfor (i = 0; i < msg.payload.length; i++ )\n{\n valueArr.push(msg.payload[i].time)\n}\nmsg.topic = \"test2/test2\"\nmsg.payload = valueArr\nreturn msg;\n","outputs":1,"noerr":0,"initialize":"","finalize":"","x":320,"y":220,"wires":[["65870d8a.420294","60868209.24110c"]]},{"id":"65870d8a.420294","type":"debug","z":"3aecfa59.984b76","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":700,"y":320,"wires":[]},{"id":"60868209.24110c","type":"function","z":"3aecfa59.984b76","name":"","func":"// Expects input msgs with topic set \n\n// saved context\nvar homeMsgs = context.get('homeMsgs') || {}\n\n// Only send to single client if needed\nvar socketId = null\nif ( msg.hasOwnProperty('_socketId') ) {\n socketId = msg._socketId\n}\n\n// Replay cache if requested\nif ( msg.hasOwnProperty('cacheControl') && msg.cacheControl === 'REPLAY' ) {\n for (var topic in homeMsgs) {\n let newMsg = {\n \"topic\": topic, \n \"payload\": homeMsgs[topic]\n }\n // Only send to a single client if we can\n if ( socketId !== null ) newMsg._socketId = socketId\n node.send(newMsg)\n }\n return null\n}\n// -- else --\n// Empty cache if requested\nif ( (msg.hasOwnProperty('cacheControl') && msg.cacheControl === 'RESET') ||\n (msg.payload.hasOwnProperty('cacheControl') && msg.payload.cacheControl === 'RESET') ) {\n homeMsgs = {}\n context.set('homeMsgs', homeMsgs)\n return null\n}\n// -- else --\n\n// ignore cacheControl and uibuilder control messages\nif ( msg.hasOwnProperty('cacheControl') || msg.hasOwnProperty('uibuilderCtrl') ) return null\n\n// Add a counter for each device name\nif ( msg.topic.endsWith('$name') ) {\n let topic = msg.topic.replace('$name', '$count')\n let count = homeMsgs[topic] || 0\n count = count + 1\n homeMsgs[topic] = count\n let newMsg = {\n \"topic\": topic, \n \"payload\": count\n }\n // Only send to a single client if we can\n if ( socketId !== null ) newMsg._socketId = socketId\n node.send(newMsg)\n}\n\n// Keep the last msg.payload by topic\nhomeMsgs[msg.topic] = msg.payload\n\n// save context for next time\ncontext.set('homeMsgs', homeMsgs)\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":640,"y":140,"wires":[["2a25f279.c41bfe"]]},{"id":"6f1ec63.91ef438","type":"influxdb","z":"","hostname":"159.89.103.242","port":"8086","protocol":"http","database":"smartmeters","name":"","usetls":false,"tls":""}]
Thank you very much for your help!