Bar Chart 2 decimals

Hi,
I made a bar chart with this data. And I would like to have the value CUMULWATT with only 2 decimals.
Here is my code, but it doesn't work ..

Edit Function Node

var m = {};
m.labels = ;
m.data = ;
m.series = ["Euros"];
var arrayLength = msg.payload.length;
for (var i = 0; i < arrayLength; i++) {
m.labels.push((msg.payload[i].fecha3));
m.data.push(msg.payload[i].CUMULWATT*0.00018).toFixed(2);
}
return {payload:[m],topic:msg.topic};

Thank you

I understand that value.toFixed(2) will give you a string. As you want to get a number probably you have to convert the result to float again. Something like
parseFloat(value.toFixed(2)). I can´t test right now though.

You would be converting the length of the array you just pushed to. As push will return the array length.

The toFixed needs to be inside the push ( ). Would probably be better to use Math.round()

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