Last value label in EJ2 JavaScript Chart control

27 Jun 20257 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.

var chartData = [
     { 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 }
 ];
var Chart = new ej.charts.Chart({
    primaryXAxis: {
        title: 'Year',
        interval: 1
    },
    primaryYAxis: {
 
        title: 'Efficiency',
        labelFormat: '{value}%'
    },
    width: '90%',
    series: [{
        dataSource: chartData,
        xName: 'x', yName: 'y',
        name: 'series1',
        marker: { visible: false, dataLabel: { visible: true } },
        type: 'Column', animation: { enable: true },
        lastValueLabel: { enable: true }
    }],
 
    tooltip: { enable: true },
 
    title: 'Efficiency of oil-fired power production'
    }, '#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://cdn.syncfusion.com/ej2/31.1.17/dist/ej2.min.js" type="text/javascript"></script>
<script src="https://cdn.syncfusion.com/ej2/syncfusion-helper.js" type ="text/javascript"></script>
</head>

<body>
    
    <div id="container">
        <div id="element"></div>
    </div>


<script>
var ele = document.getElementById('container');
if(ele) {
  ele.style.visibility = "visible";
}   
      </script>
<script src="index.js" type="text/javascript"></script>
</body></html>

Note: To use the last value label feature, we need to inject LastValueLabel module using Chart.Inject(LastValueLabel).

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.

var chartData = [
     { 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 }
 ];
var Chart = new ej.charts.Chart({
    primaryXAxis: {
        title: 'Year',
        interval: 1
    },
    primaryYAxis: {
 
        title: 'Efficiency',
        labelFormat: '{value}%'
    },
    width: '90%',
    series: [{
        dataSource: chartData,
        xName: 'x', yName: 'y',
        name: 'series1',
        marker: { visible: false, dataLabel: { visible: true } },
        type: 'Column', animation: { enable: true },
        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" } }
    }],
 
    tooltip: { enable: true },
 
    title: 'Efficiency of oil-fired power production'
    }, '#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://cdn.syncfusion.com/ej2/31.1.17/dist/ej2.min.js" type="text/javascript"></script>
<script src="https://cdn.syncfusion.com/ej2/syncfusion-helper.js" type ="text/javascript"></script>
</head>

<body>
    
    <div id="container">
        <div id="element"></div>
    </div>


<script>
var ele = document.getElementById('container');
if(ele) {
  ele.style.visibility = "visible";
}   
      </script>
<script src="index.js" type="text/javascript"></script>
</body></html>