Data Labels in React Charts
Data labels display the values of data points directly on the chart, removing the need to reference axes for exact values. Data labels are configured under the marker.dataLabel property of each series. Enable data labels by setting the visible option to true. Labels automatically adjust to avoid overlapping and to maintain readability.
import * as React from "react";
import * as ReactDOM from "react-dom";
import { ChartComponent, SeriesCollectionDirective, SeriesDirective, Inject, Legend, DateTime, Tooltip, DataLabel, LineSeries } from '@syncfusion/ej2-react-charts';
import { data } from './datasource';
function App() {
const primaryxAxis = { valueType: 'DateTime' };
const marker = {
visible: true,
height: 10, width: 10,
shape: 'Pentagon',
dataLabel: { visible: true }
};
return <ChartComponent id='charts' primaryXAxis={primaryxAxis}>
<Inject services={[LineSeries, Legend, Tooltip, DataLabel, DateTime]}/>
<SeriesCollectionDirective>
<SeriesDirective dataSource={data} xName='x' yName='y' width={2} name='Warmest' type='Line' 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 {
AxisModel, ChartComponent, SeriesCollectionDirective, SeriesDirective, Inject,
Legend, DateTime, Tooltip, DataLabel, LineSeries, MarkerSettingsModel
} from '@syncfusion/ej2-react-charts';
import { data } from './datasource';
function App() {
const primaryxAxis: AxisModel = { valueType: 'DateTime' };
const marker: MarkerSettingsModel = {
visible: true,
height: 10, width: 10,
shape: 'Pentagon',
dataLabel: { visible: true }
};
return <ChartComponent id='charts'
primaryXAxis={primaryxAxis}>
<Inject services={[LineSeries, Legend, Tooltip, DataLabel, DateTime]} />
<SeriesCollectionDirective>
<SeriesDirective dataSource={data} xName='x' yName='y' width={2} name='Warmest'
type='Line' marker={marker}>
</SeriesDirective>
</SeriesCollectionDirective>
</ChartComponent>
};
export default App;
ReactDOM.render(<App />, document.getElementById("charts"));export let data = [
{ x: new Date(2016, 0, 1), y: -7.1 }, { x: new Date(2016, 1, 1), y: -3.7 },
{ x: new Date(2016, 2, 1), y: 0.8 }, { x: new Date(2016, 3, 1), y: 6.3 },
{ x: new Date(2016, 4, 1), y: 13.3 }, { x: new Date(2016, 5, 1), y: 18.0 },
{ x: new Date(2016, 6, 1), y: 19.8 }, { x: new Date(2016, 7, 1), y: 18.1 },
{ x: new Date(2016, 8, 1), y: 13.1 }, { x: new Date(2016, 9, 1), y: 4.1 },
{ x: new Date(2016, 10, 1), y: -3.8 }, { x: new Date(2016, 11, 1), y: -6.8 }
];export let data: Object[] = [
{ x: new Date(2016, 0, 1), y: -7.1 }, { x: new Date(2016, 1, 1), y: -3.7 },
{ x: new Date(2016, 2, 1), y: 0.8 }, { x: new Date(2016, 3, 1), y: 6.3 },
{ x: new Date(2016, 4, 1), y: 13.3 }, { x: new Date(2016, 5, 1), y: 18.0 },
{ x: new Date(2016, 6, 1), y: 19.8 }, { x: new Date(2016, 7, 1), y: 18.1 },
{ x: new Date(2016, 8, 1), y: 13.1 }, { x: new Date(2016, 9, 1), y: 4.1 },
{ x: new Date(2016, 10, 1), y: -3.8 }, { x: new Date(2016, 11, 1), y: -6.8 }
];Note: To use the data label feature, the
DataLabelmodule must be injected into theservices.
Position
Use the position property to place data labels at Top, Middle, Bottom, or Outer. The Outer position applies only to column and bar series types. Appropriate label positioning enhances clarity and preserves chart readability.
import * as React from "react";
import * as ReactDOM from "react-dom";
import { ChartComponent, SeriesCollectionDirective, SeriesDirective, Inject, Legend, Category, Tooltip, DataLabel, LineSeries } from '@syncfusion/ej2-react-charts';
import { data } from './datasource';
function App() {
const primaryxAxis = { title: 'Months', valueType: 'Category' };
const marker = { dataLabel: { visible: true, position: 'Middle' } };
return <ChartComponent id='charts' primaryXAxis={primaryxAxis}>
<Inject services={[LineSeries, Legend, Tooltip, DataLabel, Category]}/>
<SeriesCollectionDirective>
<SeriesDirective dataSource={data} xName='x' yName='y' width={2} name='Warmest' type='Line' 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 { AxisModel, ChartComponent, SeriesCollectionDirective, SeriesDirective, Inject,
Legend, Category, Tooltip, DataLabel, LineSeries}
from'@syncfusion/ej2-react-charts';
import { data } from './datasource';
function App() {
const primaryxAxis: AxisModel = { title: 'Months', valueType: 'Category' };
const marker = { dataLabel: { visible: true, position: 'Middle' } };
return <ChartComponent id='charts'
primaryXAxis={primaryxAxis}>
<Inject services={[LineSeries, Legend, Tooltip, DataLabel, Category]} />
<SeriesCollectionDirective>
<SeriesDirective dataSource={data} xName='x' yName='y' width={2} name='Warmest'
type='Line' marker={marker}>
</SeriesDirective>
</SeriesCollectionDirective>
</ChartComponent>
};
export default App;
ReactDOM.render(<App />, document.getElementById("charts"));export let data = [
{ x: 'Jan', y: -7.1 }, { x: 'Feb', y: -3.7 },
{ x: 'Mar', y: 2 }, { x: 'Apr', y: 6.3 },
{ x: 'May', y: 13.3 }, { x: 'Jun', y: 18.0 },
{ x: 'Jul', y: 19.8 }, { x: 'Aug', y: 18.1 },
{ x: 'Sep', y: 13.1 }, { x: 'Oct', y: 4.1 },
{ x: 'Nov', y: -3.8 }, { x: 'Dec', y: -6.8 }
];export let data: Object[] = [
{ x: 'Jan', y: -7.1 }, { x: 'Feb', y: -3.7 },
{ x: 'Mar', y: 2 }, { x: 'Apr', y: 6.3 },
{ x: 'May', y: 13.3 }, { x: 'Jun', y: 18.0 },
{ x: 'Jul', y: 19.8 }, { x: 'Aug', y: 18.1 },
{ x: 'Sep', y: 13.1 }, { x: 'Oct', y: 4.1 },
{ x: 'Nov', y: -3.8 }, { x: 'Dec', y: -6.8 }
];Data label template
Customize label content using templates. Use placeholders such as ${point.x} and ${point.y} to display data point values. The template property enables fully customizable and visually rich labels.
import * as React from "react";
import * as ReactDOM from "react-dom";
import { ChartComponent, SeriesCollectionDirective, SeriesDirective, Inject, Legend, DateTime, Tooltip, DataLabel, LineSeries } from '@syncfusion/ej2-react-charts';
import { data } from './datasource';
function App() {
const primaryxAxis = { title: 'Months', valueType: 'DateTime', intervalType: 'Months' };
const template = chartTemplate;
const marker = { dataLabel: { visible: true, position: 'Middle', template: template } };
function chartTemplate(args) {
return (<div id="templateWrap" style={{ border: '1px solid black', backgroundColor: 'red', padding: '3px 3px 3px 3px' }}>
<div>{args.point.x.getFullYear()}</div>
<div>{args.point.y}</div>
</div>);
}
;
return <ChartComponent id='charts' primaryXAxis={primaryxAxis}>
<Inject services={[LineSeries, Legend, Tooltip, DataLabel, DateTime]} />
<SeriesCollectionDirective>
<SeriesDirective dataSource={data} xName='x' yName='y' width={2} name='Warmest' type='Line' 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 {
AxisModel, ChartComponent, SeriesCollectionDirective, SeriesDirective, Inject,
Legend, DateTime, Tooltip, DataLabel, LineSeries, MarkerSettingsModel
}
from '@syncfusion/ej2-react-charts';
import { data } from './datasource';
function App() {
const primaryxAxis: AxisModel = { title: 'Months', valueType: 'DateTime', intervalType: 'Months' };
const template: any = chartTemplate;
const marker: MarkerSettingsModel = { dataLabel: { visible: true, position: 'Middle', template: template } };
function chartTemplate(args: any) {
return (<div id="templateWrap" style={{ border: '1px solid black', backgroundColor: 'red', padding: '3px 3px 3px 3px' }}>
<div>{args.point.x.getFullYear()}</div>
<div>{args.point.y}</div>
</div>);
};
return <ChartComponent id='charts'
primaryXAxis={primaryxAxis}>
<Inject services={[LineSeries, Legend, Tooltip, DataLabel, DateTime]} />
<SeriesCollectionDirective>
<SeriesDirective dataSource={data} xName='x' yName='y' width={2} name='Warmest'
type='Line' marker={marker}>
</SeriesDirective>
</SeriesCollectionDirective>
</ChartComponent>
};
export default App;
ReactDOM.render(<App />, document.getElementById("charts"));export let data = [
{ x: new Date(2016, 0, 1), y: -7.1 }, { x: new Date(2016, 1, 1), y: -3.7 },
{ x: new Date(2016, 2, 1), y: 0.8 }, { x: new Date(2016, 3, 1), y: 6.3 },
{ x: new Date(2016, 4, 1), y: 13.3 }, { x: new Date(2016, 5, 1), y: 18.0 },
{ x: new Date(2016, 6, 1), y: 19.8 }, { x: new Date(2016, 7, 1), y: 18.1 },
{ x: new Date(2016, 8, 1), y: 13.1 }, { x: new Date(2016, 9, 1), y: 4.1 },
{ x: new Date(2016, 10, 1), y: -3.8 }, { x: new Date(2016, 11, 1), y: -6.8 }
];export let data: Object[] = [
{ x: new Date(2016, 0, 1), y: -7.1 }, { x: new Date(2016, 1, 1), y: -3.7 },
{ x: new Date(2016, 2, 1), y: 0.8 }, { x: new Date(2016, 3, 1), y: 6.3 },
{ x: new Date(2016, 4, 1), y: 13.3 }, { x: new Date(2016, 5, 1), y: 18.0 },
{ x: new Date(2016, 6, 1), y: 19.8 }, { x: new Date(2016, 7, 1), y: 18.1 },
{ x: new Date(2016, 8, 1), y: 13.1 }, { x: new Date(2016, 9, 1), y: 4.1 },
{ x: new Date(2016, 10, 1), y: -3.8 }, { x: new Date(2016, 11, 1), y: -6.8 }
];Text mapping
Display custom text using the name property, which maps label text from a specific field in the data source. This feature is useful for descriptive or category-based labels.
import * as React from "react";
import * as ReactDOM from "react-dom";
import { ChartComponent, SeriesCollectionDirective, SeriesDirective, Inject, Legend, Category, Tooltip, DataLabel, ColumnSeries } from '@syncfusion/ej2-react-charts';
import { mapData } from './datasource';
function App() {
const primaryxAxis = { valueType: 'Category' };
const marker = { dataLabel: { visible: true, name: 'text' } };
return <ChartComponent id='charts' primaryXAxis={primaryxAxis}>
<Inject services={[ColumnSeries, Legend, Tooltip, DataLabel, Category]}/>
<SeriesCollectionDirective>
<SeriesDirective dataSource={mapData} xName='x' yName='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 { AxisModel, ChartComponent, SeriesCollectionDirective, SeriesDirective, Inject,
Legend, Category, Tooltip, DataLabel, ColumnSeries}
from'@syncfusion/ej2-react-charts';
import { mapData } from './datasource';
function App() {
const primaryxAxis: AxisModel = { valueType: 'Category' };
const marker = { dataLabel: { visible: true, name: 'text' } };
return <ChartComponent id='charts'
primaryXAxis={primaryxAxis}>
<Inject services={[ColumnSeries, Legend, Tooltip, DataLabel, Category]} />
<SeriesCollectionDirective>
<SeriesDirective dataSource={mapData} xName='x' yName='y'
type='Column' marker={marker}>
</SeriesDirective>
</SeriesCollectionDirective>
</ChartComponent>
};
export default App;
ReactDOM.render(<App />, document.getElementById("charts"));export let mapData = [
{ x: 'Jan', y: 12, text: 'January : 12°C' },
{ x: 'Feb', y: 8, text: 'February : 8°C' },
{ x: 'Mar', y: 11, text: 'March : 11°C' },
{ x: 'Apr', y: 6, text: 'April : 6°C' }
];export let mapData: Object[] = [
{ x: 'Jan', y: 12, text: 'January : 12°C' },
{ x: 'Feb', y: 8, text: 'February : 8°C' },
{ x: 'Mar', y: 11, text: 'March : 11°C' },
{ x: 'Apr', y: 6, text: 'April : 6°C' }
];Format
Apply number or date formatting using the format property. Global formatting symbols include:
-
n- number format -
p- percentage format -
c- currency format
The format property also supports placeholders such as {value}°C, where {value} represents the data point’s value (for example, 20°C).
| Value | Format | Resultant Value | Description |
|---|---|---|---|
| 1000 | n1 | 1000.0 | Formats as a number with 1 decimal place. |
| 1000 | n2 | 1000.00 | Formats as a number with 2 decimal places. |
| 1000 | n3 | 1000.000 | Formats as a number with 3 decimal places. |
| 0.01 | p1 | 1.0% | Formats as a percentage with 1 decimal place. |
| 0.01 | p2 | 1.00% | Formats as a percentage with 2 decimal places. |
| 0.01 | p3 | 1.000% | Formats as a percentage with 3 decimal places. |
| 1000 | c1 | $1000.0 | Formats as currency with 1 decimal place. |
| 1000 | c2 | $1000.00 | Formats as currency with 2 decimal places. |
import * as React from "react";
import * as ReactDOM from "react-dom";
import { ChartComponent, SeriesCollectionDirective, SeriesDirective, Inject, Legend, Category, Tooltip, DataLabel, ColumnSeries } from '@syncfusion/ej2-react-charts';
import { mapData } from './datasource';
class App extends React.Component {
primaryxAxis = { valueType: 'Category' };
marker = { dataLabel: { visible: true, format: 'n2' } };
render() {
return <ChartComponent id='charts' primaryXAxis={this.primaryxAxis}>
<Inject services={[ColumnSeries, Legend, Tooltip, DataLabel, Category]}/>
<SeriesCollectionDirective>
<SeriesDirective dataSource={mapData} xName='x' yName='y' type='Column' marker={this.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 { AxisModel, ChartComponent, SeriesCollectionDirective, SeriesDirective, Inject,
Legend, Category, Tooltip, DataLabel, ColumnSeries}
from'@syncfusion/ej2-react-charts';
import { mapData } from './datasource';
class App extends React.Component<{}, {}> {
public primaryxAxis: AxisModel = { valueType: 'Category' };
public marker = { dataLabel: { visible: true, format: 'n2' } };
render() {
return <ChartComponent id='charts'
primaryXAxis={this.primaryxAxis}>
<Inject services={[ColumnSeries, Legend, Tooltip, DataLabel, Category]} />
<SeriesCollectionDirective>
<SeriesDirective dataSource={mapData} xName='x' yName='y'
type='Column' marker={this.marker}>
</SeriesDirective>
</SeriesCollectionDirective>
</ChartComponent>
}
};
export default App;
ReactDOM.render(<App />, document.getElementById("charts"));export let mapData = [
{ x: 'Jan', y: 12, text: 'January : 12°C' },
{ x: 'Feb', y: 8, text: 'February : 8°C' },
{ x: 'Mar', y: 11, text: 'March : 11°C' },
{ x: 'Apr', y: 6, text: 'April : 6°C' }
];export let mapData: Object[] = [
{ x: 'Jan', y: 12, text: 'January : 12°C' },
{ x: 'Feb', y: 8, text: 'February : 8°C' },
{ x: 'Mar', y: 11, text: 'March : 11°C' },
{ x: 'Apr', y: 6, text: 'April : 6°C' }
];Margin
Adjust spacing around labels using the margin property, which includes left, right, bottom, and top values. Margins help prevent labels from overlapping chart elements.
import * as React from "react";
import * as ReactDOM from "react-dom";
import { ChartComponent, SeriesCollectionDirective, SeriesDirective, Inject, Legend, Category, Tooltip, DataLabel, ColumnSeries } from '@syncfusion/ej2-react-charts';
import { columnData } from './datasource';
function App() {
const primaryxAxis = { valueType: 'Category' };
const marker = {
dataLabel: {
visible: true, border: { width: 1, color: 'red' },
margin: {
left: 5,
right: 5,
top: 5,
bottom: 5
}
}
};
return <ChartComponent id='charts' primaryXAxis={primaryxAxis}>
<Inject services={[ColumnSeries, Legend, Tooltip, DataLabel, Category]}/>
<SeriesCollectionDirective>
<SeriesDirective dataSource={columnData} xName='country' yName='gold' 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 { AxisModel, ChartComponent, SeriesCollectionDirective, SeriesDirective, Inject,
Legend, Category, Tooltip, DataLabel, ColumnSeries}
from'@syncfusion/ej2-react-charts';
import { columnData } from './datasource';
function App() {
const primaryxAxis: AxisModel = { valueType: 'Category' };
const marker = {
dataLabel: {
visible: true, border: { width: 1, color: 'red' },
margin: {
left: 5,
right: 5,
top: 5,
bottom: 5
}
}
};
return <ChartComponent id='charts'
primaryXAxis={primaryxAxis}>
<Inject services={[ColumnSeries, Legend, Tooltip, DataLabel, Category]} />
<SeriesCollectionDirective>
<SeriesDirective dataSource={columnData} xName='country' yName='gold'
type='Column' marker={marker}>
</SeriesDirective>
</SeriesCollectionDirective>
</ChartComponent>
};
export default App;
ReactDOM.render(<App />, document.getElementById("charts"));export let columnData = [
{ country: "USA", gold: 50 },
{ country: "China", gold: 40 },
{ country: "Japan", gold: 70 },
{ country: "Australia", gold: 60 },
{ country: "France", gold: 50 },
{ country: "Germany", gold: 40 },
{ country: "Italy", gold: 40 },
{ country: "Sweden", gold: 30 }
];export let columnData: Object[] = [
{ country: "USA", gold: 50 },
{ country: "China", gold: 40 },
{ country: "Japan", gold: 70 },
{ country: "Australia", gold: 60 },
{ country: "France", gold: 50 },
{ country: "Germany", gold: 40 },
{ country: "Italy", gold: 40 },
{ country: "Sweden", gold: 30 }
];Data label rotation
Rotate data labels by setting enableRotation to true and specifying the rotation angle with the angle property. Rotation improves readability when labels are long or when space is limited.
import * as React from "react";
import * as ReactDOM from "react-dom";
import { ChartComponent, SeriesCollectionDirective, SeriesDirective, Inject, Legend, Category, Tooltip, DataLabel, ColumnSeries } from '@syncfusion/ej2-react-charts';
import { columnData } from './datasource';
function App() {
const primaryxAxis = { valueType: 'Category' };
const marker = {
//Data label angle as 45
dataLabel: {
visible: true, border: { width: 1, color: 'red' },
margin: {
left: 5,
right: 5,
top: 5,
bottom: 5
}, angle: 45, enableRotation: true
}
};
return <ChartComponent id='charts' primaryXAxis={primaryxAxis}>
<Inject services={[ColumnSeries, Legend, Tooltip, DataLabel, Category]}/>
<SeriesCollectionDirective>
<SeriesDirective dataSource={columnData} xName='country' yName='gold' 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 { AxisModel, ChartComponent, SeriesCollectionDirective, SeriesDirective, Inject,
Legend, Category, Tooltip, DataLabel, ColumnSeries}
from'@syncfusion/ej2-react-charts';
import { columnData } from './datasource';
function App() {
const primaryxAxis: AxisModel = { valueType: 'Category' };
const marker = {
//Data label angle as 45
dataLabel: {
visible: true, border: { width: 1, color: 'red' },
margin: {
left: 5,
right: 5,
top: 5,
bottom: 5
}, angle: 45, enableRotation: true
}
};
return <ChartComponent id='charts'
primaryXAxis={primaryxAxis}>
<Inject services={[ColumnSeries, Legend, Tooltip, DataLabel, Category]} />
<SeriesCollectionDirective>
<SeriesDirective dataSource={columnData} xName='country' yName='gold'
type='Column' marker={marker}>
</SeriesDirective>
</SeriesCollectionDirective>
</ChartComponent>
};
export default App;
ReactDOM.render(<App />, document.getElementById("charts"));export let columnData = [
{ country: "USA", gold: 50 },
{ country: "China", gold: 40 },
{ country: "Japan", gold: 70 },
{ country: "Australia", gold: 60 },
{ country: "France", gold: 50 },
{ country: "Germany", gold: 40 },
{ country: "Italy", gold: 40 },
{ country: "Sweden", gold: 30 }
];export let columnData: Object[] = [
{ country: "USA", gold: 50 },
{ country: "China", gold: 40 },
{ country: "Japan", gold: 70 },
{ country: "Australia", gold: 60 },
{ country: "France", gold: 50 },
{ country: "Germany", gold: 40 },
{ country: "Italy", gold: 40 },
{ country: "Sweden", gold: 30 }
];Customization
Enhance label appearance using properties such as fill (background), border, and corner radius (rx, ry). Refine text appearance using the font settings, which support color, fontFamily, fontWeight, and size.
import * as React from "react";
import * as ReactDOM from "react-dom";
import { ChartComponent, SeriesCollectionDirective, SeriesDirective, Inject, Legend, Category, Tooltip, DataLabel, ColumnSeries } from '@syncfusion/ej2-react-charts';
import { columnData } from './datasource';
function App() {
const primaryxAxis = { valueType: 'Category' };
const marker = {
dataLabel: {
visible: true, font: { color: "blue", fontWeight: "500" }, border: { width: 2, color: 'red' },
rx: 10, ry: 10
}
};
return <ChartComponent id='charts' primaryXAxis={primaryxAxis}>
<Inject services={[ColumnSeries, Legend, Tooltip, DataLabel, Category]}/>
<SeriesCollectionDirective>
<SeriesDirective dataSource={columnData} xName='country' yName='gold' 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 { AxisModel, ChartComponent, SeriesCollectionDirective, SeriesDirective, Inject,
Legend, Category, Tooltip, DataLabel, ColumnSeries}
from'@syncfusion/ej2-react-charts';
import { columnData } from './datasource';
function App() {
const primaryxAxis: AxisModel = { valueType: 'Category' };
const marker = {
dataLabel: {
visible: true, font: { color: "blue", fontWeight: "500" }, border: { width: 2, color: 'red' },
rx: 10, ry: 10
}
};
return <ChartComponent id='charts'
primaryXAxis={primaryxAxis}>
<Inject services={[ColumnSeries, Legend, Tooltip, DataLabel, Category]} />
<SeriesCollectionDirective>
<SeriesDirective dataSource={columnData} xName='country' yName='gold'
type='Column' marker={marker}>
</SeriesDirective>
</SeriesCollectionDirective>
</ChartComponent>
};
export default App;
ReactDOM.render(<App />, document.getElementById("charts"));export let columnData = [
{ country: "USA", gold: 50 },
{ country: "China", gold: 40 },
{ country: "Japan", gold: 70 },
{ country: "Australia", gold: 60 },
{ country: "France", gold: 50 },
{ country: "Germany", gold: 40 },
{ country: "Italy", gold: 40 },
{ country: "Sweden", gold: 30 }
];export let columnData: Object[] = [
{ country: "USA", gold: 50 },
{ country: "China", gold: 40 },
{ country: "Japan", gold: 70 },
{ country: "Australia", gold: 60 },
{ country: "France", gold: 50 },
{ country: "Germany", gold: 40 },
{ country: "Italy", gold: 40 },
{ country: "Sweden", gold: 30 }
];Note: The
rxandryproperties require a non-nullbordervalue (with a definedwidthandcolor).
Handling Overlapping Data Labels
Use the labelIntersectAction property to specify how overlapping data labels are handled.
The available options are:
-
None- Displays all data labels even when they overlap. -
Hide- Hides overlapping data labels. -
Rotate90- Rotates overlapping data labels by 90 degrees. -
RelocateVertically- Relocates overlapping data labels vertically. -
RelocateHorizontally- Relocates overlapping data labels horizontally.
The RelocateVertically and RelocateHorizontally options are supported only for the following series types:
StackingColumnStackingColumn100StackingBarStackingBar100
These relocation modes enable the Smart Data Label feature, which improves readability by relocating overlapping data labels and connecting them to their corresponding data points using connector lines. Use the smartLabelSettings property to customize relocated labels through the background, pointerShape, border, connectorLineStyle, and offset settings. The offset property is applicable only when labelIntersectAction is set to RelocateVertically. Note that the seriesOverlapAction property in smartLabelSettings is not applicable for RelocateVertically and RelocateHorizontally.
import * as React from 'react';
import * as ReactDOM from 'react-dom';
import { ChartComponent, SeriesCollectionDirective, SeriesDirective, Inject, Legend, Category, Tooltip, DataLabel, StackingColumnSeries } from '@syncfusion/ej2-react-charts';
import { dataA, dataB, dataC, dataD, dataE, dataF, dataG, dataH } from './datasource';
function App() {
const primaryXAxis = {
valueType: 'Category'
};
const primaryYAxis = {
visible: false
};
const tooltip = {
enable: true
};
const legendSettings = {
visible: true
};
const marker = {
dataLabel: {
visible: true,
name: 'text',
fill: 'Transparent',
labelIntersectAction: 'RelocateVertically',
smartLabelSettings: {
background: '#4f4f4f',
border: {
color: 'black',
dashArray: '2',
width: 2
},
connectorLineStyle: {
color: 'black',
width: 2
},
pointerShape: 'Arrow',
offset: 0.5
}
}
};
return (
<ChartComponent id='charts' title='Chart Title' primaryXAxis={primaryXAxis} primaryYAxis={primaryYAxis} tooltip={tooltip} legendSettings={legendSettings}>
<Inject services={[StackingColumnSeries, Legend, Category, Tooltip, DataLabel]} />
<SeriesCollectionDirective>
<SeriesDirective dataSource={dataA} xName='x' yName='y' type='StackingColumn' name='Category A' fill='#254061' columnWidth={0.6} marker={marker}></SeriesDirective>
<SeriesDirective dataSource={dataB} xName='x' yName='y' type='StackingColumn' name='Category B' fill='#376092' columnWidth={0.6} marker={marker}></SeriesDirective>
<SeriesDirective dataSource={dataC} xName='x' yName='y' type='StackingColumn' name='Category C' fill='#4f81bd' columnWidth={0.6} marker={marker}></SeriesDirective>
<SeriesDirective dataSource={dataD} xName='x' yName='y' type='StackingColumn' name='Category D' fill='CornflowerBlue' columnWidth={0.6} marker={marker}></SeriesDirective>
<SeriesDirective dataSource={dataE} xName='x' yName='y' type='StackingColumn' name='Category E' fill='LightBlue' columnWidth={0.6} marker={marker}></SeriesDirective>
<SeriesDirective dataSource={dataF} xName='x' yName='y' type='StackingColumn' name='Category F' fill='LightSteelBlue' columnWidth={0.6} marker={marker}></SeriesDirective>
<SeriesDirective dataSource={dataG} xName='x' yName='y' type='StackingColumn' name='Category G' fill='Moccasin' columnWidth={0.6} marker={marker}></SeriesDirective>
<SeriesDirective dataSource={dataH} xName='x' yName='y' type='StackingColumn' name='Category H' fill='LightGrey' columnWidth={0.6} 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 { AxisModel, ChartComponent, SeriesCollectionDirective, SeriesDirective, Inject, Legend, Category, Tooltip, DataLabel, StackingColumnSeries } from '@syncfusion/ej2-react-charts';
import { dataA, dataB, dataC, dataD, dataE, dataF, dataG, dataH } from './datasource';
function App() {
const primaryXAxis: AxisModel = {
valueType: 'Category'
};
const primaryYAxis: AxisModel = {
visible: false
};
const tooltip: Object = {
enable: true
};
const legendSettings: Object = {
visible: true
};
const marker: Object = {
dataLabel: {
visible: true,
name: 'text',
fill: 'Transparent',
labelIntersectAction: 'RelocateVertically',
smartLabelSettings: {
background: '#4f4f4f',
border: {
color: 'black',
dashArray: '2',
width: 2
},
connectorLineStyle: {
color: 'black',
width: 2
},
pointerShape: 'Arrow',
offset: 0.5
}
}
};
return (
<ChartComponent id='charts' title='Chart Title' primaryXAxis={primaryXAxis} primaryYAxis={primaryYAxis} tooltip={tooltip} legendSettings={legendSettings}>
<Inject services={[StackingColumnSeries, Legend, Category, Tooltip, DataLabel]} />
<SeriesCollectionDirective>
<SeriesDirective dataSource={dataA} xName='x' yName='y' type='StackingColumn' name='Category A' fill='#254061' columnWidth={0.6} marker={marker}></SeriesDirective>
<SeriesDirective dataSource={dataB} xName='x' yName='y' type='StackingColumn' name='Category B' fill='#376092' columnWidth={0.6} marker={marker}></SeriesDirective>
<SeriesDirective dataSource={dataC} xName='x' yName='y' type='StackingColumn' name='Category C' fill='#4f81bd' columnWidth={0.6} marker={marker}></SeriesDirective>
<SeriesDirective dataSource={dataD} xName='x' yName='y' type='StackingColumn' name='Category D' fill='CornflowerBlue' columnWidth={0.6} marker={marker}></SeriesDirective>
<SeriesDirective dataSource={dataE} xName='x' yName='y' type='StackingColumn' name='Category E' fill='LightBlue' columnWidth={0.6} marker={marker}></SeriesDirective>
<SeriesDirective dataSource={dataF} xName='x' yName='y' type='StackingColumn' name='Category F' fill='LightSteelBlue' columnWidth={0.6} marker={marker}></SeriesDirective>
<SeriesDirective dataSource={dataG} xName='x' yName='y' type='StackingColumn' name='Category G' fill='Moccasin' columnWidth={0.6} marker={marker}></SeriesDirective>
<SeriesDirective dataSource={dataH} xName='x' yName='y' type='StackingColumn' name='Category H' fill='LightGrey' columnWidth={0.6} marker={marker}></SeriesDirective>
</SeriesCollectionDirective>
</ChartComponent>
);
}
export default App;
ReactDOM.render(<App />, document.getElementById('charts'));export const dataA = [
{ x: 'Period 1', y: 35, text: '35%' },
{ x: 'Period 2', y: 30, text: '30%' },
{ x: 'Period 3', y: 32, text: '32%' }
];
export const dataB = [
{ x: 'Period 1', y: 22, text: '22%' },
{ x: 'Period 2', y: 25, text: '25%' },
{ x: 'Period 3', y: 24, text: '24%' }
];
export const dataC = [
{ x: 'Period 1', y: 14, text: '14%' },
{ x: 'Period 2', y: 16, text: '16%' },
{ x: 'Period 3', y: 15, text: '15%' }
];
export const dataD = [
{ x: 'Period 1', y: 10, text: '10%' },
{ x: 'Period 2', y: 11, text: '11%' },
{ x: 'Period 3', y: 12, text: '12%' }
];
export const dataE = [
{ x: 'Period 1', y: 7, text: '7%' },
{ x: 'Period 2', y: 8, text: '8%' },
{ x: 'Period 3', y: 6, text: '6%' }
];
export const dataF = [
{ x: 'Period 1', y: 5, text: '5%' },
{ x: 'Period 2', y: 5, text: '5%' },
{ x: 'Period 3', y: 5, text: '5%' }
];
export const dataG = [
{ x: 'Period 1', y: 4, text: '4%' },
{ x: 'Period 2', y: 3, text: '3%' },
{ x: 'Period 3', y: 4, text: '4%' }
];
export const dataH = [
{ x: 'Period 1', y: 3, text: '3%' },
{ x: 'Period 2', y: 2, text: '2%' },
{ x: 'Period 3', y: 2, text: '2%' }
];export interface ChartData {
x: string;
y: number;
text: string;
}
export const dataA: ChartData[] = [
{ x: 'Period 1', y: 35, text: '35%' },
{ x: 'Period 2', y: 30, text: '30%' },
{ x: 'Period 3', y: 32, text: '32%' }
];
export const dataB: ChartData[] = [
{ x: 'Period 1', y: 22, text: '22%' },
{ x: 'Period 2', y: 25, text: '25%' },
{ x: 'Period 3', y: 24, text: '24%' }
];
export const dataC: ChartData[] = [
{ x: 'Period 1', y: 14, text: '14%' },
{ x: 'Period 2', y: 16, text: '16%' },
{ x: 'Period 3', y: 15, text: '15%' }
];
export const dataD: ChartData[] = [
{ x: 'Period 1', y: 10, text: '10%' },
{ x: 'Period 2', y: 11, text: '11%' },
{ x: 'Period 3', y: 12, text: '12%' }
];
export const dataE: ChartData[] = [
{ x: 'Period 1', y: 7, text: '7%' },
{ x: 'Period 2', y: 8, text: '8%' },
{ x: 'Period 3', y: 6, text: '6%' }
];
export const dataF: ChartData[] = [
{ x: 'Period 1', y: 5, text: '5%' },
{ x: 'Period 2', y: 5, text: '5%' },
{ x: 'Period 3', y: 5, text: '5%' }
];
export const dataG: ChartData[] = [
{ x: 'Period 1', y: 4, text: '4%' },
{ x: 'Period 2', y: 3, text: '3%' },
{ x: 'Period 3', y: 4, text: '4%' }
];
export const dataH: ChartData[] = [
{ x: 'Period 1', y: 3, text: '3%' },
{ x: 'Period 2', y: 2, text: '2%' },
{ x: 'Period 3', y: 2, text: '2%' }
];Smart Label
Smart Label places data labels of Cartesian series so that they do not overlap each other, the markers, or the plot area boundary. Enable it by setting the enableSmartLabels property to true. The default value is false.
How it works:
- Positioning: A label stays at its default position when that position is free. Otherwise, the label is checked around its point at the top, right, bottom, and left positions, and then at the diagonal positions. The first position that is inside the plot area of its series and does not overlap any other label or marker is used. For example, if the top and right positions collide with other labels, the label is placed at the bottom when there is enough space. If no free position is found, the label is hidden.
- Label and marker detection: A label is checked against the other data labels and the visible markers of all series.
- Connector line: A relocated label that is more than 12 px away from its point is joined to the point with a connector line and an arrow pointer.
import * as React from 'react';
import * as ReactDOM from 'react-dom';
import { ChartComponent, SeriesCollectionDirective, SeriesDirective, Inject, Legend, DataLabel, LineSeries, Double } from '@syncfusion/ej2-react-charts';
import { vietnam, indonesia, france, poland, mexico } from './datasource';
function App() {
const primaryXAxis = {
valueType: 'Double',
majorGridLines: { width: 0 },
edgeLabelPlacement: 'Shift'
};
const primaryYAxis = {
title: 'Volume in million metric tons',
labelFormat: '{value}',
lineStyle: { width: 0 },
majorTickLines: { width: 0 },
minorTickLines: { width: 0 }
};
const animation = { enable: false };
const vietnamMarker = {
visible: true,
width: 7,
height: 7,
shape: 'Circle',
isFilled: true,
dataLabel: { visible: true }
};
const indonesiaMarker = {
visible: true,
width: 6,
height: 6,
shape: 'Triangle',
isFilled: true,
dataLabel: { visible: true }
};
const franceMarker = {
visible: true,
width: 7,
height: 7,
shape: 'Diamond',
isFilled: true,
dataLabel: { visible: true }
};
const polandMarker = {
visible: true,
width: 5,
height: 5,
shape: 'Rectangle',
isFilled: true,
dataLabel: { visible: true }
};
const mexicoMarker = {
visible: true,
width: 7,
height: 7,
shape: 'Pentagon',
isFilled: true,
dataLabel: { visible: true }
};
return (
<ChartComponent id='charts' primaryXAxis={primaryXAxis} primaryYAxis={primaryYAxis} enableSmartLabels={true}
title='Annual Crude Steel Production by Country (2016–2024)' subTitle='Source: wikipedia.org'>
<Inject services={[LineSeries, Double, DataLabel, Legend]} />
<SeriesCollectionDirective>
<SeriesDirective dataSource={vietnam} xName='x' yName='y' name='Vietnam' width={2} animation={animation} marker={vietnamMarker} type='Line'></SeriesDirective>
<SeriesDirective dataSource={indonesia} xName='x' yName='y' name='Indonesia' width={2} animation={animation} marker={indonesiaMarker} type='Line'></SeriesDirective>
<SeriesDirective dataSource={france} xName='x' yName='y' name='France' width={2} animation={animation} marker={franceMarker} type='Line'></SeriesDirective>
<SeriesDirective dataSource={poland} xName='x' yName='y' name='Poland' width={2} animation={animation} marker={polandMarker} type='Line'></SeriesDirective>
<SeriesDirective dataSource={mexico} xName='x' yName='y' name='Mexico' width={2} animation={animation} marker={mexicoMarker} type='Line'></SeriesDirective>
</SeriesCollectionDirective>
</ChartComponent>
);
};
export default App;
ReactDOM.render(<App />, document.getElementById('charts'));import * as React from 'react';
import * as ReactDOM from 'react-dom';
import { AxisModel, ChartComponent, SeriesCollectionDirective, SeriesDirective, Inject, Legend, DataLabel, LineSeries, Double } from '@syncfusion/ej2-react-charts';
import { vietnam, indonesia, france, poland, mexico } from './datasource';
function App() {
const primaryXAxis: AxisModel = {
valueType: 'Double',
majorGridLines: { width: 0 },
edgeLabelPlacement: 'Shift'
};
const primaryYAxis: AxisModel = {
title: 'Volume in million metric tons',
labelFormat: '{value}',
lineStyle: { width: 0 },
majorTickLines: { width: 0 },
minorTickLines: { width: 0 }
};
const animation: Object = { enable: false };
const vietnamMarker: Object = {
visible: true,
width: 7,
height: 7,
shape: 'Circle',
isFilled: true,
dataLabel: { visible: true }
};
const indonesiaMarker: Object = {
visible: true,
width: 6,
height: 6,
shape: 'Triangle',
isFilled: true,
dataLabel: { visible: true }
};
const franceMarker: Object = {
visible: true,
width: 7,
height: 7,
shape: 'Diamond',
isFilled: true,
dataLabel: { visible: true }
};
const polandMarker: Object = {
visible: true,
width: 5,
height: 5,
shape: 'Rectangle',
isFilled: true,
dataLabel: { visible: true }
};
const mexicoMarker: Object = {
visible: true,
width: 7,
height: 7,
shape: 'Pentagon',
isFilled: true,
dataLabel: { visible: true }
};
return (
<ChartComponent id='charts' primaryXAxis={primaryXAxis} primaryYAxis={primaryYAxis} enableSmartLabels={true}
title='Annual Crude Steel Production by Country (2016–2024)' subTitle='Source: wikipedia.org'>
<Inject services={[LineSeries, Double, DataLabel, Legend]} />
<SeriesCollectionDirective>
<SeriesDirective dataSource={vietnam} xName='x' yName='y' name='Vietnam' width={2} animation={animation} marker={vietnamMarker} type='Line'></SeriesDirective>
<SeriesDirective dataSource={indonesia} xName='x' yName='y' name='Indonesia' width={2} animation={animation} marker={indonesiaMarker} type='Line'></SeriesDirective>
<SeriesDirective dataSource={france} xName='x' yName='y' name='France' width={2} animation={animation} marker={franceMarker} type='Line'></SeriesDirective>
<SeriesDirective dataSource={poland} xName='x' yName='y' name='Poland' width={2} animation={animation} marker={polandMarker} type='Line'></SeriesDirective>
<SeriesDirective dataSource={mexico} xName='x' yName='y' name='Mexico' width={2} animation={animation} marker={mexicoMarker} type='Line'></SeriesDirective>
</SeriesCollectionDirective>
</ChartComponent>
);
};
export default App;
ReactDOM.render(<App />, document.getElementById('charts'));export const vietnam = [
{ x: 2016, y: 7.8 },
{ x: 2017, y: 10.3 },
{ x: 2018, y: 15.5 },
{ x: 2019, y: 17.5 },
{ x: 2020, y: 19.5 },
{ x: 2021, y: 23.0 },
{ x: 2022, y: 20.0 },
{ x: 2023, y: 19.0 },
{ x: 2024, y: 22.1 }
];
export const indonesia = [
{ x: 2016, y: 4.8 },
{ x: 2017, y: 5.2 },
{ x: 2018, y: 6.2 },
{ x: 2019, y: 7.8 },
{ x: 2020, y: 9.3 },
{ x: 2021, y: 14.3 },
{ x: 2022, y: 15.6 },
{ x: 2023, y: 16.0 },
{ x: 2024, y: 17.0 }
];
export const france = [
{ x: 2016, y: 14.6 },
{ x: 2017, y: 15.5 },
{ x: 2018, y: 15.4 },
{ x: 2019, y: 14.4 },
{ x: 2020, y: 11.6 },
{ x: 2021, y: 13.9 },
{ x: 2022, y: 12.1 },
{ x: 2023, y: 10.0 },
{ x: 2024, y: 10.8 }
];
export const poland = [
{ x: 2016, y: 8.9 },
{ x: 2017, y: 10.3 },
{ x: 2018, y: 10.8 },
{ x: 2019, y: 9.0 },
{ x: 2020, y: 7.9 },
{ x: 2021, y: 8.5 },
{ x: 2022, y: 7.4 },
{ x: 2023, y: 6.4 },
{ x: 2024, y: 7.1 }
];
export const mexico = [
{ x: 2016, y: 19.0 },
{ x: 2017, y: 20.0 },
{ x: 2018, y: 20.2 },
{ x: 2019, y: 18.4 },
{ x: 2020, y: 16.8 },
{ x: 2021, y: 18.5 },
{ x: 2022, y: 18.4 },
{ x: 2023, y: 16.3 },
{ x: 2024, y: 13.7 }
];export interface ChartData {
x: number;
y: number;
}
export const vietnam: ChartData[] = [
{ x: 2016, y: 7.8 },
{ x: 2017, y: 10.3 },
{ x: 2018, y: 15.5 },
{ x: 2019, y: 17.5 },
{ x: 2020, y: 19.5 },
{ x: 2021, y: 23.0 },
{ x: 2022, y: 20.0 },
{ x: 2023, y: 19.0 },
{ x: 2024, y: 22.1 }
];
export const indonesia: ChartData[] = [
{ x: 2016, y: 4.8 },
{ x: 2017, y: 5.2 },
{ x: 2018, y: 6.2 },
{ x: 2019, y: 7.8 },
{ x: 2020, y: 9.3 },
{ x: 2021, y: 14.3 },
{ x: 2022, y: 15.6 },
{ x: 2023, y: 16.0 },
{ x: 2024, y: 17.0 }
];
export const france: ChartData[] = [
{ x: 2016, y: 14.6 },
{ x: 2017, y: 15.5 },
{ x: 2018, y: 15.4 },
{ x: 2019, y: 14.4 },
{ x: 2020, y: 11.6 },
{ x: 2021, y: 13.9 },
{ x: 2022, y: 12.1 },
{ x: 2023, y: 10.0 },
{ x: 2024, y: 10.8 }
];
export const poland: ChartData[] = [
{ x: 2016, y: 8.9 },
{ x: 2017, y: 10.3 },
{ x: 2018, y: 10.8 },
{ x: 2019, y: 9.0 },
{ x: 2020, y: 7.9 },
{ x: 2021, y: 8.5 },
{ x: 2022, y: 7.4 },
{ x: 2023, y: 6.4 },
{ x: 2024, y: 7.1 }
];
export const mexico: ChartData[] = [
{ x: 2016, y: 19.0 },
{ x: 2017, y: 20.0 },
{ x: 2018, y: 20.2 },
{ x: 2019, y: 18.4 },
{ x: 2020, y: 16.8 },
{ x: 2021, y: 18.5 },
{ x: 2022, y: 18.4 },
{ x: 2023, y: 16.3 },
{ x: 2024, y: 13.7 }
];Note: When Smart Label is enabled,
labelIntersectActionis ignored, and the data labelpositiondecides only the default position. Stacked column and bar series continue to use theRelocateVerticallyandRelocateHorizontallyoptions.
Duplicate data labels
Use the showDuplicateLabels property of the chart to control labels that have the same text at the same location, such as labels of multiple series with identical values.
-
true(default) - Renders all the labels. -
false- Renders only the first label and skips the others. The first label is decided by the series order and then the point order.
This property works with or without enableSmartLabels.
import * as React from 'react';
import * as ReactDOM from 'react-dom';
import { ChartComponent, SeriesCollectionDirective, SeriesDirective, Inject, Legend, DataLabel, LineSeries, Double } from '@syncfusion/ej2-react-charts';
import { vietnam, indonesia, france, poland, mexico } from './datasource';
function App() {
const primaryXAxis = {
valueType: 'Double',
majorGridLines: { width: 0 },
edgeLabelPlacement: 'Shift'
};
const primaryYAxis = {
title: 'Volume in million metric tons',
labelFormat: '{value}',
lineStyle: { width: 0 },
majorTickLines: { width: 0 },
minorTickLines: { width: 0 }
};
const animation = { enable: false };
const vietnamMarker = {
visible: true,
width: 7,
height: 7,
shape: 'Circle',
isFilled: true,
dataLabel: { visible: true }
};
const indonesiaMarker = {
visible: true,
width: 6,
height: 6,
shape: 'Triangle',
isFilled: true,
dataLabel: { visible: true }
};
const franceMarker = {
visible: true,
width: 7,
height: 7,
shape: 'Diamond',
isFilled: true,
dataLabel: { visible: true }
};
const polandMarker = {
visible: true,
width: 5,
height: 5,
shape: 'Rectangle',
isFilled: true,
dataLabel: { visible: true }
};
const mexicoMarker = {
visible: true,
width: 7,
height: 7,
shape: 'Pentagon',
isFilled: true,
dataLabel: { visible: true }
};
return (
<ChartComponent id='charts' primaryXAxis={primaryXAxis} primaryYAxis={primaryYAxis} enableSmartLabels={true} showDuplicateLabels={false}
title='Annual Crude Steel Production by Country (2016–2024)' subTitle='Source: wikipedia.org'>
<Inject services={[LineSeries, Double, DataLabel, Legend]} />
<SeriesCollectionDirective>
<SeriesDirective dataSource={vietnam} xName='x' yName='y' name='Vietnam' width={2} animation={animation} marker={vietnamMarker} type='Line'></SeriesDirective>
<SeriesDirective dataSource={indonesia} xName='x' yName='y' name='Indonesia' width={2} animation={animation} marker={indonesiaMarker} type='Line'></SeriesDirective>
<SeriesDirective dataSource={france} xName='x' yName='y' name='France' width={2} animation={animation} marker={franceMarker} type='Line'></SeriesDirective>
<SeriesDirective dataSource={poland} xName='x' yName='y' name='Poland' width={2} animation={animation} marker={polandMarker} type='Line'></SeriesDirective>
<SeriesDirective dataSource={mexico} xName='x' yName='y' name='Mexico' width={2} animation={animation} marker={mexicoMarker} type='Line'></SeriesDirective>
</SeriesCollectionDirective>
</ChartComponent>
);
};
export default App;
ReactDOM.render(<App />, document.getElementById('charts'));import * as React from 'react';
import * as ReactDOM from 'react-dom';
import { AxisModel, ChartComponent, SeriesCollectionDirective, SeriesDirective, Inject, Legend, DataLabel, LineSeries, Double } from '@syncfusion/ej2-react-charts';
import { vietnam, indonesia, france, poland, mexico } from './datasource';
function App() {
const primaryXAxis: AxisModel = {
valueType: 'Double',
majorGridLines: { width: 0 },
edgeLabelPlacement: 'Shift'
};
const primaryYAxis: AxisModel = {
title: 'Volume in million metric tons',
labelFormat: '{value}',
lineStyle: { width: 0 },
majorTickLines: { width: 0 },
minorTickLines: { width: 0 }
};
const animation: Object = { enable: false };
const vietnamMarker: Object = {
visible: true,
width: 7,
height: 7,
shape: 'Circle',
isFilled: true,
dataLabel: { visible: true }
};
const indonesiaMarker: Object = {
visible: true,
width: 6,
height: 6,
shape: 'Triangle',
isFilled: true,
dataLabel: { visible: true }
};
const franceMarker: Object = {
visible: true,
width: 7,
height: 7,
shape: 'Diamond',
isFilled: true,
dataLabel: { visible: true }
};
const polandMarker: Object = {
visible: true,
width: 5,
height: 5,
shape: 'Rectangle',
isFilled: true,
dataLabel: { visible: true }
};
const mexicoMarker: Object = {
visible: true,
width: 7,
height: 7,
shape: 'Pentagon',
isFilled: true,
dataLabel: { visible: true }
};
return (
<ChartComponent id='charts' primaryXAxis={primaryXAxis} primaryYAxis={primaryYAxis} enableSmartLabels={true} showDuplicateLabels={false}
title='Annual Crude Steel Production by Country (2016–2024)' subTitle='Source: wikipedia.org'>
<Inject services={[LineSeries, Double, DataLabel, Legend]} />
<SeriesCollectionDirective>
<SeriesDirective dataSource={vietnam} xName='x' yName='y' name='Vietnam' width={2} animation={animation} marker={vietnamMarker} type='Line'></SeriesDirective>
<SeriesDirective dataSource={indonesia} xName='x' yName='y' name='Indonesia' width={2} animation={animation} marker={indonesiaMarker} type='Line'></SeriesDirective>
<SeriesDirective dataSource={france} xName='x' yName='y' name='France' width={2} animation={animation} marker={franceMarker} type='Line'></SeriesDirective>
<SeriesDirective dataSource={poland} xName='x' yName='y' name='Poland' width={2} animation={animation} marker={polandMarker} type='Line'></SeriesDirective>
<SeriesDirective dataSource={mexico} xName='x' yName='y' name='Mexico' width={2} animation={animation} marker={mexicoMarker} type='Line'></SeriesDirective>
</SeriesCollectionDirective>
</ChartComponent>
);
};
export default App;
ReactDOM.render(<App />, document.getElementById('charts'));export const vietnam = [
{ x: 2016, y: 7.8 },
{ x: 2017, y: 10.3 },
{ x: 2018, y: 15.5 },
{ x: 2019, y: 17.5 },
{ x: 2020, y: 19.5 },
{ x: 2021, y: 23.0 },
{ x: 2022, y: 20.0 },
{ x: 2023, y: 19.0 },
{ x: 2024, y: 22.1 }
];
export const indonesia = [
{ x: 2016, y: 4.8 },
{ x: 2017, y: 5.2 },
{ x: 2018, y: 6.2 },
{ x: 2019, y: 7.8 },
{ x: 2020, y: 9.3 },
{ x: 2021, y: 14.3 },
{ x: 2022, y: 15.6 },
{ x: 2023, y: 16.0 },
{ x: 2024, y: 17.0 }
];
export const france = [
{ x: 2016, y: 14.6 },
{ x: 2017, y: 15.5 },
{ x: 2018, y: 15.4 },
{ x: 2019, y: 14.4 },
{ x: 2020, y: 11.6 },
{ x: 2021, y: 13.9 },
{ x: 2022, y: 12.1 },
{ x: 2023, y: 10.0 },
{ x: 2024, y: 10.8 }
];
export const poland = [
{ x: 2016, y: 8.9 },
{ x: 2017, y: 10.3 },
{ x: 2018, y: 10.8 },
{ x: 2019, y: 9.0 },
{ x: 2020, y: 7.9 },
{ x: 2021, y: 8.5 },
{ x: 2022, y: 7.4 },
{ x: 2023, y: 6.4 },
{ x: 2024, y: 7.1 }
];
export const mexico = [
{ x: 2016, y: 19.0 },
{ x: 2017, y: 20.0 },
{ x: 2018, y: 20.2 },
{ x: 2019, y: 18.4 },
{ x: 2020, y: 16.8 },
{ x: 2021, y: 18.5 },
{ x: 2022, y: 18.4 },
{ x: 2023, y: 16.3 },
{ x: 2024, y: 13.7 }
];export interface ChartData {
x: number;
y: number;
}
export const vietnam: ChartData[] = [
{ x: 2016, y: 7.8 },
{ x: 2017, y: 10.3 },
{ x: 2018, y: 15.5 },
{ x: 2019, y: 17.5 },
{ x: 2020, y: 19.5 },
{ x: 2021, y: 23.0 },
{ x: 2022, y: 20.0 },
{ x: 2023, y: 19.0 },
{ x: 2024, y: 22.1 }
];
export const indonesia: ChartData[] = [
{ x: 2016, y: 4.8 },
{ x: 2017, y: 5.2 },
{ x: 2018, y: 6.2 },
{ x: 2019, y: 7.8 },
{ x: 2020, y: 9.3 },
{ x: 2021, y: 14.3 },
{ x: 2022, y: 15.6 },
{ x: 2023, y: 16.0 },
{ x: 2024, y: 17.0 }
];
export const france: ChartData[] = [
{ x: 2016, y: 14.6 },
{ x: 2017, y: 15.5 },
{ x: 2018, y: 15.4 },
{ x: 2019, y: 14.4 },
{ x: 2020, y: 11.6 },
{ x: 2021, y: 13.9 },
{ x: 2022, y: 12.1 },
{ x: 2023, y: 10.0 },
{ x: 2024, y: 10.8 }
];
export const poland: ChartData[] = [
{ x: 2016, y: 8.9 },
{ x: 2017, y: 10.3 },
{ x: 2018, y: 10.8 },
{ x: 2019, y: 9.0 },
{ x: 2020, y: 7.9 },
{ x: 2021, y: 8.5 },
{ x: 2022, y: 7.4 },
{ x: 2023, y: 6.4 },
{ x: 2024, y: 7.1 }
];
export const mexico: ChartData[] = [
{ x: 2016, y: 19.0 },
{ x: 2017, y: 20.0 },
{ x: 2018, y: 20.2 },
{ x: 2019, y: 18.4 },
{ x: 2020, y: 16.8 },
{ x: 2021, y: 18.5 },
{ x: 2022, y: 18.4 },
{ x: 2023, y: 16.3 },
{ x: 2024, y: 13.7 }
];Customization
Use the smartLabelSettings property in the series dataLabel to customize relocated labels and their connector lines. Labels at their default position keep the dataLabel settings.
-
background- Sets the background color of the relocated label. -
border- Sets thecolor,width, anddashArrayof the relocated label border. -
pointerShape- Sets the pointer at the point end of the connector line. The options areArrow(default) andNone. -
connectorLineStyle- Sets thecolor,width, andopacityof the connector line and pointer. Setwidthto0orcolortotransparentto hide the line. -
seriesOverlapAction- Specifies whether labels avoid series elements. See Series overlap action.
Note: The
offsetproperty is not applicable when Smart Label is enabled, because Smart Label automatically determines the final label position to avoid overlaps.
import * as React from 'react';
import * as ReactDOM from 'react-dom';
import { ChartComponent, SeriesCollectionDirective, SeriesDirective, Inject, Legend, DataLabel, LineSeries, Double } from '@syncfusion/ej2-react-charts';
import { vietnam, indonesia, france, poland, mexico } from './datasource';
function App() {
const primaryXAxis = {
valueType: 'Double',
majorGridLines: { width: 0 },
edgeLabelPlacement: 'Shift'
};
const primaryYAxis = {
title: 'Volume in million metric tons',
labelFormat: '{value}',
lineStyle: { width: 0 },
majorTickLines: { width: 0 },
minorTickLines: { width: 0 }
};
const animation = { enable: false };
const vietnamMarker = {
visible: true,
width: 7,
height: 7,
shape: 'Circle',
isFilled: true,
dataLabel: {
visible: true,
smartLabelSettings: {
background: '#e0e0e0',
border: { color: '#404040', width: 1 },
pointerShape: 'Arrow',
connectorLineStyle: { color: '#404040', width: 1.5 }
}
}
};
const indonesiaMarker = {
visible: true,
width: 6,
height: 6,
shape: 'Triangle',
isFilled: true,
dataLabel: { visible: true }
};
const franceMarker = {
visible: true,
width: 7,
height: 7,
shape: 'Diamond',
isFilled: true,
dataLabel: { visible: true }
};
const polandMarker = {
visible: true,
width: 5,
height: 5,
shape: 'Rectangle',
isFilled: true,
dataLabel: { visible: true }
};
const mexicoMarker = {
visible: true,
width: 7,
height: 7,
shape: 'Pentagon',
isFilled: true,
dataLabel: { visible: true }
};
return (
<ChartComponent id='charts' primaryXAxis={primaryXAxis} primaryYAxis={primaryYAxis} enableSmartLabels={true}
title='Annual Crude Steel Production by Country (2016–2024)' subTitle='Source: wikipedia.org'>
<Inject services={[LineSeries, Double, DataLabel, Legend]} />
<SeriesCollectionDirective>
<SeriesDirective dataSource={vietnam} xName='x' yName='y' name='Vietnam' width={2} animation={animation} marker={vietnamMarker} type='Line'></SeriesDirective>
<SeriesDirective dataSource={indonesia} xName='x' yName='y' name='Indonesia' width={2} animation={animation} marker={indonesiaMarker} type='Line'></SeriesDirective>
<SeriesDirective dataSource={france} xName='x' yName='y' name='France' width={2} animation={animation} marker={franceMarker} type='Line'></SeriesDirective>
<SeriesDirective dataSource={poland} xName='x' yName='y' name='Poland' width={2} animation={animation} marker={polandMarker} type='Line'></SeriesDirective>
<SeriesDirective dataSource={mexico} xName='x' yName='y' name='Mexico' width={2} animation={animation} marker={mexicoMarker} type='Line'></SeriesDirective>
</SeriesCollectionDirective>
</ChartComponent>
);
};
export default App;
ReactDOM.render(<App />, document.getElementById('charts'));import * as React from 'react';
import * as ReactDOM from 'react-dom';
import { AxisModel, ChartComponent, SeriesCollectionDirective, SeriesDirective, Inject, Legend, DataLabel, LineSeries, Double } from '@syncfusion/ej2-react-charts';
import { vietnam, indonesia, france, poland, mexico } from './datasource';
function App() {
const primaryXAxis: AxisModel = {
valueType: 'Double',
majorGridLines: { width: 0 },
edgeLabelPlacement: 'Shift'
};
const primaryYAxis: AxisModel = {
title: 'Volume in million metric tons',
labelFormat: '{value}',
lineStyle: { width: 0 },
majorTickLines: { width: 0 },
minorTickLines: { width: 0 }
};
const animation: Object = { enable: false };
const vietnamMarker: Object = {
visible: true,
width: 7,
height: 7,
shape: 'Circle',
isFilled: true,
dataLabel: {
visible: true,
smartLabelSettings: {
background: '#e0e0e0',
border: { color: '#404040', width: 1 },
pointerShape: 'Arrow',
connectorLineStyle: { color: '#404040', width: 1.5 }
}
}
};
const indonesiaMarker: Object = {
visible: true,
width: 6,
height: 6,
shape: 'Triangle',
isFilled: true,
dataLabel: { visible: true }
};
const franceMarker: Object = {
visible: true,
width: 7,
height: 7,
shape: 'Diamond',
isFilled: true,
dataLabel: { visible: true }
};
const polandMarker: Object = {
visible: true,
width: 5,
height: 5,
shape: 'Rectangle',
isFilled: true,
dataLabel: { visible: true }
};
const mexicoMarker: Object = {
visible: true,
width: 7,
height: 7,
shape: 'Pentagon',
isFilled: true,
dataLabel: { visible: true }
};
return (
<ChartComponent id='charts' primaryXAxis={primaryXAxis} primaryYAxis={primaryYAxis} enableSmartLabels={true}
title='Annual Crude Steel Production by Country (2016–2024)' subTitle='Source: wikipedia.org'>
<Inject services={[LineSeries, Double, DataLabel, Legend]} />
<SeriesCollectionDirective>
<SeriesDirective dataSource={vietnam} xName='x' yName='y' name='Vietnam' width={2} animation={animation} marker={vietnamMarker} type='Line'></SeriesDirective>
<SeriesDirective dataSource={indonesia} xName='x' yName='y' name='Indonesia' width={2} animation={animation} marker={indonesiaMarker} type='Line'></SeriesDirective>
<SeriesDirective dataSource={france} xName='x' yName='y' name='France' width={2} animation={animation} marker={franceMarker} type='Line'></SeriesDirective>
<SeriesDirective dataSource={poland} xName='x' yName='y' name='Poland' width={2} animation={animation} marker={polandMarker} type='Line'></SeriesDirective>
<SeriesDirective dataSource={mexico} xName='x' yName='y' name='Mexico' width={2} animation={animation} marker={mexicoMarker} type='Line'></SeriesDirective>
</SeriesCollectionDirective>
</ChartComponent>
);
};
export default App;
ReactDOM.render(<App />, document.getElementById('charts'));export const vietnam = [
{ x: 2016, y: 7.8 },
{ x: 2017, y: 10.3 },
{ x: 2018, y: 15.5 },
{ x: 2019, y: 17.5 },
{ x: 2020, y: 19.5 },
{ x: 2021, y: 23.0 },
{ x: 2022, y: 20.0 },
{ x: 2023, y: 19.0 },
{ x: 2024, y: 22.1 }
];
export const indonesia = [
{ x: 2016, y: 4.8 },
{ x: 2017, y: 5.2 },
{ x: 2018, y: 6.2 },
{ x: 2019, y: 7.8 },
{ x: 2020, y: 9.3 },
{ x: 2021, y: 14.3 },
{ x: 2022, y: 15.6 },
{ x: 2023, y: 16.0 },
{ x: 2024, y: 17.0 }
];
export const france = [
{ x: 2016, y: 14.6 },
{ x: 2017, y: 15.5 },
{ x: 2018, y: 15.4 },
{ x: 2019, y: 14.4 },
{ x: 2020, y: 11.6 },
{ x: 2021, y: 13.9 },
{ x: 2022, y: 12.1 },
{ x: 2023, y: 10.0 },
{ x: 2024, y: 10.8 }
];
export const poland = [
{ x: 2016, y: 8.9 },
{ x: 2017, y: 10.3 },
{ x: 2018, y: 10.8 },
{ x: 2019, y: 9.0 },
{ x: 2020, y: 7.9 },
{ x: 2021, y: 8.5 },
{ x: 2022, y: 7.4 },
{ x: 2023, y: 6.4 },
{ x: 2024, y: 7.1 }
];
export const mexico = [
{ x: 2016, y: 19.0 },
{ x: 2017, y: 20.0 },
{ x: 2018, y: 20.2 },
{ x: 2019, y: 18.4 },
{ x: 2020, y: 16.8 },
{ x: 2021, y: 18.5 },
{ x: 2022, y: 18.4 },
{ x: 2023, y: 16.3 },
{ x: 2024, y: 13.7 }
];export interface ChartData {
x: number;
y: number;
}
export const vietnam: ChartData[] = [
{ x: 2016, y: 7.8 },
{ x: 2017, y: 10.3 },
{ x: 2018, y: 15.5 },
{ x: 2019, y: 17.5 },
{ x: 2020, y: 19.5 },
{ x: 2021, y: 23.0 },
{ x: 2022, y: 20.0 },
{ x: 2023, y: 19.0 },
{ x: 2024, y: 22.1 }
];
export const indonesia: ChartData[] = [
{ x: 2016, y: 4.8 },
{ x: 2017, y: 5.2 },
{ x: 2018, y: 6.2 },
{ x: 2019, y: 7.8 },
{ x: 2020, y: 9.3 },
{ x: 2021, y: 14.3 },
{ x: 2022, y: 15.6 },
{ x: 2023, y: 16.0 },
{ x: 2024, y: 17.0 }
];
export const france: ChartData[] = [
{ x: 2016, y: 14.6 },
{ x: 2017, y: 15.5 },
{ x: 2018, y: 15.4 },
{ x: 2019, y: 14.4 },
{ x: 2020, y: 11.6 },
{ x: 2021, y: 13.9 },
{ x: 2022, y: 12.1 },
{ x: 2023, y: 10.0 },
{ x: 2024, y: 10.8 }
];
export const poland: ChartData[] = [
{ x: 2016, y: 8.9 },
{ x: 2017, y: 10.3 },
{ x: 2018, y: 10.8 },
{ x: 2019, y: 9.0 },
{ x: 2020, y: 7.9 },
{ x: 2021, y: 8.5 },
{ x: 2022, y: 7.4 },
{ x: 2023, y: 6.4 },
{ x: 2024, y: 7.1 }
];
export const mexico: ChartData[] = [
{ x: 2016, y: 19.0 },
{ x: 2017, y: 20.0 },
{ x: 2018, y: 20.2 },
{ x: 2019, y: 18.4 },
{ x: 2020, y: 16.8 },
{ x: 2021, y: 18.5 },
{ x: 2022, y: 18.4 },
{ x: 2023, y: 16.3 },
{ x: 2024, y: 13.7 }
];Series overlap action
Use the seriesOverlapAction property in smartLabelSettings to specify whether labels can overlap the series elements, such as lines, areas, columns, bars, and trendlines.
-
None(default) - Labels avoid only other labels and markers, so they can be placed over series elements. -
Hide- Labels also avoid the elements of all visible series. A label moves to a free position if one exists, and is hidden only when none is available.
Note: In canvas rendering mode,
Hidebehaves likeNone.
import * as React from 'react';
import * as ReactDOM from 'react-dom';
import { ChartComponent, SeriesCollectionDirective, SeriesDirective, Inject, Legend, DataLabel, LineSeries, Double } from '@syncfusion/ej2-react-charts';
import { vietnam, indonesia, france, poland, mexico } from './datasource';
function App() {
const primaryXAxis = {
valueType: 'Double',
majorGridLines: { width: 0 },
edgeLabelPlacement: 'Shift'
};
const primaryYAxis = {
title: 'Volume in million metric tons',
labelFormat: '{value}',
lineStyle: { width: 0 },
majorTickLines: { width: 0 },
minorTickLines: { width: 0 }
};
const animation = { enable: false };
const vietnamMarker = {
visible: true,
width: 7,
height: 7,
shape: 'Circle',
isFilled: true,
dataLabel: {
visible: true,
smartLabelSettings: {
seriesOverlapAction: 'Hide'
}
}
};
const indonesiaMarker = {
visible: true,
width: 6,
height: 6,
shape: 'Triangle',
isFilled: true,
dataLabel: {
visible: true,
smartLabelSettings: {
seriesOverlapAction: 'Hide'
}
}
};
const franceMarker = {
visible: true,
width: 7,
height: 7,
shape: 'Diamond',
isFilled: true,
dataLabel: {
visible: true,
smartLabelSettings: {
seriesOverlapAction: 'Hide'
}
}
};
const polandMarker = {
visible: true,
width: 5,
height: 5,
shape: 'Rectangle',
isFilled: true,
dataLabel: {
visible: true,
smartLabelSettings: {
seriesOverlapAction: 'Hide'
}
}
};
const mexicoMarker = {
visible: true,
width: 7,
height: 7,
shape: 'Pentagon',
isFilled: true,
dataLabel: {
visible: true,
smartLabelSettings: {
seriesOverlapAction: 'Hide'
}
}
};
return (
<ChartComponent id='charts' primaryXAxis={primaryXAxis} primaryYAxis={primaryYAxis} enableSmartLabels={true}
title='Annual Crude Steel Production by Country (2016–2024)' subTitle='Source: wikipedia.org'>
<Inject services={[LineSeries, Double, DataLabel, Legend]} />
<SeriesCollectionDirective>
<SeriesDirective dataSource={vietnam} xName='x' yName='y' name='Vietnam' width={2} animation={animation} marker={vietnamMarker} type='Line'></SeriesDirective>
<SeriesDirective dataSource={indonesia} xName='x' yName='y' name='Indonesia' width={2} animation={animation} marker={indonesiaMarker} type='Line'></SeriesDirective>
<SeriesDirective dataSource={france} xName='x' yName='y' name='France' width={2} animation={animation} marker={franceMarker} type='Line'></SeriesDirective>
<SeriesDirective dataSource={poland} xName='x' yName='y' name='Poland' width={2} animation={animation} marker={polandMarker} type='Line'></SeriesDirective>
<SeriesDirective dataSource={mexico} xName='x' yName='y' name='Mexico' width={2} animation={animation} marker={mexicoMarker} type='Line'></SeriesDirective>
</SeriesCollectionDirective>
</ChartComponent>
);
};
export default App;
ReactDOM.render(<App />, document.getElementById('charts'));import * as React from 'react';
import * as ReactDOM from 'react-dom';
import { AxisModel, ChartComponent, SeriesCollectionDirective, SeriesDirective, Inject, Legend, DataLabel, LineSeries, Double } from '@syncfusion/ej2-react-charts';
import { vietnam, indonesia, france, poland, mexico } from './datasource';
function App() {
const primaryXAxis: AxisModel = {
valueType: 'Double',
majorGridLines: { width: 0 },
edgeLabelPlacement: 'Shift'
};
const primaryYAxis: AxisModel = {
title: 'Volume in million metric tons',
labelFormat: '{value}',
lineStyle: { width: 0 },
majorTickLines: { width: 0 },
minorTickLines: { width: 0 }
};
const animation: Object = { enable: false };
const vietnamMarker: Object = {
visible: true,
width: 7,
height: 7,
shape: 'Circle',
isFilled: true,
dataLabel: {
visible: true,
smartLabelSettings: {
seriesOverlapAction: 'Hide'
}
}
};
const indonesiaMarker: Object = {
visible: true,
width: 6,
height: 6,
shape: 'Triangle',
isFilled: true,
dataLabel: {
visible: true,
smartLabelSettings: {
seriesOverlapAction: 'Hide'
}
}
};
const franceMarker: Object = {
visible: true,
width: 7,
height: 7,
shape: 'Diamond',
isFilled: true,
dataLabel: {
visible: true,
smartLabelSettings: {
seriesOverlapAction: 'Hide'
}
}
};
const polandMarker: Object = {
visible: true,
width: 5,
height: 5,
shape: 'Rectangle',
isFilled: true,
dataLabel: {
visible: true,
smartLabelSettings: {
seriesOverlapAction: 'Hide'
}
}
};
const mexicoMarker: Object = {
visible: true,
width: 7,
height: 7,
shape: 'Pentagon',
isFilled: true,
dataLabel: {
visible: true,
smartLabelSettings: {
seriesOverlapAction: 'Hide'
}
}
};
return (
<ChartComponent id='charts' primaryXAxis={primaryXAxis} primaryYAxis={primaryYAxis} enableSmartLabels={true}
title='Annual Crude Steel Production by Country (2016–2024)' subTitle='Source: wikipedia.org'>
<Inject services={[LineSeries, Double, DataLabel, Legend]} />
<SeriesCollectionDirective>
<SeriesDirective dataSource={vietnam} xName='x' yName='y' name='Vietnam' width={2} animation={animation} marker={vietnamMarker} type='Line'></SeriesDirective>
<SeriesDirective dataSource={indonesia} xName='x' yName='y' name='Indonesia' width={2} animation={animation} marker={indonesiaMarker} type='Line'></SeriesDirective>
<SeriesDirective dataSource={france} xName='x' yName='y' name='France' width={2} animation={animation} marker={franceMarker} type='Line'></SeriesDirective>
<SeriesDirective dataSource={poland} xName='x' yName='y' name='Poland' width={2} animation={animation} marker={polandMarker} type='Line'></SeriesDirective>
<SeriesDirective dataSource={mexico} xName='x' yName='y' name='Mexico' width={2} animation={animation} marker={mexicoMarker} type='Line'></SeriesDirective>
</SeriesCollectionDirective>
</ChartComponent>
);
};
export default App;
ReactDOM.render(<App />, document.getElementById('charts'));export const vietnam = [
{ x: 2016, y: 7.8 },
{ x: 2017, y: 10.3 },
{ x: 2018, y: 15.5 },
{ x: 2019, y: 17.5 },
{ x: 2020, y: 19.5 },
{ x: 2021, y: 23.0 },
{ x: 2022, y: 20.0 },
{ x: 2023, y: 19.0 },
{ x: 2024, y: 22.1 }
];
export const indonesia = [
{ x: 2016, y: 4.8 },
{ x: 2017, y: 5.2 },
{ x: 2018, y: 6.2 },
{ x: 2019, y: 7.8 },
{ x: 2020, y: 9.3 },
{ x: 2021, y: 14.3 },
{ x: 2022, y: 15.6 },
{ x: 2023, y: 16.0 },
{ x: 2024, y: 17.0 }
];
export const france = [
{ x: 2016, y: 14.6 },
{ x: 2017, y: 15.5 },
{ x: 2018, y: 15.4 },
{ x: 2019, y: 14.4 },
{ x: 2020, y: 11.6 },
{ x: 2021, y: 13.9 },
{ x: 2022, y: 12.1 },
{ x: 2023, y: 10.0 },
{ x: 2024, y: 10.8 }
];
export const poland = [
{ x: 2016, y: 8.9 },
{ x: 2017, y: 10.3 },
{ x: 2018, y: 10.8 },
{ x: 2019, y: 9.0 },
{ x: 2020, y: 7.9 },
{ x: 2021, y: 8.5 },
{ x: 2022, y: 7.4 },
{ x: 2023, y: 6.4 },
{ x: 2024, y: 7.1 }
];
export const mexico = [
{ x: 2016, y: 19.0 },
{ x: 2017, y: 20.0 },
{ x: 2018, y: 20.2 },
{ x: 2019, y: 18.4 },
{ x: 2020, y: 16.8 },
{ x: 2021, y: 18.5 },
{ x: 2022, y: 18.4 },
{ x: 2023, y: 16.3 },
{ x: 2024, y: 13.7 }
];export interface ChartData {
x: number;
y: number;
}
export const vietnam: ChartData[] = [
{ x: 2016, y: 7.8 },
{ x: 2017, y: 10.3 },
{ x: 2018, y: 15.5 },
{ x: 2019, y: 17.5 },
{ x: 2020, y: 19.5 },
{ x: 2021, y: 23.0 },
{ x: 2022, y: 20.0 },
{ x: 2023, y: 19.0 },
{ x: 2024, y: 22.1 }
];
export const indonesia: ChartData[] = [
{ x: 2016, y: 4.8 },
{ x: 2017, y: 5.2 },
{ x: 2018, y: 6.2 },
{ x: 2019, y: 7.8 },
{ x: 2020, y: 9.3 },
{ x: 2021, y: 14.3 },
{ x: 2022, y: 15.6 },
{ x: 2023, y: 16.0 },
{ x: 2024, y: 17.0 }
];
export const france: ChartData[] = [
{ x: 2016, y: 14.6 },
{ x: 2017, y: 15.5 },
{ x: 2018, y: 15.4 },
{ x: 2019, y: 14.4 },
{ x: 2020, y: 11.6 },
{ x: 2021, y: 13.9 },
{ x: 2022, y: 12.1 },
{ x: 2023, y: 10.0 },
{ x: 2024, y: 10.8 }
];
export const poland: ChartData[] = [
{ x: 2016, y: 8.9 },
{ x: 2017, y: 10.3 },
{ x: 2018, y: 10.8 },
{ x: 2019, y: 9.0 },
{ x: 2020, y: 7.9 },
{ x: 2021, y: 8.5 },
{ x: 2022, y: 7.4 },
{ x: 2023, y: 6.4 },
{ x: 2024, y: 7.1 }
];
export const mexico: ChartData[] = [
{ x: 2016, y: 19.0 },
{ x: 2017, y: 20.0 },
{ x: 2018, y: 20.2 },
{ x: 2019, y: 18.4 },
{ x: 2020, y: 16.8 },
{ x: 2021, y: 18.5 },
{ x: 2022, y: 18.4 },
{ x: 2023, y: 16.3 },
{ x: 2024, y: 13.7 }
];Customizing specific point
Customize individual markers or labels using the pointRender and textRender events:
-
pointRendermodifies shape, color, or border of a point. -
textRendercustomizes the label text for specific points.
import * as React from "react";
import * as ReactDOM from "react-dom";
import { ChartComponent, SeriesCollectionDirective, SeriesDirective, Inject, Legend, Category, Tooltip, DataLabel, LineSeries } from '@syncfusion/ej2-react-charts';
import { data } from './datasource';
function App() {
const pointRender = (args) => {
if (args.point.index === 6) {
args.fill = 'red';
}
};
const primaryxAxis = { valueType: 'Category' };
const marker = { dataLabel: { visible: true, position: 'Middle' } };
return <ChartComponent id='charts' primaryXAxis={primaryxAxis} pointRender={pointRender} title='Alaska Weather Statistics - 2016'>
<Inject services={[LineSeries, Legend, Tooltip, DataLabel, Category]}/>
<SeriesCollectionDirective>
<SeriesDirective dataSource={data} xName='x' yName='y' type='Line' 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 { AxisModel, ChartComponent, SeriesCollectionDirective, SeriesDirective, Inject,
Legend, Category, Tooltip, DataLabel, LineSeries}
from'@syncfusion/ej2-react-charts';
import { data } from './datasource';
function App() {
const pointRender: EmitType<IPointRenderEventArgs> = (args: IPointRenderEventArgs): void => {
if (args.point.index === 6) {
args.fill = 'red'
}
};
const primaryxAxis: AxisModel = { valueType: 'Category' };
const marker = { dataLabel: { visible: true, position: 'Middle' } };
return <ChartComponent id='charts'
primaryXAxis={primaryxAxis}
pointRender={pointRender}
title='Alaska Weather Statistics - 2016'>
<Inject services={[LineSeries, Legend, Tooltip, DataLabel, Category]} />
<SeriesCollectionDirective>
<SeriesDirective dataSource={data} xName='x' yName='y'
type='Line' marker={marker}>
</SeriesDirective>
</SeriesCollectionDirective>
</ChartComponent>
};
export default App;
ReactDOM.render(<App />, document.getElementById("charts"));export let data = [
{ x: 'Jan', y: -7.1 }, { x: 'Feb', y: -3.7 },
{ x: 'Mar', y: 2 }, { x: 'Apr', y: 6.3 },
{ x: 'May', y: 13.3 }, { x: 'Jun', y: 18.0 },
{ x: 'Jul', y: 19.8 }, { x: 'Aug', y: 18.1 },
{ x: 'Sep', y: 13.1 }, { x: 'Oct', y: 4.1 },
{ x: 'Nov', y: -3.8 }, { x: 'Dec', y: -6.8 }
];export let data: Object[] = [
{ x: 'Jan', y: -7.1 }, { x: 'Feb', y: -3.7 },
{ x: 'Mar', y: 2 }, { x: 'Apr', y: 6.3 },
{ x: 'May', y: 13.3 }, { x: 'Jun', y: 18.0 },
{ x: 'Jul', y: 19.8 }, { x: 'Aug', y: 18.1 },
{ x: 'Sep', y: 13.1 }, { x: 'Oct', y: 4.1 },
{ x: 'Nov', y: -3.8 }, { x: 'Dec', y: -6.8 }
];Show percentage based on each series points
Calculate and display percentage values based on each series’ total using the seriesRender and textRender events:
- In
seriesRender, compute the total ofyvalues. - In
textRender, calculate the percentage for each point and update the label text.
import { render } from 'react-dom';
import * as React from "react";
import { ChartComponent, SeriesCollectionDirective, SeriesDirective, Inject, Legend, Category, Tooltip, ColumnSeries, DataLabel } from '@syncfusion/ej2-react-charts';
import { Browser } from '@syncfusion/ej2-base';
import { data1, data2, data3 } from './datasource';
const total = [];
function App() {
return (<div className='control-pane'>
<div className='control-section'>
<ChartComponent id='charts' style={{ textAlign: "center" }} textRender={onTextRender.bind(this)} primaryXAxis={{ valueType: 'Category', interval: 1, majorGridLines: { width: 0 } }} primaryYAxis={{
majorGridLines: { width: 0 },
majorTickLines: { width: 0 }, lineStyle: { width: 0 }, labelStyle: { color: 'transparent' }
}} chartArea={{ border: { width: 0 } }} tooltip={{ enable: true }} width={Browser.isDevice ? '100%' : '60%'} title='Olympic Medal Counts - RIO' seriesRender={onSeriesRender.bind(this)}>
<Inject services={[ColumnSeries, Legend, Tooltip, Category, DataLabel]}/>
<SeriesCollectionDirective>
<SeriesDirective dataSource={data1} xName='x' yName='y' name='Gold' type='Column' marker={{ dataLabel: { visible: true, position: 'Top', font: { fontWeight: '600', color: '#ffffff' } } }}>
</SeriesDirective>
<SeriesDirective dataSource={data2} xName='x' yName='y' name='Silver' type='Column' marker={{ dataLabel: { visible: true, position: 'Top', font: { fontWeight: '600', color: '#ffffff' } } }}>
</SeriesDirective>
<SeriesDirective dataSource={data3} xName='x' yName='y' name='Bronze' type='Column' marker={{ dataLabel: { visible: true, position: 'Top', font: { fontWeight: '600', color: '#ffffff' } } }}>
</SeriesDirective>
</SeriesCollectionDirective>
</ChartComponent>
</div>
</div>);
function onSeriesRender(args) {
for (var i = 0; i < args.data.length; i++) {
if (!total[args.data[i].x])
total[args.data[i].x] = 0;
total[args.data[i].x] += parseInt(args.data[i].y);
}
}
;
function onTextRender(args) {
var percentage = (parseInt(args.text) / total[args.point.x]) * 100;
percentage = percentage % 1 === 0 ? percentage : percentage.toFixed(2);
args.text = percentage + '%';
}
;
}
export default App;
render(<App />, document.getElementById('charts'));import { render } from 'react-dom';
import * as React from "react";
import { ChartComponent, SeriesCollectionDirective, SeriesDirective, Inject, Legend, Category, Tooltip, ColumnSeries, DataLabel } from '@syncfusion/ej2-react-charts';
import { Browser } from '@syncfusion/ej2-base';
import { data1, data2, data3 } from './datasource';
const total = [];
function App() {
return (<div className='control-pane'>
<div className='control-section'>
<ChartComponent id='charts' style={{ textAlign: "center" }} textRender={onTextRender.bind(this)} primaryXAxis={{ valueType: 'Category', interval: 1, majorGridLines: { width: 0 } }} primaryYAxis={{
majorGridLines: { width: 0 },
majorTickLines: { width: 0 }, lineStyle: { width: 0 }, labelStyle: { color: 'transparent' }
}} chartArea={{ border: { width: 0 } }} tooltip={{ enable: true }} width={Browser.isDevice ? '100%' : '60%'} title='Olympic Medal Counts - RIO' seriesRender={onSeriesRender.bind(this)}>
<Inject services={[ColumnSeries, Legend, Tooltip, Category, DataLabel]} />
<SeriesCollectionDirective>
<SeriesDirective dataSource={data1} xName='x' yName='y' name='Gold' type='Column' marker={{ dataLabel: { visible: true, position: 'Top', font: { fontWeight: '600', color: '#ffffff' } } }}>
</SeriesDirective>
<SeriesDirective dataSource={data2} xName='x' yName='y' name='Silver' type='Column' marker={{ dataLabel: { visible: true, position: 'Top', font: { fontWeight: '600', color: '#ffffff' } } }}>
</SeriesDirective>
<SeriesDirective dataSource={data3} xName='x' yName='y' name='Bronze' type='Column' marker={{ dataLabel: { visible: true, position: 'Top', font: { fontWeight: '600', color: '#ffffff' } } }}>
</SeriesDirective>
</SeriesCollectionDirective>
</ChartComponent>
</div>
</div>);
function onSeriesRender(args) {
for (var i = 0; i < args.data.length; i++) {
if (!total[args.data[i].x]) total[args.data[i].x] = 0;
total[args.data[i].x] += parseInt(args.data[i].y);
}
}
;
function onTextRender(args) {
var percentage = (parseInt(args.text) / total[args.point.x]) * 100;
percentage = percentage % 1 === 0 ? percentage : percentage.toFixed(2);
args.text = percentage + '%';
};
}
export default App;
render(<App />, document.getElementById('charts'));export let data1 = [
{ x: 'USA', y: 46 },
{ x: 'GBR', y: 27 },
{ x: 'CHN', y: 26 }
];
export let data2 = [
{ x: 'USA', y: 37 },
{ x: 'GBR', y: 23 },
{ x: 'CHN', y: 18 }
];
export let data3 = [
{ x: 'USA', y: 38 },
{ x: 'GBR', y: 17 },
{ x: 'CHN', y: 26 }
];export let data1: Object[] = [
{ x: 'USA', y: 46 },
{ x: 'GBR', y: 27 },
{ x: 'CHN', y: 26 }
];
export let data2: Object[] = [
{ x: 'USA', y: 37 },
{ x: 'GBR', y: 23 },
{ x: 'CHN', y: 18 }
];
export let data3: Object[] = [
{ x: 'USA', y: 38 },
{ x: 'GBR', y: 17 },
{ x: 'CHN', y: 26 }
];Last value label
The lastValueLabel feature highlights the final data point in a series, making the latest trend or value easy to identify. The lastValueLabel option is configured on each SeriesDirective (it is a Series-level property), not on the chart component. To use this feature, inject the ColumnSeries (or other required series), Category, DataLabel, and LastValueLabel modules into the services.
Enable last value label
Enable the label by setting the enable property inside the lastValueLabel configuration of the series.
import * as React from "react";
import * as ReactDOM from "react-dom";
import { Category, ChartComponent, ColumnSeries, DataLabel, Inject, Legend, LastValueLabel, SeriesCollectionDirective, SeriesDirective, Tooltip } from '@syncfusion/ej2-react-charts';
import { data } from './datasource';
function App() {
const primaryXAxis = { title: 'Year', interval: 1 };
const primaryYAxis = { title: 'Efficiency', labelFormat: '{value}%' };
const tooltip = { enable: true };
const title = 'Efficiency of oil-fired power production';
const marker = { visible: false, dataLabel: { visible: true }};
return <ChartComponent id='charts' title={title} width='90%' primaryXAxis={primaryXAxis} primaryYAxis={primaryYAxis} tooltip={tooltip}>
<Inject services={[ColumnSeries, Legend, Tooltip, DataLabel, LastValueLabel, Category]}/>
<SeriesCollectionDirective>
<SeriesDirective dataSource={data} xName='x' yName='y' type='Column' name='series1' animation={{ enable: true }}
lastValueLabel={{ enable: true }} marker={marker}/>
</SeriesCollectionDirective>
</ChartComponent>;
};
export default App;
ReactDOM.render(<App />, document.getElementById("charts"));import * as React from "react";
import * as ReactDOM from "react-dom";
import { Category, ChartComponent, ColumnSeries, DataLabel, Inject, Legend, SeriesCollectionDirective, MarkerSettingsModel, SeriesDirective, TooltipSettingsModel, Tooltip, LastValueLabel } from '@syncfusion/ej2-react-charts';
import { data } from './datasource';
function App() {
const primaryXAxis: Object = { title: 'Year', interval: 1 };
const primaryYAxis: Object = { title: 'Efficiency', labelFormat: '{value}%' };
const tooltip: TooltipSettingsModel = { enable: true };
const title: string = 'Efficiency of oil-fired power production';
const marker: MarkerSettingsModel = { visible: false, dataLabel: { visible: true }};
return <ChartComponent id='charts' title={title} width='90%' primaryXAxis={primaryXAxis} primaryYAxis={primaryYAxis} tooltip={tooltip}>
<Inject services={[ColumnSeries, Legend, Tooltip, DataLabel, LastValueLabel, Category]}/>
<SeriesCollectionDirective>
<SeriesDirective dataSource={data} xName='x' yName='y' type='Column' name='series1' animation={{ enable: true }}
lastValueLabel={{ enable: true }} marker={marker}/>
</SeriesCollectionDirective>
</ChartComponent>;
};
export default App;
ReactDOM.render(<App />, document.getElementById("charts"));export let data = [
{ x: 2005, y: 28 }, { x: 2006, y: 25 }, { x: 2007, y: 26 }, { x: 2008, y: 27 },
{ x: 2009, y: 32 }, { x: 2010, y: 35 }, { x: 2011, y: 40 }
];export let data: Object[] = [
{ x: 2005, y: 28 }, { x: 2006, y: 25 }, { x: 2007, y: 26 }, { x: 2008, y: 27 },
{ x: 2009, y: 32 }, { x: 2010, y: 35 }, { x: 2011, y: 40 }
];Note: To use the last value label feature, inject the
LastValueLabelmodule into theservices.
Customization
Customize the appearance using font, background, border, dashArray, lineWidth, lineColor, rx, and ry. The lineColor, lineWidth, and dashArray properties control the connector line drawn between the last data point and the label.
import * as React from "react";
import * as ReactDOM from "react-dom";
import { Category, ChartComponent, ColumnSeries, DataLabel, Inject, Legend, LastValueLabel, SeriesCollectionDirective, SeriesDirective, Tooltip } from '@syncfusion/ej2-react-charts';
import { data } from './datasource';
function App() {
const primaryXAxis = { title: 'Year', interval: 1 };
const primaryYAxis = { title: 'Efficiency', labelFormat: '{value}%' };
const lastValueLabel = { enable: true, background: "blue", lineColor: "red", lineWidth: 2, dashArray: "5,5", rx: 10, ry: 10, border: { width: 2, color: "red" }, font: { color: "white", size: "12px", fontWeight: "bold" } };
const tooltip = { enable: true };
const title = 'Efficiency of oil-fired power production';
const marker = { visible: false, dataLabel: { visible: true }};
return <ChartComponent id='charts' title={title} width='90%' primaryXAxis={primaryXAxis} primaryYAxis={primaryYAxis} tooltip={tooltip}>
<Inject services={[ColumnSeries, Legend, Tooltip, DataLabel, LastValueLabel, Category]}/>
<SeriesCollectionDirective>
<SeriesDirective dataSource={data} xName='x' yName='y' type='Column' name='series1' animation={{ enable: true }}
lastValueLabel={lastValueLabel} marker={marker}/>
</SeriesCollectionDirective>
</ChartComponent>;
};
export default App;
ReactDOM.render(<App />, document.getElementById("charts"));import * as React from "react";
import * as ReactDOM from "react-dom";
import { Category, ChartComponent, ColumnSeries, DataLabel, Inject, Legend, SeriesCollectionDirective, MarkerSettingsModel, SeriesDirective, TooltipSettingsModel, Tooltip, LastValueLabel, LastValueLabelSettingsModel } from '@syncfusion/ej2-react-charts';
import { data } from './datasource';
function App() {
const primaryXAxis: Object = { title: 'Year', interval: 1 };
const primaryYAxis: Object = { title: 'Efficiency', labelFormat: '{value}%' };
const lastValueLabel: LastValueLabelSettingsModel = { enable: true, background: "blue", lineColor: "red", lineWidth: 2, dashArray: "5,5", rx: 10, ry: 10, border: { width: 2, color: "red" }, font: { color: "white", size: "12px", fontWeight: "bold" } };
const tooltip: TooltipSettingsModel = { enable: true };
const title: string = 'Efficiency of oil-fired power production';
const marker: MarkerSettingsModel = { visible: false, dataLabel: { visible: true }};
return <ChartComponent id='charts' title={title} width='90%' primaryXAxis={primaryXAxis} primaryYAxis={primaryYAxis} tooltip={tooltip}>
<Inject services={[ColumnSeries, Legend, Tooltip, DataLabel, LastValueLabel, Category]}/>
<SeriesCollectionDirective>
<SeriesDirective dataSource={data} xName='x' yName='y' type='Column' name='series1' animation={{ enable: true }}
lastValueLabel={lastValueLabel} marker={marker}/>
</SeriesCollectionDirective>
</ChartComponent>;
};
export default App;
ReactDOM.render(<App />, document.getElementById("charts"));export let data = [
{ x: 2005, y: 28 }, { x: 2006, y: 25 }, { x: 2007, y: 26 }, { x: 2008, y: 27 },
{ x: 2009, y: 32 }, { x: 2010, y: 35 }, { x: 2011, y: 40 }
];export let data: Object[] = [
{ x: 2005, y: 28 }, { x: 2006, y: 25 }, { x: 2007, y: 26 }, { x: 2008, y: 27 },
{ x: 2009, y: 32 }, { x: 2010, y: 35 }, { x: 2011, y: 40 }
];