How do I localize Chartjs 3.0 tooltip #8308
Answered
by
etimberg
paulhayessilex
asked this question in
Q&A
|
How in the world can you localize the values in the tooltip of Chartjs 3.0???? |
Answered by
etimberg
Jan 15, 2021
Replies: 2 comments 3 replies
|
If you want the straight answer seeing from how you formulate your question: look in the documentation. If you want the slightly nicer explanation which you don't deserve, look at the custom callback of tooltip items and apply the right localisation there |
3 replies
|
The simplest way to do this is to use the tooltip callbacks to generate a different string. Inside of that I would use const formatter = new Intl.NumberFormat('en-US');
const options = {
plugins: {
tooltip: {
callbacks: {
label: (item) => {
// Note this code is not handling edge cases
const value = item.dataset[item.dataIndex];
const localeValue = formatter.format(value);
return `${item.label}: ${localeValue}`;
}
}
}
}
}Another option is to use the locale settings which I believe should change the tooltip too. const options = {
locale: 'en-US'
}; |
0 replies
Answer selected by
kurkle
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The simplest way to do this is to use the tooltip callbacks to generate a different string. Inside of that I would use
Intl.NumberFormatto do the actual formatting.Another option is to use the locale settings which I believe should change the tooltip too.