Example of Polar Line in ASP.NET Core Charts Control
This Polar Chart example shows the average wind speed by direction as a line around a circle.
@* 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 = "polarChart",
Title = "Wind speed (km/h)",
Data = (IEnumerable<object>)ViewData["ChartData"],
Height = "360px",
Series = new List<UiChartSeries>
{
new UiChartSeries { Type = UiChartSeriesType.Polar, DrawType = UiChartDrawType.Line, XName = "Direction", YName = "Gust", Name = "Gust", ShowMarker = true }
}
})
@Html.UiChart(new UiChartOptions
{
Id = "polarChart",
Title = "Wind speed (km/h)",
Data = (IEnumerable<object>)ViewData["ChartData"],
Height = "360px",
Series = new List<UiChartSeries>
{
new UiChartSeries { Type = UiChartSeriesType.Polar, DrawType = UiChartDrawType.Line, XName = "Direction", YName = "Gust", Name = "Gust", ShowMarker = 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/PolarChart.cshtml; it draws what ViewData holds.
public ActionResult PolarChart()
{
ViewData["ChartData"] = WindSpeeds();
return View();
}
/// <summary>The wind of one direction: the rows of the Polar and Radar samples.</summary>
public class WindData
{
public string Direction { get; set; }
public double Average { get; set; }
public double Gust { get; set; }
}
private static List<WindData> WindSpeeds()
{
return new List<WindData>
{
new WindData { Direction = "N", Average = 42, Gust = 52 },
new WindData { Direction = "NE", Average = 28, Gust = 37 },
new WindData { Direction = "E", Average = 35, Gust = 44 },
new WindData { Direction = "SE", Average = 20, Gust = 31 },
new WindData { Direction = "S", Average = 38, Gust = 47 },
new WindData { Direction = "SW", Average = 25, Gust = 33 },
new WindData { Direction = "W", Average = 30, Gust = 41 },
new WindData { Direction = "NW", Average = 18, Gust = 26 }
};
}
}
}
@* 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. *@
Polar with DrawType.Line: the values are joined by lines around the centre.