How to Plot line chart of real time data

If y-axis is amplitude and x-axis is frequency and you draw line then at each point of line the corresponding frequency has measured amplitude.
Meaning that you should have an array of frequencies [10Hz, 20Hz, 30Hz]
And for every item in frequency array you have measured (peak) amplitude [50dB,20dB,33dB] (whatever the displacement unit is).
Those make pairs. From chart perspective two-dimensional points. {x,y}
As you have an array of such points, you can draw line between them.
Such graph represents vibration spectrum.

I don't know anything about what the data is, but if it comes in as for single point, then may be something like that can be somehow represent the vibration spectrum.

[{"id":"f84ec1a3.50318","type":"ui_chart","z":"7ee51301.a9185c","name":"","group":"c7a27394.057878","order":5,"width":9,"height":9,"label":"","chartType":"line","legend":"false","xformat":"HH:mm:ss","interpolate":"linear","nodata":"","dot":false,"ymin":"-30","ymax":"30","removeOlder":"24","removeOlderPoints":"","removeOlderUnit":"3600","cutout":0,"useOneColor":false,"useUTC":false,"colors":["#00b3ff","#aec7e8","#ff7f0e","#2ca02c","#98df8a","#d62728","#ff9896","#9467bd","#c5b0d5"],"outputs":1,"useDifferentColor":false,"x":750,"y":300,"wires":[[]]},{"id":"9251a607.5109c","type":"inject","z":"7ee51301.a9185c","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":".2","crontab":"","once":true,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":210,"y":280,"wires":[["146b04a0.ed33cb"]]},{"id":"ec9e71e8.8842e","type":"function","z":"7ee51301.a9185c","name":"modify chart options","func":"let gridcolors = ['rgba(255, 160, 0, 0.3)']\nmsg.ui_control = {\n    options: {\n        legend: {\n            display: false\n        },\n        tooltips: {\n            enabled: false\n        },\n        scales: {\n            xAxes: [{\n                type: 'linear',\n                id: 'custom-x-axis',\n                position:'bottom',\n                padding:100,\n                gridLines:{\n                    color:gridcolors,\n                    zeroLineColor:'rgba(123, 113, 113, 0.75)',\n                    tickMarkLength:7,\n                    drawTicks:false\n                },\n                ticks: {\n                    fontColor:\"#ccc\",\n                    max: 60,\n                    min: 0,\n                    stepSize: 10\n                   \n                }\n            }],\n            yAxes: [{\n                id: 'custom-y-axis',\n                \n                gridLines:{\n                    color:gridcolors,\n                    zeroLineColor:'rgba(123, 113, 113, 0.75)',\n                    tickMarkLength:5,\n                    drawTicks:false\n                },\n                ticks: {\n                    fontColor:\"#ccc\",\n                    max: 30,\n                    min: -30,\n                    stepSize: 10\n                }\n            }]\n       }\n    }\n}\ndelete msg.payload\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":520,"y":320,"wires":[["f84ec1a3.50318"]]},{"id":"d689bde.df3354","type":"inject","z":"7ee51301.a9185c","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":true,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":210,"y":320,"wires":[["ec9e71e8.8842e"]]},{"id":"46dd99bd.680638","type":"function","z":"7ee51301.a9185c","name":"data collection","func":"var data = context.get('data') || []\n\nif(data.length == 0){\n    data.push(msg.payload)\n}\nelse{\n    var idx = data.findIndex( element => element.x == msg.payload.x)\n    if(idx == -1){\n        //x-axis value does not exist. create new datapoint\n        data.push(msg.payload)\n        // sort data as  x-axis values must be in linear order\n        data.sort((a, b) => a.x - b.x);\n    }\n    else{\n        //x-axis value exist. update y value for that datapoint\n        data[idx].y = msg.payload.y\n    }\n}\n\n\ncontext.set('data',data)\n\n\n\nmsg.payload = [{\n    \"series\": [\"A\"],\n    \"xAxisID\": 'custom-x-axis',\n    \"yAxisID\": 'custom-y-axis',\n    \"data\": [data],\n    \"labels\": [\"\"]\n}]\n\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":540,"y":280,"wires":[["8f963860.bf5468","f84ec1a3.50318"]]},{"id":"c4f537f2.375308","type":"ui_template","z":"7ee51301.a9185c","group":"c7a27394.057878","name":"CSS","order":6,"width":0,"height":0,"format":"<style>\n    canvas.chart.chart-line {\n        height:calc(100%) !important;\n        width: calc(100%) !important;\n    }\n</style>","storeOutMessages":true,"fwdInMessages":true,"resendOnRefresh":true,"templateScope":"global","x":190,"y":360,"wires":[[]]},{"id":"146b04a0.ed33cb","type":"function","z":"7ee51301.a9185c","name":"random data","func":"var data = {}\ndata.x= Math.floor(Math.random()*60)\ndata.y = ((Math.random()*40)-20) - (data.x*0.2)\n\nmsg.payload = data\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":370,"y":280,"wires":[["46dd99bd.680638"]]},{"id":"8f963860.bf5468","type":"debug","z":"7ee51301.a9185c","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":770,"y":260,"wires":[]},{"id":"c7a27394.057878","type":"ui_group","name":"CHART","tab":"54e197d8.7f7fe8","order":2,"disp":false,"width":"9","collapse":false},{"id":"54e197d8.7f7fe8","type":"ui_tab","name":"Home","icon":"dashboard","disabled":false,"hidden":false}]

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.