Does the chartjs supports localization?

👍:0

Chart.js uses moment for date-handling. You can set the locale globally on moment before initializing the chart.

  1. Import moment-with-locales.min.js in your HTML.
  2. Set the locale in a JavaScript: moment.locale('sv-SE');
  3. Inititialize your chart.

👍:0

Assuming you’re talking about localizing dates, you need to first make sure the chart displays dates that can be parsed by the JavaScript’s toLocaleDateString function.
e.g. options.scales.xAxes[0].time.displayFormats.day = 'h:mm:ss a';
The list of possible formats is https://www.chartjs.org/docs/2.9.4/axes/cartesian/time.html

Then, again, in your options json options.scales.xAxes[0].ticks, set a callback to your date value where you can localize it like shown below.

callback: function (value) {
  return new Date(value).toLocaleDateString('ja-JP', {
    dateStyle: 'long',
    timeStyle: 'long'
  });
}

👍:-2

Well, chartjs has nothing to do with localization; and no, it doesn’t.

They even have no support for flipping labels etc. But you shouldn’t have any problems unless you need to display rtl charts.

Leave a comment