Last value label in ASP.NET MVC Chart Control

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

@Html.EJS().Chart("container").Series(series =>
   {
   series.Type(Syncfusion.EJ2.Charts.ChartSeriesType.Column).
   Marker(marker => marker.Visible(false).DataLabel(dataLabel => dataLabel.Visible(true))).
   XName("x").
   YName("y").
   DataSource(ViewBag.dataSource).
   Animation(animation => animation.Enable(true)).
   LastValueLabel(lastValueLabel => lastValueLabel.Enable(true)).
   Name("series1").Add();
   }).
   PrimaryXAxis(px => px.Interval(1).Title("Year")).
   PrimaryYAxis(py => py.LabelFormat("{value}%").Title("Efficiency")).
   Tooltip(tooltip => tooltip.Enable(true)).Width("90%").
   Title("Efficiency of oil-fired power production").Render()
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.

@Html.EJS().Chart("container").Series(series =>
   {
   series.Type(Syncfusion.EJ2.Charts.ChartSeriesType.Column).
   Marker(marker => marker.Visible(false).DataLabel(dataLabel => dataLabel.Visible(true))).
   XName("x").
   YName("y").
   DataSource(ViewBag.dataSource).
   Animation(animation => animation.Enable(true)).
   LastValueLabel(lastValueLabel => lastValueLabel.Enable(true).Background("blue").LineColor("red").LineWidth("2").DashArray("5,5").Rx(10).Ry(10).Border(br => br.Width(2).Color("red").Font(font => font.Color("white").Size("12px").FontWeight("bold")))).
   Name("series1").Add();
   }).
   PrimaryXAxis(px => px.Interval(1).Title("Year")).
   PrimaryYAxis(py => py.LabelFormat("{value}%").Title("Efficiency")).
   Tooltip(tooltip => tooltip.Enable(true)).Width("90%").
   Title("Efficiency of oil-fired power production").Render()
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;
        }