Example of Stacked Smart Labels in ASP.NET Core Charts Control
This sample shows the global smartphone shipment trends by vendor using smart labels in a stacked column chart.
${x}
${series}: ${y}
${series}: ${y}
@Html.UiChart(new UiChartOptions
{
Id = "stackedSmartLabelsChart",
Title = "Global Smartphone Shipments by Vendor (2025)",
SubTitle = "Smart labels automatically reposition small stacked-segment labels to avoid overlap.",
Data = (IEnumerable<object>)ViewData["ChartPoints"],
Tooltip = new UiChartTooltip { Enable = true, EnableHighlight = true, Shared = true, Template = "#tipStackedSmartLabels" },
Legend = new UiChartLegend { Visible = true, EnableHighlight = true, Position = UiChartLegendPosition.Bottom },
PrimaryXAxis = new UiChartAxis { ValueType = UiChartValueType.Category, ShowGridLines = false, Interval = 1, LabelIntersectAction = UiChartLabelIntersectAction.Rotate45 },
PrimaryYAxis = new UiChartAxis { Title = "Shipments (Millions of Units)", LabelFormat = "{value}M", Minimum = 0, Maximum = 400, Interval = 50 },
Series = new List<UiChartSeries>
{
new UiChartSeries { Type = UiChartSeriesType.StackingColumn, XName = "X", YName = "Samsung", Name = "Samsung", ColumnWidth = 0.5, ShowDataLabel = true, SmartLabels = true },
new UiChartSeries { Type = UiChartSeriesType.StackingColumn, XName = "X", YName = "Apple", Name = "Apple", ColumnWidth = 0.5, ShowDataLabel = true, SmartLabels = true },
new UiChartSeries { Type = UiChartSeriesType.StackingColumn, XName = "X", YName = "Xiaomi", Name = "Xiaomi", ColumnWidth = 0.5, ShowDataLabel = true, SmartLabels = true },
new UiChartSeries { Type = UiChartSeriesType.StackingColumn, XName = "X", YName = "Oppo", Name = "OPPO", ColumnWidth = 0.5, ShowDataLabel = true, SmartLabels = true },
new UiChartSeries { Type = UiChartSeriesType.StackingColumn, XName = "X", YName = "Vivo", Name = "vivo", ColumnWidth = 0.5, ShowDataLabel = true, SmartLabels = true },
new UiChartSeries { Type = UiChartSeriesType.StackingColumn, XName = "X", YName = "Others", Name = "Others", ColumnWidth = 0.5, ShowDataLabel = true, SmartLabels = true }
}
})
<template id="tipStackedSmartLabels">${x}<br>${series}: <b>${y}</b></template>
@Html.UiChart(new UiChartOptions
{
Id = "stackedSmartLabelsChart",
Title = "Global Smartphone Shipments by Vendor (2025)",
SubTitle = "Smart labels automatically reposition small stacked-segment labels to avoid overlap.",
Data = (IEnumerable<object>)ViewData["ChartPoints"],
Tooltip = new UiChartTooltip { Enable = true, EnableHighlight = true, Shared = true, Template = "#tipStackedSmartLabels" },
Legend = new UiChartLegend { Visible = true, EnableHighlight = true, Position = UiChartLegendPosition.Bottom },
PrimaryXAxis = new UiChartAxis { ValueType = UiChartValueType.Category, ShowGridLines = false, Interval = 1, LabelIntersectAction = UiChartLabelIntersectAction.Rotate45 },
PrimaryYAxis = new UiChartAxis { Title = "Shipments (Millions of Units)", LabelFormat = "{value}M", Minimum = 0, Maximum = 400, Interval = 50 },
Series = new List<UiChartSeries>
{
new UiChartSeries { Type = UiChartSeriesType.StackingColumn, XName = "X", YName = "Samsung", Name = "Samsung", ColumnWidth = 0.5, ShowDataLabel = true, SmartLabels = true },
new UiChartSeries { Type = UiChartSeriesType.StackingColumn, XName = "X", YName = "Apple", Name = "Apple", ColumnWidth = 0.5, ShowDataLabel = true, SmartLabels = true },
new UiChartSeries { Type = UiChartSeriesType.StackingColumn, XName = "X", YName = "Xiaomi", Name = "Xiaomi", ColumnWidth = 0.5, ShowDataLabel = true, SmartLabels = true },
new UiChartSeries { Type = UiChartSeriesType.StackingColumn, XName = "X", YName = "Oppo", Name = "OPPO", ColumnWidth = 0.5, ShowDataLabel = true, SmartLabels = true },
new UiChartSeries { Type = UiChartSeriesType.StackingColumn, XName = "X", YName = "Vivo", Name = "vivo", ColumnWidth = 0.5, ShowDataLabel = true, SmartLabels = true },
new UiChartSeries { Type = UiChartSeriesType.StackingColumn, XName = "X", YName = "Others", Name = "Others", ColumnWidth = 0.5, ShowDataLabel = true, SmartLabels = true }
}
})
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web.Mvc;
using Lumen.UI.Mvc;
namespace YourApp.Controllers
{
public class ChartController : Controller
{
// The page is Views/Chart/StackedSmartLabels.cshtml; it draws what ViewData holds.
public ActionResult StackedSmartLabels()
{
List<StackedSmartLabelsChartData> ChartPoints = new List<StackedSmartLabelsChartData>
{
new StackedSmartLabelsChartData { X = "Q1 2025", Samsung = 72.3, Apple = 56.2, Xiaomi = 42.7, Oppo = 7.4, Vivo = 5.2, Others = 70.7 },
new StackedSmartLabelsChartData { X = "Q2 2025", Samsung = 75.9, Apple = 57.1, Xiaomi = 43.9, Oppo = 6.2, Vivo = 3.9, Others = 4.9 },
new StackedSmartLabelsChartData { X = "Q3 2025", Samsung = 80.1, Apple = 60.3, Xiaomi = 46.0, Oppo = 4.8, Vivo = 3.9, Others = 78.9 },
new StackedSmartLabelsChartData { X = "Q4 2025", Samsung = 85.5, Apple = 62.7, Xiaomi = 48.9, Oppo = 6.4, Vivo = 5.8, Others = 81.5 }
};
ViewData["ChartPoints"] = ChartPoints;
return View();
}
public class StackedSmartLabelsChartData
{
public string X { get; set; }
public double Samsung { get; set; }
public double Apple { get; set; }
public double Xiaomi { get; set; }
public double Oppo { get; set; }
public double Vivo { get; set; }
public double Others { get; set; }
}
}
}
@* Program.cs *@
builder.Services.AddControllersWithViews().AddLumenUIJson();
builder.Services.AddLumenUI();
// ...
app.UseLumenUI();
@* Views/_ViewImports.cshtml *@
@using Lumen.UI.Mvc
@addTagHelper *, Lumen.UI.Core
@* Views/Shared/_Layout.cshtml *@
<head>
@Html.UiStyles()
<link rel="stylesheet" href="~/css/site.css" />
</head>
<body>
@RenderBody()
@Html.UiScripts()
@await RenderSectionAsync("scripts", required: false)
</body>
@* Charts with a DataUrl: @Html.AntiForgeryToken() on the page and [HttpPost, ValidateJsonAntiForgeryToken] on the action. *@
In this example, you can see how the labels can be arranged smartly without overlapping. When a stacked segment does not have enough space to display a data label, the label is automatically moved outside the segment and connected using a callout line.
Tooltip is enabled in this example. To see the tooltip in action, hover over a point or tap on a point in touch-enabled devices.