Localization

Overview

All AnyChart products support full localization of input and output date/time and number formats, based on the locale mechanism. This article describes how to use locales (which is quite easy).

All the methods you need are located on anychart.format namespace.

You can also see how locales work using our localization demo applications:

Applying an Automatic Locale

AnyChart provides built-in locales covering most regions and cultures. To use an automatic locale, first link a file from AnyChart CDN or download it to your server and link it from there.

Linking from CDN looks like this:

<script src="https://cdn.anychart.com/locale/1.1.0/en-gb.js">
<script src="https://cdn.anychart.com/locale/1.1.0/en-us.js">

Linking from your server may look like this:

<script src="./locales/en-gb.js">
<script src="http://mydomain.com/anychart-locales/en-us.js">

After the file is linked, AnyChart engine knows about it, and you can start applying the locale in your charts: just set the code of the locale using the inputLocale() or outputLocale() methods. Codes of locales are listed in the CODE column on AnyChart CDN.

Setting input and output locales looks like this:

anychart.format.inputLocale('en-us');
anychart.format.outputLocale('hi-in');

Tuning a Locale

If you want to use custom input and output date/time formats, you can tune them via the inputDateTimeFormat() and outputDateTimeFormat() methods:

// set locales
anychart.format.inputLocale('en-us');
anychart.format.outputLocale('hi-in');

// tune inputDateTimeFormat and outputDateTimeFormat
anychart.format.inputDateTimeFormat('yyyy-MM-dd'); 
anychart.format.outputDateTimeFormat('dd MMM');

You can also tune any output in tooltips or labels formatters using dateTime() and {api:}number(){api} methods:

chart.xAxis().labels().format(function () {
    return anychart.format.dateTime(this.value, 'MMM', -8 * 60, locale);
});
chart.tooltip().titleFormat(function () {
    return anychart.format.dateTime(this.points[0].x, format, -8 * 60, locale);
});

Locales in AnyChart CDN

You can get all available locales from AnyChart CDN and either download them to your server or link directly from the CDN.