Internationalization in TypeScript Charts

Chart provides internationalization support for the following elements:

  • Data label
  • Axis label
  • Tooltip

For more information about number and date formatting, see the internationalization guide.

Globalization

Globalization lets a component work with different cultures and locales. In the Chart component, use setCulture and setCurrencyCode (with loadCldr for non-default cultures) to localize numbers, dates, and times. Combine with the axis labelFormat property to control the output format.

This page covers number, date, time, and currency formatting. For translating UI strings (button captions, error messages), use the L10n class.

Setting the culture

Before you can format values in a non-default culture, you must load the corresponding CLDR data and call setCulture and (for currency) setCurrencyCode. In an ES5 (script-tag) setup, load the required CLDR JSON files:

import { loadCldr, setCulture, setCurrencyCode } from '@syncfusion/ej2-base';
import * as germanData from '@syncfusion/ej2-cldr-data/main/de/all.json';
import * as numberingSystems from '@syncfusion/ej2-cldr-data/supplemental/numberingSystems.json';

loadCldr(germanData, numberingSystems);
setCulture('de-DE');
setCurrencyCode('EUR');

Numeric format

The example below globalize axis labels, data labels, and tooltip labels to the EUR currency format.

import { Chart, ColumnSeries, DataLabel, Tooltip } from '@syncfusion/ej2-charts';
Chart.Inject(ColumnSeries, DataLabel, Tooltip);
import { loadCldr, L10n, setCulture, setCurrencyCode } from '@syncfusion/ej2-base';
setCulture('de');
setCurrencyCode('EUR');
let chartData: Object[] = [
    { x: 1900, y: 4, y1: 2.6 }, { x: 1920, y: 3.0, y1: 2.8 },
    { x: 1940, y: 3.8, y1: 2.6}, { x: 1960, y: 3.4, y1: 3 },
    { x: 1980, y: 3.2, y1: 3.6 }, { x: 2000, y: 3.9, y1: 3 }
]
let chart: Chart = new Chart({
    primaryXAxis: {
        title: 'Year',
        edgeLabelPlacement: 'Shift'
    },
    primaryYAxis: {
        title: 'Sales Amount in Millions',
        //Label format as currency
        labelFormat: 'c'
    },
    series:[{
        dataSource: chartData,
        xName: 'x', yName: 'y',
        name: 'Product X', type: 'Column',
        marker: { dataLabel: { visible: true }}
    },{
        dataSource: chartData,
        xName: 'x', yName: 'y1',
        name: 'Product Y', type: 'Column',
         marker: { dataLabel: { visible: true }}
    }],
    title: 'Average Sales Comparison',
    tooltip: { enable: true, format: '${series.name} <br>${point.x} : ${point.y}'}
}, '#element');
<!DOCTYPE html>
<html lang="en">

<head>
    <title>EJ2 Animation</title>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta name="description" content="Typescript UI Controls" />
    <meta name="author" content="Syncfusion" />
    <link href="index.css" rel="stylesheet" />
    <script src="https://cdnjs.cloudflare.com/ajax/libs/systemjs/0.19.38/system.js"></script>
    <script src="systemjs.config.js"></script>
</head>

<body>
    <div id='loader'>Loading....</div>
    <div id='container'>
        <div id='element'></div>
    </div>
</body>

</html>

Troubleshooting

  • The expected culture is not applied: Confirm that the required CLDR data is loaded before calling setCulture and before creating the Chart.
  • The wrong currency symbol is displayed: Call setCurrencyCode with the required ISO currency code and use the c currency format in the axis or data-label configuration.
  • Dates or numbers use the default US format: Verify that setCulture is called before the Chart is initialized.
  • A culture-loading error occurs: Confirm that the required numbers, currencies, ca-Gregorian, timeZoneNames, and numberingSystems data files are available and loaded correctly.

See also