How can I help you?
Internationalization in React Chart component
3 Feb 20267 minutes to read
Chart provides support for internationalization for the following elements:
- Data label
- Axis label
- Tooltip
For more information about number and date formatting, see the internationalization guide: internationalization.
Globalization
Globalization is the process of designing and developing a component that works in different cultures/locales. Use the internationalization library to localize numbers, dates, and times in the Chart component, for example by using the axis labelFormat property.
Numeric Format
The example below globalizes axis, point, and tooltip labels to the EUR currency format.
import * as React from "react";
import * as ReactDOM from "react-dom";
import { ChartComponent, SeriesCollectionDirective, SeriesDirective, Inject, ColumnSeries, Legend, Tooltip, DataLabel } from '@syncfusion/ej2-react-charts';
import { setCurrencyCode } from '@syncfusion/ej2-base';
import { data } from './datasource';
setCurrencyCode('EUR');
function App() {
const primaryxAxis = { edgeLabelPlacement: 'Shift', title: 'Years' };
const primaryyAxis = { labelFormat: 'c', title: 'Sales Amount in Millions' };
const marker = { dataLabel: { visible: true } };
const tooltip = { enable: true, format: '${point.x} : ${point.y}' };
return <ChartComponent id='charts' primaryXAxis={primaryxAxis} primaryYAxis={primaryyAxis} title='Average Sales Comparison' tooltip={tooltip}>
<Inject services={[ColumnSeries, Legend, Tooltip, DataLabel]}/>
<SeriesCollectionDirective>
<SeriesDirective dataSource={data} xName='x' yName='y' name='Product X' type='Column' marker={marker}>
</SeriesDirective>
<SeriesDirective dataSource={data} xName='x' yName='y1' name='Product Y' type='Column' marker={marker}>
</SeriesDirective>
</SeriesCollectionDirective>
</ChartComponent>;
}
;
export default App;
ReactDOM.render(<App />, document.getElementById("charts"));import * as React from "react";
import * as ReactDOM from "react-dom";
import { ChartComponent, SeriesCollectionDirective, AxesDirective, AxisDirective, SeriesDirective, Inject,
ColumnSeries, Legend, Tooltip, DataLabel, TooltipSettingsModel, AxisModel }
from'@syncfusion/ej2-react-charts';
import { loadCldr, setCurrencyCode } from '@syncfusion/ej2-base';
import { data } from './datasource';
setCurrencyCode('EUR');
function App() {
const primaryxAxis: AxisModel = { edgeLabelPlacement: 'Shift', title: 'Years' };
const primaryyAxis: AxisModel = { labelFormat: 'c', title: 'Sales Amount in Millions' };
const marker = { dataLabel: { visible: true } };
const tooltip: TooltipSettingsModel = { enable: true, format: '${point.x} : ${point.y}' };
return <ChartComponent id='charts'
primaryXAxis={primaryxAxis}
primaryYAxis={primaryyAxis}
title='Average Sales Comparison'
tooltip={tooltip}>
<Inject services={[ColumnSeries, Legend, Tooltip, DataLabel]} />
<SeriesCollectionDirective>
<SeriesDirective dataSource={data} xName='x' yName='y' name='Product X' type='Column'
marker={marker}>
</SeriesDirective>
<SeriesDirective dataSource={data} xName='x' yName='y1' name='Product Y' type='Column'
marker={marker}>
</SeriesDirective>
</SeriesCollectionDirective>
</ChartComponent>
};
export default App;
ReactDOM.render(<App />, document.getElementById("charts"));export let data = [
{ x: 1900, y: 4, y1: 2.6, y2: 2.8 },
{ x: 1920, y: 3.0, y1: 2.8, y2: 2.5 },
{ x: 1940, y: 3.8, y1: 2.6, y2: 2.8 },
{ x: 1960, y: 3.4, y1: 3, y2: 3.2 },
{ x: 1980, y: 3.2, y1: 3.6, y2: 2.9 },
{ x: 2000, y: 3.9, y1: 3, y2: 2 }
];export let data: Object[] = [
{ x: 1900, y: 4, y1: 2.6, y2: 2.8 },
{ x: 1920, y: 3.0, y1: 2.8, y2: 2.5 },
{ x: 1940, y: 3.8, y1: 2.6, y2: 2.8 },
{ x: 1960, y: 3.4, y1: 3, y2: 3.2 },
{ x: 1980, y: 3.2, y1: 3.6, y2: 2.9 },
{ x: 2000, y: 3.9, y1: 3, y2: 2 }
];