Skip to content

How do I localize Chartjs 3.0 tooltip #8308

Answered by etimberg
paulhayessilex asked this question in Q&A
Discussion options

You must be logged in to vote

The simplest way to do this is to use the tooltip callbacks to generate a different string. Inside of that I would use Intl.NumberFormat to do the actual formatting.

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'
};

Replies: 2 comments 3 replies

Comment options

You must be logged in to vote
3 replies
@paulhayessilex
Comment options

@paulhayessilex
Comment options

@paulhayessilex
Comment options

Comment options

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