Example of RangeColumn in ASP.NET Core Charts Control
This Range Column Chart example demonstrates the Range Column series, highlighting the maximum and minimum temperature changes in the Contiguous U.S. for the year 2024 over different months.
${tooltip}
Temperature : ${low} - ${high}
Temperature : ${low} - ${high}
@Html.UiChart(new UiChartOptions
{
Id = "rangeColumnChart",
Title = "Contiguous U.S. Average Temperature in 2024",
SubTitle = "Source: ncei.noaa.gov",
Data = (IEnumerable<object>)ViewData["ChartPoints"],
Tooltip = new UiChartTooltip { Enable = true, Template = "#tipRangeColumn" },
Legend = new UiChartLegend { Visible = false, EnableHighlight = true },
PrimaryXAxis = new UiChartAxis { ValueType = UiChartValueType.Category, ShowGridLines = false },
PrimaryYAxis = new UiChartAxis { LabelFormat = "{value}˚F", Minimum = 0, Maximum = 100, Interval = 20, Title = "Monthly Temperature Variation (°F)" },
Series = new List<UiChartSeries>
{
new UiChartSeries { Type = UiChartSeriesType.RangeColumn, XName = "Month", High = "Max", Low = "Min", ShowDataLabel = true, ColumnSpacing = 0.4, CornerRadius = 4 }
}
})
<template id="tipRangeColumn"><b>${tooltip}</b><br>Temperature : <b>${low} - ${high}</b></template>
@Html.UiChart(new UiChartOptions
{
Id = "rangeColumnChart",
Title = "Contiguous U.S. Average Temperature in 2024",
SubTitle = "Source: ncei.noaa.gov",
Data = (IEnumerable<object>)ViewData["ChartPoints"],
Tooltip = new UiChartTooltip { Enable = true, Template = "#tipRangeColumn" },
Legend = new UiChartLegend { Visible = false, EnableHighlight = true },
PrimaryXAxis = new UiChartAxis { ValueType = UiChartValueType.Category, ShowGridLines = false },
PrimaryYAxis = new UiChartAxis { LabelFormat = "{value}˚F", Minimum = 0, Maximum = 100, Interval = 20, Title = "Monthly Temperature Variation (°F)" },
Series = new List<UiChartSeries>
{
new UiChartSeries { Type = UiChartSeriesType.RangeColumn, XName = "Month", High = "Max", Low = "Min", ShowDataLabel = true, ColumnSpacing = 0.4, CornerRadius = 4 }
}
})
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/RangeColumn.cshtml; it draws what ViewData holds.
public ActionResult RangeColumn()
{
List<RangeColumnChartData> ChartPoints = new List<RangeColumnChartData>
{
new RangeColumnChartData { Month = "Jan", Min = 22.75, Max = 41.02, TooltipText = "January" },
new RangeColumnChartData { Month = "Feb", Min = 29.71, Max = 51.93, TooltipText = "February" },
new RangeColumnChartData { Month = "Mar", Min = 33.53, Max = 56.39, TooltipText = "March" },
new RangeColumnChartData { Month = "Apr", Min = 41.22, Max = 66.06, TooltipText = "April" },
new RangeColumnChartData { Month = "May", Min = 49.87, Max = 74.64, TooltipText = "May" },
new RangeColumnChartData { Month = "Jun", Min = 59.02, Max = 84.58, TooltipText = "June" },
new RangeColumnChartData { Month = "Jul", Min = 62.94, Max = 88.43, TooltipText = "July" },
new RangeColumnChartData { Month = "Aug", Min = 61.27, Max = 86.72, TooltipText = "August" },
new RangeColumnChartData { Month = "Sep", Min = 55.36, Max = 81.86, TooltipText = "September" },
new RangeColumnChartData { Month = "Oct", Min = 44.76, Max = 73.13, TooltipText = "October" },
new RangeColumnChartData { Month = "Nov", Min = 34.79, Max = 55.54, TooltipText = "November" },
new RangeColumnChartData { Month = "Dec", Min = 28.04, Max = 48.36, TooltipText = "December" }
};
ViewData["ChartPoints"] = ChartPoints;
return View();
}
public class RangeColumnChartData
{
public string Month { get; set; }
public double Min { get; set; }
public double Max { get; set; }
public string TooltipText { 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 the range column chart. The range column chart is used to display a range of data by plotting two y-values per data point. The two y-values are used as the upper and lower bounds of a column.
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.