Last value label in ASP.NET CORE Chart Control

30 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.

<ejs-chart id="container" width="90%" title="Efficiency of oil-fired power production">
        <e-chart-tooltipsettings enable="true"></e-chart-tooltipsettings>
        <e-chart-primaryxaxis title="Year" interval="1"></e-chart-primaryxaxis>
        <e-chart-primaryyaxis labelFormat="{value}%" title="Efficiency"></e-chart-primaryyaxis>
        <e-series-collection>
            <e-series dataSource="ViewBag.dataSource" xName="x" yName="y" type="@Syncfusion.EJ2.Charts.ChartSeriesType.Column" name="series1">
            <e-series-marker visible="false">
            <e-series-datalabel visible="true"></e-series-datalabel>
                </e-series-marker>
            </e-series>
            <e-series-lastvaluelabel enable="true"></e-series-lastvaluelabel>
        </e-series-collection>
    </ejs-chart>
public ActionResult Index()
        {
            List<LastValueLabelChartData> chartData = new List<LastValueLabelChartData>
            {
             new LastValueLabelChartData {x= 2005, y= 28  },
             new LastValueLabelChartData{ x= 2006, y= 25 },
             new LastValueLabelChartData{ x= 2007, y= 26 },
             new LastValueLabelChartData{ x= 2008, y= 27 },
             new LastValueLabelChartData{ x= 2009, y= 32 },
             new LastValueLabelChartData{ x= 2010, y= 35 },
             new LastValueLabelChartData{ x= 2011, y= 40 }
            };
            ViewBag.dataSource = chartData;
            return View();
        }
        public class LastValueLabelChartData
{
            public double x;
            public double y;
        }

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.

<ejs-chart id="container" width="90%" title="Efficiency of oil-fired power production">
        <e-chart-tooltipsettings enable="true"></e-chart-tooltipsettings>
        <e-chart-primaryxaxis title="Year" interval="1"></e-chart-primaryxaxis>
        <e-chart-primaryyaxis labelFormat="{value}%" title="Efficiency"></e-chart-primaryyaxis>
        <e-series-collection>
            <e-series dataSource="ViewBag.dataSource" xName="x" yName="y" type="@Syncfusion.EJ2.Charts.ChartSeriesType.Column" name="series1">
            <e-series-marker visible="false">
            <e-series-datalabel visible="true"></e-series-datalabel>
                </e-series-marker>
            </e-series>
            <e-series-lastvaluelabel enable="true" background="blue" lineColor="red" lineWidth="2" dashArray="5,5" rx="10" ry="10">
               <e-series-border width="2" color="red"></e-series-border>
               <e-series-font color="white" size="12px" fontWeight="bold"></e-series-font>
            </e-series-lastvaluelabel>
        </e-series-collection>
    </ejs-chart>
public ActionResult Index()
        {
            List<LastValueLabelChartData> chartData = new List<LastValueLabelChartData>
            {
             new LastValueLabelChartData {x= 2005, y= 28  },
             new LastValueLabelChartData{ x= 2006, y= 25 },
             new LastValueLabelChartData{ x= 2007, y= 26 },
             new LastValueLabelChartData{ x= 2008, y= 27 },
             new LastValueLabelChartData{ x= 2009, y= 32 },
             new LastValueLabelChartData{ x= 2010, y= 35 },
             new LastValueLabelChartData{ x= 2011, y= 40 }
            };
            ViewBag.dataSource = chartData;
            return View();
        }
        public class LastValueLabelChartData
{
            public double x;
            public double y;
        }