Csv file to chart

Hi!

Im Hungary so sorry my bad english.

I send temperature data with esp8266 with mqtt. I draw a diagram (chart) and I went down to the .csv file.

How can I make a chart from .csv file?

flows2.json (3.5 KB)
ment.txt (5.1 KB)
TXT file because that's how I able to upload it here.

Thanks

Welcome to the forum.

This is a common question asked here. If you search the forum for
CSV chart
you will find several threads.

If you need to post a flow again then see this post for how to do that How to share code or flow json

If you are a beginner with nodered I recommend watching this playlist: Node-RED Essentials. The videos are done by the developers of node-red. They're nice & short and to the point. You will understand a whole lot more in about 1 hour. A small investment for a lot of gain.

[{"id":"578e4ece.740fb","type":"tab","label":"Chart - JSON data to Dashboard ","disabled":false,"info":""},{"id":"dc77a1fa.1d179","type":"ui_chart","z":"578e4ece.740fb","name":"","group":"770538f1.66e878","order":0,"width":0,"height":0,"label":"{{msg.label}}","chartType":"line","legend":"true","xformat":"HH:mm:ss","interpolate":"step","nodata":"","dot":false,"ymin":"","ymax":"","removeOlder":"1","removeOlderPoints":"","removeOlderUnit":"3600","cutout":0,"useOneColor":false,"useUTC":false,"colors":["#1f77b4","#aec7e8","#ff7f0e","#2ca02c","#98df8a","#d62728","#ff9896","#9467bd","#c5b0d5"],"outputs":1,"useDifferentColor":false,"x":550,"y":460,"wires":[["8134c85a.895e08"]]},{"id":"5b6c4e78.45035","type":"function","z":"578e4ece.740fb","name":"Setup payload","func":"series = [];\ndata = [];\nlabels = [];\n\nseries.push(\"Temp\");\nlabels.push(\"Temp\");\ndata.push(msg.data);\n\nmsg.payload = [{\"series\":series, \"data\":data,\"labels\": labels}];\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":480,"y":380,"wires":[["ce576854.132428","dc77a1fa.1d179"]]},{"id":"ce576854.132428","type":"debug","z":"578e4ece.740fb","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","x":690,"y":380,"wires":[]},{"id":"1676e907.849427","type":"watch","z":"578e4ece.740fb","name":"Watch chart1.txt","files":"/mnt/rssd/ment.csv","recursive":"","x":180,"y":160,"wires":[["64a684f6.f507dc"]]},{"id":"cb101826.98daa8","type":"debug","z":"578e4ece.740fb","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","statusVal":"","statusType":"auto","x":850,"y":260,"wires":[]},{"id":"d49a4414.251d18","type":"file in","z":"578e4ece.740fb","name":"","filename":"/mnt/rssd/ment.csv","format":"lines","chunk":false,"sendError":false,"x":550,"y":160,"wires":[["65d3b86.4bad748","9b967ad2.875f98"]]},{"id":"64a684f6.f507dc","type":"change","z":"578e4ece.740fb","name":"Set filename","rules":[{"t":"set","p":"filename","pt":"msg","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":350,"y":160,"wires":[["d49a4414.251d18"]]},{"id":"9b967ad2.875f98","type":"join","z":"578e4ece.740fb","name":"","mode":"custom","build":"array","property":"payload","propertyType":"msg","key":"topic","joiner":"\\n","joinerType":"str","accumulate":false,"timeout":"","count":"","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"","reduceFixup":"","x":350,"y":240,"wires":[["8a29dd98.b2c0f","26e24857.84ae18"]]},{"id":"26e24857.84ae18","type":"function","z":"578e4ece.740fb","name":"Build Data array","func":"\n\n/*\nfunction fixData(elem) {\n    return {\"x\" : new Date(elem.Timedate).getTime(), \"y\":parseFloat(elem.Temp)};\n}\n\nlet adata = msg.payload.map(fixData);\nmsg.data = adata;\nreturn msg;\n\n\n\n*/","outputs":1,"noerr":0,"initialize":"","finalize":"","x":600,"y":240,"wires":[["cb101826.98daa8","5b6c4e78.45035"]]},{"id":"65d3b86.4bad748","type":"debug","z":"578e4ece.740fb","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":800,"y":140,"wires":[]},{"id":"8134c85a.895e08","type":"debug","z":"578e4ece.740fb","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":730,"y":460,"wires":[]},{"id":"8a29dd98.b2c0f","type":"debug","z":"578e4ece.740fb","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":350,"y":300,"wires":[]},{"id":"770538f1.66e878","type":"ui_group","name":"Group 1","tab":"b5acd512.0b8b98","order":1,"disp":true,"width":"12","collapse":false},{"id":"b5acd512.0b8b98","type":"ui_tab","name":"Tab1","icon":"dashboard"}]

It is almost works. I cant write a function.

Show us what is going into the setup payload function and what comes out of it.

Edit, I am assuming that it is the final function that is not working, if not then tell us which bit isn't working.

[{"id":"e459c529.3efd08","type":"tab","label":"graph csv","disabled":false,"info":""},{"id":"9b28a059.04552","type":"inject","z":"e459c529.3efd08","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"start","payload":"1","payloadType":"num","x":90,"y":80,"wires":[["76549421.1fc5ac"]]},{"id":"3a7595e5.8d2daa","type":"ui_chart","z":"e459c529.3efd08","name":"","group":"533e8032.78164","order":4,"width":0,"height":0,"label":"","chartType":"line","legend":"true","xformat":"MM.DD-HH:mm","interpolate":"bezier","nodata":"","dot":false,"ymin":"18","ymax":"24","removeOlder":"2","removeOlderPoints":"","removeOlderUnit":"86400","cutout":0,"useOneColor":false,"useUTC":false,"colors":["#1f77b4","#aec7e8","#ff7f0e","#2ca02c","#98df8a","#d62728","#ff9896","#9467bd","#c5b0d5"],"outputs":1,"useDifferentColor":false,"x":770,"y":160,"wires":[["4724fa6a.a738c4"]]},{"id":"5c6a3ffb.124b8","type":"debug","z":"e459c529.3efd08","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":290,"y":100,"wires":[]},{"id":"76549421.1fc5ac","type":"file in","z":"e459c529.3efd08","name":"","filename":"/home/pi/mentes.csv","format":"utf8","chunk":false,"sendError":false,"encoding":"none","x":160,"y":160,"wires":[["e20a0d90.875c8","5c6a3ffb.124b8"]]},{"id":"e20a0d90.875c8","type":"csv","z":"e459c529.3efd08","name":"","sep":";","hdrin":false,"hdrout":"","multi":"mult","ret":"\\n","temp":"x,y","skip":"0","strings":true,"include_empty_strings":false,"include_null_values":false,"x":390,"y":160,"wires":[["4b0e85bf.559dac","19f4c4b8.00b2cb"]]},{"id":"4b0e85bf.559dac","type":"function","z":"e459c529.3efd08","name":"graph generate","func":"\nfunction toTimestamp(strDate){\n     var datum = Date.parse(strDate);\n     return datum/1000;\n    }\nvar payload=msg.payload;\n\n\nvar data_out=[];\nvar a1=[];\n\nfor(let i=0;i<payload.length;i++)\n{\n  \n//var Data= payload[i].Data.split(\"-\");\n//var t=Data[2]+\"/\"+Data[1]+\"/\"+Data[0];\n// timestamp=toTimestamp(t+\" \"+payload[i][\"Godzina\"]);\n\n\nvar temp1={ \"x\":( payload[i][\"x\"]), \"y\":( payload[i][\"y\"]) };\n\n\na1.push(temp1);\n\n \n \n //\n \n \n}\n\ndata_out=[a1];\nmsg.payload=[{\n\"series\": [\"esp\"],\n\"data\":data_out,\n\"labels\": [\"01\"]\n}];\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":580,"y":160,"wires":[["3a7595e5.8d2daa","a04160a2.72642"]]},{"id":"19f4c4b8.00b2cb","type":"debug","z":"e459c529.3efd08","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":470,"y":100,"wires":[]},{"id":"a04160a2.72642","type":"debug","z":"e459c529.3efd08","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":670,"y":100,"wires":[]},{"id":"4724fa6a.a738c4","type":"debug","z":"e459c529.3efd08","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":890,"y":100,"wires":[]},{"id":"90d0fcfc.949a4","type":"ui_button","z":"e459c529.3efd08","name":"","group":"533e8032.78164","order":3,"width":0,"height":0,"passthru":false,"label":"frissít","tooltip":"","color":"","bgcolor":"","icon":"","payload":"","payloadType":"date","topic":"topic","topicType":"msg","x":90,"y":240,"wires":[["76549421.1fc5ac"]]},{"id":"533e8032.78164","type":"ui_group","name":"szoba hőmérséklet","tab":"ebb1ed1c.5ebe2","order":1,"disp":true,"width":11,"collapse":false},{"id":"ebb1ed1c.5ebe2","type":"ui_tab","name":"Szoba","icon":"dashboard","disabled":false,"hidden":false}]

Finally works.

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