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

fix: apply ticks.format to the value 0

Open harukikuri opened this issue 6 months ago • 0 comments

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 to 0 → $0, 0%
    • with no format, 0 stays 0 (no decimals; and no 0E0 even for huge ranges)
  • core.ticks spec passes on Chrome (6/6).

harukikuri avatar May 29 '26 05:05 harukikuri