chartjs / chartjs/Chart.js

Wrong tooltip value/formattedValue shown if category scale contains labels that convert to numbers within 0..labels.length

Open
#12,107 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

In the tooltip for values with a category scale the formattedValue is showing a completely wrong value if the category scale contains labels that convert to numbers within 0..labels.length.
E.g. if there are 5 labels and one of them is "1" for items having that value "1" a wrong tooltip value is returned.

### Current behavior

Currently the nth label is shown for a value of "n" and not the label "n".

### Reproducible sample

https://github.com/chartjs/Chart.js/pull/12106

### Optional extra steps/info to reproduce

I think this is due to scale.category.js _getLabelForValue ignoring the type.

### Possible solution

See adjusted test case showing the issue and potential fix in
https://github.com/chartjs/Chart.js/pull/12106

### Context

_No response_

### chart.js version

v4.5.0

### Browser name and version

_No response_

### Link to your project

https://github.com/mbehr1/dlt-logs/issues/268

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.