chartjs / chartjs/Chart.js

Tick NumberFormat not working for 0

Open
#11,905 0 comments 0 reactions 0 assignees View on GitHub
type: bug
Dominant language
JavaScript
Stars
67.7k
Forks
11.9k
Avg merge
7h 39m
Merged PRs (30d)
5

Description

### 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_

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.