Example of Area Empty Points in ASP.NET MVC Charts Control
This sample illustrates an area series with empty points. Data points with null points are shown here.
${x} : ${y}
@Html.UiChart(new UiChartOptions
{
Id = "areaGapChart",
Title = "Data Consumption",
Data = (IEnumerable<object>)ViewData["ChartPoints"],
Tooltip = new UiChartTooltip { Enable = true, ShowNearestTooltip = true, EnableHighlight = true, Template = "#tipAreaEmptyPoints" },
Legend = new UiChartLegend { EnableHighlight = true },
PrimaryXAxis = new UiChartAxis { ShowGridLines = false, ValueType = UiChartValueType.DateTime, MinimumDate = new DateTime(2021, 11, 15), MaximumDate = new DateTime(2021, 11, 24), LabelFormat = "dd MMM" },
PrimaryYAxis = new UiChartAxis { LabelFormat = "{value}MB", Minimum = 0, Maximum = 5, Interval = 1 },
Series = new List<UiChartSeries>
{
new UiChartSeries { Type = UiChartSeriesType.Area, Width = 2, XName = "Period", YName = "US_InflationRate", Name = "Andrew", Opacity = 0.5, Marker = new UiChartMarker { Visible = true, Width = 7, Height = 7, IsFilled = true } },
new UiChartSeries { Type = UiChartSeriesType.Area, Width = 2, XName = "Period", YName = "IN_InflationRate", Name = "Thomas", Opacity = 0.5, Marker = new UiChartMarker { Visible = true, Width = 7, Height = 7, Shape = UiChartMarkerShape.Diamond, IsFilled = true } }
}
})
<template id="tipAreaEmptyPoints">${x} : <b>${y}</b></template>
@Html.UiChart(new UiChartOptions
{
Id = "areaGapChart",
Title = "Data Consumption",
Data = (IEnumerable<object>)ViewData["ChartPoints"],
Tooltip = new UiChartTooltip { Enable = true, ShowNearestTooltip = true, EnableHighlight = true, Template = "#tipAreaEmptyPoints" },
Legend = new UiChartLegend { EnableHighlight = true },
PrimaryXAxis = new UiChartAxis { ShowGridLines = false, ValueType = UiChartValueType.DateTime, MinimumDate = new DateTime(2021, 11, 15), MaximumDate = new DateTime(2021, 11, 24), LabelFormat = "dd MMM" },
PrimaryYAxis = new UiChartAxis { LabelFormat = "{value}MB", Minimum = 0, Maximum = 5, Interval = 1 },
Series = new List<UiChartSeries>
{
new UiChartSeries { Type = UiChartSeriesType.Area, Width = 2, XName = "Period", YName = "US_InflationRate", Name = "Andrew", Opacity = 0.5, Marker = new UiChartMarker { Visible = true, Width = 7, Height = 7, IsFilled = true } },
new UiChartSeries { Type = UiChartSeriesType.Area, Width = 2, XName = "Period", YName = "IN_InflationRate", Name = "Thomas", Opacity = 0.5, Marker = new UiChartMarker { Visible = true, Width = 7, Height = 7, Shape = UiChartMarkerShape.Diamond, IsFilled = true } }
}
})
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/AreaEmptyPoints.cshtml; it draws what ViewData holds.
public ActionResult AreaEmptyPoints()
{
List<AreaEmptyChartData> ChartPoints = new List<AreaEmptyChartData>
{
new AreaEmptyChartData { Period = new DateTime(2021, 11, 15), US_InflationRate = 2.2, IN_InflationRate = 0.8 },
new AreaEmptyChartData { Period = new DateTime(2021, 11, 16), US_InflationRate = 2.0, IN_InflationRate = 1.7 },
new AreaEmptyChartData { Period = new DateTime(2021, 11, 17), US_InflationRate = 2.8, IN_InflationRate = 1.8 },
new AreaEmptyChartData { Period = new DateTime(2021, 11, 18), US_InflationRate = 1.6, IN_InflationRate = 2.1 },
new AreaEmptyChartData { Period = new DateTime(2021, 11, 19), US_InflationRate = 2.3, IN_InflationRate = Double.NaN },
new AreaEmptyChartData { Period = new DateTime(2021, 11, 20), US_InflationRate = 2.5, IN_InflationRate = 2.3 },
new AreaEmptyChartData { Period = new DateTime(2021, 11, 21), US_InflationRate = 2.9, IN_InflationRate = 1.7 },
new AreaEmptyChartData { Period = new DateTime(2021, 11, 22), US_InflationRate = 1.1, IN_InflationRate = 1.5 },
new AreaEmptyChartData { Period = new DateTime(2021, 11, 23), US_InflationRate = 1.4, IN_InflationRate = 0.5 },
new AreaEmptyChartData { Period = new DateTime(2021, 11, 24), US_InflationRate = 1.1, IN_InflationRate = 1.3 }
};
ViewData["ChartPoints"] = ChartPoints;
return View();
}
public class AreaEmptyChartData
{
public DateTime Period { get; set; }
public double US_InflationRate { get; set; }
public double IN_InflationRate { get; set; }
}
}
}
@* 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. *@
In this example, you can see how to render an area series with empty points. Also, a legend is enabled in the shape of the series.