Set Bar Chart Y-Axis dynamically, to handle negative values
By default, the Bar Chart will not display negative values, such as low temperature data, without fixing the Y-Axis minimum values in the Chart node UI.
This flow looks at the incoming data and identifies the minimum value. If it's less than zero, the msg.ui_control "ymin" value is set to that value, which formats the scale in the chart node.
[{"id":"c7599c1.6cf866","type":"ui_chart","z":"f82b93ba.98aad","name":"","group":"61d2dced.3db8f4","order":0,"width":"6","height":"6","label":"chart","chartType":"bar","legend":"false","xformat":"HH:mm:ss","interpolate":"linear","nodata":"","dot":false,"ymin":"","ymax":"","removeOlder":1,"removeOlderPoints":"","removeOlderUnit":"3600","cutout":0,"useOneColor":false,"colors":["#1f77b4","#aec7e8","#ff7f0e","#2ca02c","#98df8a","#d62728","#ff9896","#9467bd","#c5b0d5"],"useOldStyle":false,"x":639,"y":375,"wires":[[],[]]},{"id":"caffa85d.ba12b8","type":"function","z":"f82b93ba.98aad","name":"Format Y-Axis","func":"//Assuming payload[0].data[0] holds the data value array\n//depending upon format of bar graph - var num path may need to be changed\nvar num= msg.payload[0].data[0];\n\nvar min = Math.min(...num);\nif (min < 0) {\n msg.ui_control = { \"ymin\":(Math.floor(min)) }\n } else {\n msg.ui_control = { \"ymin\":0 } \n }\n \nreturn msg;","outputs":1,"noerr":0,"x":488,"y":375,"wires":[["c7599c1.6cf866"]]},{"id":"f7a7179f.603f48","type":"inject","z":"f82b93ba.98aad","name":"","topic":"","payload":"[{\"series\":[\"X\"],\"data\":[[15,10,5,1,0,-3,-6.2,0,4]],\"labels\":[\"1\",\"2\",\"3\",\"4\",\"5\",\"6\",\"7\",\"8\",\"9\"]}]","payloadType":"json","repeat":"15","crontab":"","once":true,"onceDelay":0.1,"x":106,"y":375,"wires":[["caffa85d.ba12b8"]]},{"id":"97e92da7.09448","type":"inject","z":"f82b93ba.98aad","name":"","topic":"","payload":"[{\"series\":[\"X\"],\"data\":[[4,3,2,1,0,-1,-2,-3,-4]],\"labels\":[\"1\",\"2\",\"3\",\"4\",\"5\",\"6\",\"7\",\"8\",\"9\"]}]","payloadType":"json","repeat":"15","crontab":"","once":true,"onceDelay":0.1,"x":106,"y":414,"wires":[["75093cb5.db8174"]]},{"id":"75093cb5.db8174","type":"delay","z":"f82b93ba.98aad","name":"","pauseType":"delay","timeout":"5","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":245.5,"y":414,"wires":[["caffa85d.ba12b8"]]},{"id":"98273b74.779208","type":"inject","z":"f82b93ba.98aad","name":"","topic":"","payload":"[{\"series\":[\"X\"],\"data\":[[44,33,28,10,5,13,12,6,4]],\"labels\":[\"1\",\"2\",\"3\",\"4\",\"5\",\"6\",\"7\",\"8\",\"9\"]}]","payloadType":"json","repeat":"15","crontab":"","once":true,"onceDelay":0.1,"x":105,"y":452,"wires":[["4dbed3a3.51373c"]]},{"id":"4dbed3a3.51373c","type":"delay","z":"f82b93ba.98aad","name":"","pauseType":"delay","timeout":"10","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":243.5,"y":452,"wires":[["caffa85d.ba12b8"]]},{"id":"61d2dced.3db8f4","type":"ui_group","z":"","name":"Test","tab":"3c94630c.13381c","disp":true,"width":"12"},{"id":"3c94630c.13381c","type":"ui_tab","z":"","name":"Test","icon":"dashboard"}]