Example of Spline Area in ASP.NET Core Charts Control
This Spline Area Chart example visualizes inflation rate comparison for two countries by using spline area series.
@* 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 = "splineAreaChart",
Title = "Inflation Rate in Percentage",
Data = (IEnumerable<object>)ViewData["ChartPoints"],
Tooltip = new UiChartTooltip { Enable = true, EnableHighlight = true, ShowNearestTooltip = true },
Legend = new UiChartLegend { EnableHighlight = true },
PrimaryXAxis = new UiChartAxis { ShowGridLines = false, ValueType = UiChartValueType.DateTime, IntervalType = UiChartIntervalType.Years, LabelFormat = "yyyy" },
PrimaryYAxis = new UiChartAxis { LabelFormat = "{value}%", Maximum = 4, Interval = 1, Minimum = 0 },
Series = new List<UiChartSeries>
{
new UiChartSeries { Type = UiChartSeriesType.SplineArea, Width = 2, XName = "Period", YName = "US_InflationRate", Name = "US", Opacity = 0.5, Marker = new UiChartMarker { Visible = true, Width = 6, Height = 6, Shape = UiChartMarkerShape.Circle, IsFilled = true } },
new UiChartSeries { Type = UiChartSeriesType.SplineArea, Width = 2, XName = "Period", YName = "FR_InflationRate", Name = "France", Opacity = 0.5, Marker = new UiChartMarker { Visible = true, Width = 7, Height = 7, Shape = UiChartMarkerShape.Diamond, IsFilled = true } }
}
})
@Html.UiChart(new UiChartOptions
{
Id = "splineAreaChart",
Title = "Inflation Rate in Percentage",
Data = (IEnumerable<object>)ViewData["ChartPoints"],
Tooltip = new UiChartTooltip { Enable = true, EnableHighlight = true, ShowNearestTooltip = true },
Legend = new UiChartLegend { EnableHighlight = true },
PrimaryXAxis = new UiChartAxis { ShowGridLines = false, ValueType = UiChartValueType.DateTime, IntervalType = UiChartIntervalType.Years, LabelFormat = "yyyy" },
PrimaryYAxis = new UiChartAxis { LabelFormat = "{value}%", Maximum = 4, Interval = 1, Minimum = 0 },
Series = new List<UiChartSeries>
{
new UiChartSeries { Type = UiChartSeriesType.SplineArea, Width = 2, XName = "Period", YName = "US_InflationRate", Name = "US", Opacity = 0.5, Marker = new UiChartMarker { Visible = true, Width = 6, Height = 6, Shape = UiChartMarkerShape.Circle, IsFilled = true } },
new UiChartSeries { Type = UiChartSeriesType.SplineArea, Width = 2, XName = "Period", YName = "FR_InflationRate", Name = "France", 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/SplineArea.cshtml; it draws what ViewData holds.
public ActionResult SplineArea()
{
List<SplineAreaChartData> ChartPoints = new List<SplineAreaChartData>
{
new SplineAreaChartData { Period = new DateTime(2002, 01, 01), US_InflationRate = 2.2, FR_InflationRate = 2, GER_InflationRate = 0.8 },
new SplineAreaChartData { Period = new DateTime(2003, 01, 01), US_InflationRate = 3.4, FR_InflationRate = 1.7, GER_InflationRate = 1.3 },
new SplineAreaChartData { Period = new DateTime(2004, 01, 01), US_InflationRate = 2.8, FR_InflationRate = 1.8, GER_InflationRate = 1.1 },
new SplineAreaChartData { Period = new DateTime(2005, 01, 01), US_InflationRate = 1.6, FR_InflationRate = 2.1, GER_InflationRate = 1.6 },
new SplineAreaChartData { Period = new DateTime(2006, 01, 01), US_InflationRate = 2.3, FR_InflationRate = 2.3, GER_InflationRate = 2 },
new SplineAreaChartData { Period = new DateTime(2007, 01, 01), US_InflationRate = 2.5, FR_InflationRate = 1.7, GER_InflationRate = 1.7 },
new SplineAreaChartData { Period = new DateTime(2008, 01, 01), US_InflationRate = 2.9, FR_InflationRate = 1.5, GER_InflationRate = 2.3 },
new SplineAreaChartData { Period = new DateTime(2009, 01, 01), US_InflationRate = 1.1, FR_InflationRate = 0.5, GER_InflationRate = 2.7 },
new SplineAreaChartData { Period = new DateTime(2010, 01, 01), US_InflationRate = 1.4, FR_InflationRate = 1.5, GER_InflationRate = 1.1 },
new SplineAreaChartData { Period = new DateTime(2011, 01, 01), US_InflationRate = 1.1, FR_InflationRate = 1.3, GER_InflationRate = 1.5 }
};
ViewData["ChartPoints"] = ChartPoints;
return View();
}
public class SplineAreaChartData
{
public DateTime Period { get; set; }
public double US_InflationRate { get; set; }
public double FR_InflationRate { get; set; }
public double GER_InflationRate { 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 a spline area chart. This chart plots a fitted curve through each data point in a series. It is used to represent time-dependent data and show trends in data at equal intervals.