Example of Bar with Gradient in ASP.NET Core Charts Control
This sample shows a gradient on the bars of a bar chart and on the areas of an area chart.
@Html.UiChart(new UiChartOptions
{
Id = "barGradientChart",
Data = (IEnumerable<object>)ViewData["RegionData"],
Height = "360px",
Title = "Bars",
PrimaryYAxis = new UiChartAxis { LabelFormat = "N0" },
Series = new List<UiChartSeries>
{
new UiChartSeries { Type = UiChartSeriesType.Bar, XName = "Region", YName = "Q4", Name = "Q4", Gradient = true }
}
})
@Html.UiChart(new UiChartOptions
{
Id = "areaGradientChart",
Data = (IEnumerable<object>)ViewData["MonthlyData"],
Height = "360px",
Title = "Area",
PrimaryYAxis = new UiChartAxis { LabelFormat = "N0" },
Series = new List<UiChartSeries>
{
new UiChartSeries { Type = UiChartSeriesType.Area, XName = "MonthName", YName = "Online", Name = "Online", Gradient = true }
}
})
<div class="row g-3">
<div class="col-lg-6">
@Html.UiChart(new UiChartOptions
{
Id = "barGradientChart",
Data = (IEnumerable<object>)ViewData["RegionData"],
Height = "360px",
Title = "Bars",
PrimaryYAxis = new UiChartAxis { LabelFormat = "N0" },
Series = new List<UiChartSeries>
{
new UiChartSeries { Type = UiChartSeriesType.Bar, XName = "Region", YName = "Q4", Name = "Q4", Gradient = true }
}
})
</div>
<div class="col-lg-6">
@Html.UiChart(new UiChartOptions
{
Id = "areaGradientChart",
Data = (IEnumerable<object>)ViewData["MonthlyData"],
Height = "360px",
Title = "Area",
PrimaryYAxis = new UiChartAxis { LabelFormat = "N0" },
Series = new List<UiChartSeries>
{
new UiChartSeries { Type = UiChartSeriesType.Area, XName = "MonthName", YName = "Online", Name = "Online", Gradient = true }
}
})
</div>
</div>
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/BarGradient.cshtml; it draws what ViewData holds.
public ActionResult BarGradient()
{
ViewData["RegionData"] = RegionSalesData();
ViewData["MonthlyData"] = MonthlySalesData();
return View();
}
/// <summary>The sales of one region per quarter: the rows of the Bar, Stacked Column and Bar Gradient samples.</summary>
public class RegionData
{
public string Region { get; set; }
public double Q1 { get; set; }
public double Q2 { get; set; }
public double Q3 { get; set; }
public double Q4 { get; set; }
}
private static List<RegionData> RegionSalesData()
{
return new List<RegionData>
{
new RegionData { Region = "Luzon", Q1 = 42000, Q2 = 48500, Q3 = 51200, Q4 = 60300 },
new RegionData { Region = "Visayas", Q1 = 27500, Q2 = 29800, Q3 = 33100, Q4 = 36900 },
new RegionData { Region = "Mindanao", Q1 = 21300, Q2 = 24100, Q3 = 23800, Q4 = 28700 },
new RegionData { Region = "Metro Manila", Q1 = 55800, Q2 = 58200, Q3 = 61900, Q4 = 70400 }
};
}
/// <summary>The sales of one month per channel: the rows of the Line, Column and Area samples.</summary>
public class SalesData
{
public string MonthName { get; set; }
public double Online { get; set; }
public double Retail { get; set; }
public double Wholesale { get; set; }
public double Target { get; set; }
}
private static List<SalesData> MonthlySalesData()
{
var list = new List<SalesData>();
for (int m = 0; m < 12; m++)
{
list.Add(new SalesData
{
MonthName = new DateTime(2026, 1, 1).AddMonths(m).ToString("MMM"),
Online = 18000 + m * 1400 + (m % 3) * 2100,
Retail = 26000 + (m % 4) * 1800 - m * 300,
Wholesale = 12000 + m * 900 + (m % 2) * 3000,
Target = 60000 + m * 1500
});
}
return list;
}
}
}
@* 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. *@
A gradient on bars (Gradient = true): from a lighter shade of the series colour at the start of each bar into the colour at its end. The same option works on columns and areas.