Example of Range Area in ASP.NET Core Charts Control
This Range Area Chart example shows two temperature bands as areas between a low and a high line.
@* 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 = "rangeAreaChart",
Title = "Temperature range",
Data = (IEnumerable<object>)ViewData["ChartData"],
Height = "340px",
Tooltip = new UiChartTooltip { Shared = true },
PrimaryYAxis = new UiChartAxis { LabelFormat = "{value}\u00B0C" },
Series = new List<UiChartSeries>
{
new UiChartSeries { Type = UiChartSeriesType.RangeArea, XName = "Month", High = "OtherHigh", Low = "OtherLow", Name = "Texas", Opacity = 0.6 },
new UiChartSeries { Type = UiChartSeriesType.RangeArea, XName = "Month", High = "High", Low = "Low", Name = "California", Opacity = 0.6 }
}
})
@Html.UiChart(new UiChartOptions
{
Id = "rangeAreaChart",
Title = "Temperature range",
Data = (IEnumerable<object>)ViewData["ChartData"],
Height = "340px",
Tooltip = new UiChartTooltip { Shared = true },
PrimaryYAxis = new UiChartAxis { LabelFormat = "{value}\u00B0C" },
Series = new List<UiChartSeries>
{
new UiChartSeries { Type = UiChartSeriesType.RangeArea, XName = "Month", High = "OtherHigh", Low = "OtherLow", Name = "Texas", Opacity = 0.6 },
new UiChartSeries { Type = UiChartSeriesType.RangeArea, XName = "Month", High = "High", Low = "Low", Name = "California", Opacity = 0.6 }
}
})
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/RangeArea.cshtml; it draws what ViewData holds.
public ActionResult RangeArea()
{
ViewData["ChartData"] = TemperatureRanges();
return View();
}
/// <summary>The temperature of one month in two cities: the rows of the range samples.</summary>
public class TemperatureData
{
public string Month { get; set; }
public double Low { get; set; }
public double High { get; set; }
public double OtherLow { get; set; }
public double OtherHigh { get; set; }
}
private static List<TemperatureData> TemperatureRanges()
{
double[][] rows =
{
new[] { 4.0, 14, 8, 20 }, new[] { 6.0, 17, 9, 22 }, new[] { 9.0, 20, 11, 24 }, new[] { 12.0, 24, 13, 27 },
new[] { 15.0, 27, 16, 30 }, new[] { 18.0, 31, 19, 33 }, new[] { 20.0, 33, 21, 34 }, new[] { 19.0, 32, 21, 33 }
};
return rows.Select((t, i) => new TemperatureData
{
Month = new DateTime(2026, i + 1, 1).ToString("MMM"),
Low = t[0],
High = t[1],
OtherLow = t[2],
OtherHigh = t[3]
}).ToList();
}
}
}
@* 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. *@
Range Area Chart fills the region between a low and a high value. In this example, each series is the band between the low and the high temperature of one city.