Example of Donut With Gradient in ASP.NET Core Charts Control
This donut chart example shows the share of e-commerce orders by country in 2025 using a donut chart with radial gradient fills. Each slice is annotated with data labels showing the country name and its exact percentage, while the legend on the right provides a quick reference for all countries and their respective values.
@Html.UiChart(new UiChartOptions
{
Id = "donutGradientChart",
Title = "Share of E-commerce Orders by Country - 2025",
SubTitle = "Source: Data provided by Eurostat European Statistics",
Data = (IEnumerable<object>)ViewData["ChartPoints"],
Tooltip = new UiChartTooltip { Enable = true, Template = "#tipDonutGradient" },
Legend = new UiChartLegend { Visible = true, Position = UiChartLegendPosition.Right },
Series = new List<UiChartSeries>
{
new UiChartSeries { Type = UiChartSeriesType.Doughnut, XName = "Country", YName = "Share", Name = "Share by country", ShowDataLabel = true, DataLabelTemplate = "${DataLabelMappingName}", DataLabelPosition = UiChartLabelPosition.Outside, InnerRadius = "65%", Radius = "70%", Gradient = true }
}
})
<template id="tipDonutGradient">${x} : <b>${y}%</b></template>
@Html.UiChart(new UiChartOptions
{
Id = "donutGradientChart",
Title = "Share of E-commerce Orders by Country - 2025",
SubTitle = "Source: Data provided by Eurostat European Statistics",
Data = (IEnumerable<object>)ViewData["ChartPoints"],
Tooltip = new UiChartTooltip { Enable = true, Template = "#tipDonutGradient" },
Legend = new UiChartLegend { Visible = true, Position = UiChartLegendPosition.Right },
Series = new List<UiChartSeries>
{
new UiChartSeries { Type = UiChartSeriesType.Doughnut, XName = "Country", YName = "Share", Name = "Share by country", ShowDataLabel = true, DataLabelTemplate = "${DataLabelMappingName}", DataLabelPosition = UiChartLabelPosition.Outside, InnerRadius = "65%", Radius = "70%", Gradient = 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/DonutGradient.cshtml; it draws what ViewData holds.
public ActionResult DonutGradient()
{
var seriesData = new List<DonutGradientData>
{
new DonutGradientData { Country = "Austria", Share = 38.03, DataLabelMappingName = "Austria: 38.03%" },
new DonutGradientData { Country = "Belgium", Share = 33.7, DataLabelMappingName = "Belgium: 33.7%" },
new DonutGradientData { Country = "Germany", Share = 31.27, DataLabelMappingName = "Germany: 31.27%" },
new DonutGradientData { Country = "The Netherlands", Share = 29.71, DataLabelMappingName = "The Netherlands: 29.71%" },
new DonutGradientData { Country = "Lithuania", Share = 27.72, DataLabelMappingName = "Lithuania: 27.72%" },
new DonutGradientData { Country = "Czechia", Share = 27.37, DataLabelMappingName = "Czechia: 27.37%" },
new DonutGradientData { Country = "Poland", Share = 22.1, DataLabelMappingName = "Poland: 22.1%" },
new DonutGradientData { Country = "Ireland", Share = 18.87, DataLabelMappingName = "Ireland: 18.87%" },
new DonutGradientData { Country = "Croatia", Share = 14.88, DataLabelMappingName = "Croatia: 14.88%" }
};
ViewData["ChartPoints"] = seriesData;
return View();
}
public class DonutGradientData
{
public string Country { get; set; }
public double Share { get; set; }
public string DataLabelMappingName { 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 to render and configure a donut chart with a gradient. To apply a gradient to each point in the pie series, use the pointRender event. Through this event, you can customize the color of each point in the donut chart using the radialGradient property, which applies a circular gradient from the center outward with multiple color stops to create smooth color transitions across each slice.
Tooltip is enabled in this example. To see the tooltip in action, hover over a point or tap on a point on touch-enabled devices.