Last value label in React Chart component
27 Jun 202512 minutes to read
The lastValueLabel
in a chart allows you to easily display the value of the last data point in a series. This feature provides an intuitive way to highlight the most recent or last data value in a series on your chart.
Enable last value label
To show the last value label, make sure the enable
property inside the lastValueLabel
settings is set to true
within the series configuration.
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=
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 } 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=
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 }
];
Note: To use the last value label feature, we need to inject
LastValueLabel
module into theservices
.
Customization
The appearance of the last value label can be customized using style properties such as font
, background
, border
, dashArray
, lineWidth
, lineColor
, rx
, and ry
in the lastValueLabel property of the chart series. These settings allow you to tailor the label’s look to align with your desired visual presentation.
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=
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=
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 }
];