Example of Empty Point in ASP.NET MVC Charts Control
This Line Chart example shows what the chart does with rows that have no value: drop them, leave a gap, draw zero or draw the average.
@Html.UiChart(new UiChartOptions
{
Id = "emptyPoint" + mode,
Data = (IEnumerable<object>)ViewData["ChartData"],
Height = "260px",
Title = "EmptyPointMode = " + mode,
Legend = new UiChartLegend { Visible = false },
PrimaryYAxis = new UiChartAxis { Minimum = 0, Maximum = 30 },
Series = new List<UiChartSeries>
{
new UiChartSeries { Type = UiChartSeriesType.Line, XName = "Day", YName = "Value", Name = "Value", ShowMarker = true, EmptyPointMode = mode }
}
})
<div class="row g-3">
@foreach (var mode in new[] { UiChartEmptyPointMode.Drop, UiChartEmptyPointMode.Gap, UiChartEmptyPointMode.Zero, UiChartEmptyPointMode.Average })
{
<div class="col-lg-6">
@Html.UiChart(new UiChartOptions
{
Id = "emptyPoint" + mode,
Data = (IEnumerable<object>)ViewData["ChartData"],
Height = "260px",
Title = "EmptyPointMode = " + mode,
Legend = new UiChartLegend { Visible = false },
PrimaryYAxis = new UiChartAxis { Minimum = 0, Maximum = 30 },
Series = new List<UiChartSeries>
{
new UiChartSeries { Type = UiChartSeriesType.Line, XName = "Day", YName = "Value", Name = "Value", ShowMarker = true, EmptyPointMode = mode }
}
})
</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/EmptyPoint.cshtml; it draws what ViewData holds.
public ActionResult EmptyPoint()
{
var readings = new[]
{
new { Day = "Mon", Value = (double?)12 }, new { Day = "Tue", Value = (double?)18 }, new { Day = "Wed", Value = (double?)null },
new { Day = "Thu", Value = (double?)22 }, new { Day = "Fri", Value = (double?)null }, new { Day = "Sat", Value = (double?)16 },
new { Day = "Sun", Value = (double?)20 }
};
ViewData["ChartData"] = readings;
return View();
}
}
}
@* Install once: Install-Package Lumen.UI.Mvc (or: dotnet add package Lumen.UI.Mvc) *@
@* Views/Web.config: <add namespace="Lumen.UI.Mvc" /> *@
@* Views/Shared/_Layout.cshtml *@
<head>
@Html.UiStyles()
<link rel="stylesheet" href="~/Content/site.css" />
</head>
<body>
@RenderBody()
@Html.UiScripts()
@RenderSection("scripts", required: false)
</body>
@* Charts with a DataUrl: @Html.AntiForgeryToken() on the page and [HttpPost, ValidateJsonAntiForgeryToken] on the action. *@
Rows without a value are "empty points". EmptyPointMode says what a line, an area or a column does with them: Drop joins the points around it, Gap leaves a break, Zero draws 0, Average draws the mean of the neighbours.