Chart.js icon indicating copy to clipboard operation
Chart.js copied to clipboard

Tick NumberFormat not working for 0

Open SosthenG opened this issue 1 year ago • 0 comments

Expected behavior

The 0 value is formatted as the other ticks when a "format" config is provided in scales.y.ticks.format

Current behavior

The 0 is never formatted

Reproducible sample

https://codepen.io/SosthenG/pen/rNXNPPL

Optional extra steps/info to reproduce

No response

Possible solution

Issue is here : https://github.com/chartjs/Chart.js/blob/ea88dba68d41d4974c1fff5ce1c60f5d68279c13/src/core/core.ticks.js#L28-L31

While it makes sense to prevent the 0 value to have any decimal, it also prevent the call to formatNumber. I think it should be possible to achieve the same by still calling the formatNumber in any case but forcing the minimumFractionDigits to 0 if the value is 0.

Context

I want the 0 to be formatted the same as other values because otherwise it does not look well when using percent or currency values to have juste "0" without the unit.

chart.js version

4.4.2

Browser name and version

No response

Link to your project

No response

SosthenG avatar Sep 24 '24 12:09 SosthenG