Skip to content

Formatting datalabels #298

Answered by nsartor
Samamoah asked this question in Q&A
Discussion options

You must be logged in to vote

@Samamoah I was able to get this to work using chartjs 3.0 and a regex. I know you're using 2x, but if you happen to upgrade this should do it. I never got it to work using toLocaleString which would have been much cleaner.

datalabels: {
  formatter: (value, ctx) => {
    return value.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ',');
  },
}

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by simonbrunel
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants