I want to force two decimals places for summed stacks on stacked bar chart components
Issue:
None of the data in my table is more precise than the hundredths decimal place, but the automatic summed stack label generated in the component has some really long values. No idea where this is coming from, but I want a hard method of preventing this.
Steps I've taken to troubleshoot:
Verified that my data is all only to the hundredths decimal place.
The solution comes from a quick line of JS that formats numbers to the hundredths place. I'm assuming you're mapping over an array of numbers, so your expression could look like this (where toFixed() sets which decimal place to be formatted):
{{ data.map(x => x.toFixed(2)) }}
If you're mapping over an array of strings, just wrap "x" in parseFloat() to convert it to a decimal:
{{ data.map(x => parseFloat(x).toFixed(2)) }}
Here's a screenshot of that in action in the Y data of a mock bar chart I created that maps over mock product costs:
This is coming straight from a sql query. The query already rounds the values to two decimals, so I just don't know where this is coming from. It seems more the trouble comes from the way that the grouped y-values are getting summed by the chart.
Thanks for giving that a try and letting me know it didn't work. I've escalated this issue internally to get some more eyes on this so we can investigate further. I'll keep you posted here as soon as I have an update!
I have the same issue. In the Series Data labels options you can change the number of displayed decimals places. Could this same option be added to the βSummed stacks data labelβ?
I think that would be a reasonable solution, @mikeheiss! I'll add this note to the internal convo that Branden already kicked off and get back to you as soon as I can.