Chart.js
Chart.js copied to clipboard
fix: apply ticks.format to the value 0
Closes #11905
Ticks.formatters.numeric returned the literal '0' for a zero tick, short-circuiting before formatNumber. As a result a configured ticks.format (e.g. { style: 'currency', currency: 'USD' } or { style: 'percent' }) was ignored only for the value 0 — an axis would render 0 instead of $0 / 0%, while every other tick was formatted correctly.
Zero now flows through formatNumber with the configured format, but with minimumFractionDigits/maximumFractionDigits forced to 0 and handled before the scientific-notation logic. This preserves the existing behavior (plain 0, no decimals, no scientific notation) when no format is set, while applying the format when one is provided.
Test plan
- Added unit tests in
test/specs/core.ticks.tests.js:ticks.format(currency / percent) is applied to0→$0,0%- with no format,
0stays0(no decimals; and no0E0even for huge ranges)
core.ticksspec passes on Chrome (6/6).