Example of Polar WindRose in ASP.NET MVC Charts Control
This sample shows a wind rose chart designed using polar and radar charts with a stacking column series. A wind rose chart helps visualize wind patterns, i.e., wind speed and wind direction.
@* 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 = "windRoseChart",
Title = "Wind Rose Chart",
Data = (IEnumerable<object>)ViewData["ChartPoints"],
Tooltip = new UiChartTooltip { Enable = true, EnableHighlight = true },
Legend = new UiChartLegend { EnableHighlight = true },
PrimaryXAxis = new UiChartAxis { Interval = 1, ValueType = UiChartValueType.Category },
Series = new List<UiChartSeries>
{
new UiChartSeries { Type = UiChartSeriesType.Polar, Width = 2, XName = "XValue", YName = "YValue", Name = "6-9", DrawType = UiChartDrawType.StackingColumn },
new UiChartSeries { Type = UiChartSeriesType.Polar, Width = 2, XName = "XValue", YName = "YValue1", Name = "9-11", DrawType = UiChartDrawType.StackingColumn },
new UiChartSeries { Type = UiChartSeriesType.Polar, Width = 2, XName = "XValue", YName = "YValue2", Name = "11-14", DrawType = UiChartDrawType.StackingColumn },
new UiChartSeries { Type = UiChartSeriesType.Polar, Width = 2, XName = "XValue", YName = "YValue3", Name = "14-17", DrawType = UiChartDrawType.StackingColumn },
new UiChartSeries { Type = UiChartSeriesType.Polar, Width = 2, XName = "XValue", YName = "YValue4", Name = "17-20", DrawType = UiChartDrawType.StackingColumn },
new UiChartSeries { Type = UiChartSeriesType.Polar, Width = 2, XName = "XValue", YName = "YValue5", Name = "23 Above", DrawType = UiChartDrawType.StackingColumn }
}
})
@Html.UiChart(new UiChartOptions
{
Id = "windRoseChart",
Title = "Wind Rose Chart",
Data = (IEnumerable<object>)ViewData["ChartPoints"],
Tooltip = new UiChartTooltip { Enable = true, EnableHighlight = true },
Legend = new UiChartLegend { EnableHighlight = true },
PrimaryXAxis = new UiChartAxis { Interval = 1, ValueType = UiChartValueType.Category },
Series = new List<UiChartSeries>
{
new UiChartSeries { Type = UiChartSeriesType.Polar, Width = 2, XName = "XValue", YName = "YValue", Name = "6-9", DrawType = UiChartDrawType.StackingColumn },
new UiChartSeries { Type = UiChartSeriesType.Polar, Width = 2, XName = "XValue", YName = "YValue1", Name = "9-11", DrawType = UiChartDrawType.StackingColumn },
new UiChartSeries { Type = UiChartSeriesType.Polar, Width = 2, XName = "XValue", YName = "YValue2", Name = "11-14", DrawType = UiChartDrawType.StackingColumn },
new UiChartSeries { Type = UiChartSeriesType.Polar, Width = 2, XName = "XValue", YName = "YValue3", Name = "14-17", DrawType = UiChartDrawType.StackingColumn },
new UiChartSeries { Type = UiChartSeriesType.Polar, Width = 2, XName = "XValue", YName = "YValue4", Name = "17-20", DrawType = UiChartDrawType.StackingColumn },
new UiChartSeries { Type = UiChartSeriesType.Polar, Width = 2, XName = "XValue", YName = "YValue5", Name = "23 Above", DrawType = UiChartDrawType.StackingColumn }
}
})
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/PolarWindRose.cshtml; it draws what ViewData holds.
public ActionResult PolarWindRose()
{
List<PolarWindRoseData> ChartPoints = new List<PolarWindRoseData>
{
new PolarWindRoseData { XValue = "N", YValue= 1, YValue1= 0.8, YValue2= 0.8, YValue3= 0.3, YValue4= 0.2, YValue5= 0.2 },
new PolarWindRoseData { XValue = "NNE", YValue= 0.9, YValue1= 0.7, YValue2= 0.7, YValue3= 0.3, YValue4= 0.2, YValue5= 0.2 },
new PolarWindRoseData { XValue = "NE", YValue= 0.7, YValue1= 0.8, YValue2= 0.5, YValue3= 1.1, YValue4= 1.2, YValue5= 0.5 },
new PolarWindRoseData { XValue = "ENE", YValue= 0.9, YValue1= 1, YValue2= 0.4, YValue3= 0.9, YValue4= 1, YValue5= 0.4 },
new PolarWindRoseData { XValue = "E", YValue= 0.9, YValue1= 0.6, YValue2= 0.9, YValue3= 0.5, YValue4= 0.7, YValue5= 0.4 },
new PolarWindRoseData { XValue = "ESE", YValue= 0.8, YValue1= 0.5, YValue2= 0.7, YValue3= 0.3, YValue4= 0.8, YValue5= 0.3 },
new PolarWindRoseData { XValue = "SE", YValue= 0.7, YValue1= 0.4, YValue2= 0.6, YValue3= 0.5, YValue4= 0.5, YValue5= 0.3 },
new PolarWindRoseData { XValue = "SSE", YValue= 1.4, YValue1= 0.4, YValue2= 0.5, YValue3= 0.4, YValue4= 0.6, YValue5= 0.2 },
new PolarWindRoseData { XValue = "S", YValue= 2, YValue1= 1.2, YValue2= 0.6, YValue3= 0.6, YValue4= 0.4, YValue5= 0.4 },
new PolarWindRoseData { XValue = "SSW", YValue= 2, YValue1= 2.5, YValue2= 2, YValue3= 1, YValue4= 0.5, YValue5= 0.3 },
new PolarWindRoseData { XValue = "SW", YValue= 2.2, YValue1= 2, YValue2= 1.8, YValue3= 1, YValue4= 0.4, YValue5= 0.2 },
new PolarWindRoseData { XValue = "WSW", YValue= 1.8, YValue1= 1.1, YValue2= 0.8, YValue3= 0.1, YValue4= 0.4, YValue5= 0.2 },
new PolarWindRoseData { XValue = "W", YValue= 1.6, YValue1= 1.8, YValue2= 2.1, YValue3= 1, YValue4= 0.4, YValue5= 0.4 },
new PolarWindRoseData { XValue = "WNW", YValue= 1.2, YValue1= 1.2, YValue2= 1.5, YValue3= 1.3, YValue4= 1.1, YValue5= 1.2 },
new PolarWindRoseData { XValue = "NW", YValue= 2, YValue1= 2.5, YValue2= 2, YValue3= 1, YValue4= 0.2, YValue5= 0.7 },
new PolarWindRoseData { XValue = "NNW", YValue= 1.8, YValue1= 1.1, YValue2= 0.8, YValue3= 0.1, YValue4= 0.4, YValue5= 0.2 }
};
ViewData["ChartPoints"] = ChartPoints;
return View();
}
public class PolarWindRoseData
{
public string XValue { get; set; }
public double YValue { get; set; }
public double YValue1 { get; set; }
public double YValue2 { get; set; }
public double YValue3 { get; set; }
public double YValue4 { get; set; }
public double YValue5 { 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 and configure the polar and radar charts with a stacking column series. Switching between polar and radar series can be done using Series Type in the property panel.
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.