Example of Line Zone in ASP.NET Core Charts Control
This Line Chart example changes the colour of the line where it crosses chosen values of the Y axis.
@* The chart's settings are in the view; the data they read (ViewData) is set in the controller action (see the controller tab). *@
@Html.UiChart(new UiChartOptions
{
Id = "lineZoneChart",
Title = "Retail sales by zone",
Data = (IEnumerable<object>)ViewData["ChartData"],
Height = "340px",
PrimaryYAxis = new UiChartAxis { LabelFormat = "N0" },
Legend = new UiChartLegend { Visible = false },
Series = new List<UiChartSeries>
{
new UiChartSeries
{
Type = UiChartSeriesType.MultiColoredLine, XName = "MonthName", YName = "Retail", Name = "Retail", Width = 3, ShowMarker = true,
Segments = new List<UiChartSegment>
{
new UiChartSegment { Value = 22000, Color = "#d13438" },
new UiChartSegment { Value = 28000, Color = "#f7a600" },
new UiChartSegment { Color = "#09af74" }
}
}
}
})
@Html.UiChart(new UiChartOptions
{
Id = "lineZoneChart",
Title = "Retail sales by zone",
Data = (IEnumerable<object>)ViewData["ChartData"],
Height = "340px",
PrimaryYAxis = new UiChartAxis { LabelFormat = "N0" },
Legend = new UiChartLegend { Visible = false },
Series = new List<UiChartSeries>
{
new UiChartSeries
{
Type = UiChartSeriesType.MultiColoredLine, XName = "MonthName", YName = "Retail", Name = "Retail", Width = 3, ShowMarker = true,
Segments = new List<UiChartSegment>
{
new UiChartSegment { Value = 22000, Color = "#d13438" },
new UiChartSegment { Value = 28000, Color = "#f7a600" },
new UiChartSegment { Color = "#09af74" }
}
}
}
})
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/LineZone.cshtml; it draws what ViewData holds.
public ActionResult LineZone()
{
ViewData["ChartData"] = MonthlySalesData();
return View();
}
/// <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. *@
Line zones: the line changes colour where it crosses a value of the Y axis (Segments with SegmentAxis = Y).