Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

extra zeros for y axis ticks #10324

Closed
digiage opened this issue Apr 28, 2022 · 2 comments
Closed

extra zeros for y axis ticks #10324

digiage opened this issue Apr 28, 2022 · 2 comments

Comments

@digiage
Copy link

digiage commented Apr 28, 2022

Expected behavior

No parasitic decimal places when ticks value used in callback

Current behavior

I use the ticks callback to replace decimal separator. Sometimes the value (val) of this callback includes additional parasite decimal places (log here):

image

but when callback is not used there is a standard number of decimal places (numbers like 12.1, 12.4 ...)

the code for ticks setup is here

scales:{
  ['y-' + id ]:{
    ticks:{
      callback: function(val, index) {
        console.log('val', val);
	return val.toString().replace('.', ',');
      }
    }
  }
}

Reproducible sample

https://codesandbox.io/s/react-chartjs-2-chart-js-issue-template-forked-v99pdg?file=/src/App.jsx

Optional extra steps/info to reproduce

I don't think I am able to reproduce the issue in sandbox as this happens only sometimes. Link can be added later on, when project is online.

Possible solution

No response

Context

No response

chart.js version

3.6.2

Browser name and version

No response

Link to your project

No response

@LeeLenaleee
Copy link
Collaborator

duplicate of #9991

https://www.chartjs.org/docs/master/axes/labelling.html#creating-custom-tick-formats

@digiage
Copy link
Author

digiage commented May 2, 2022

this seems to do the trick:

callback(value) { return this.getLabelForValue(value); }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants