Example of Radar Chart in ASP.NET Core Charts Control
This sample shows the average product sales comparison for 6 years in polar and radar charts.
@* 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 = "radarChart",
Title = "Average Sales Comparison",
Data = (IEnumerable<object>)ViewData["ChartPoints"],
Tooltip = new UiChartTooltip { Enable = true, EnableHighlight = true },
Legend = new UiChartLegend { EnableHighlight = true },
PrimaryXAxis = new UiChartAxis { ValueType = UiChartValueType.Category, Interval = 1 },
PrimaryYAxis = new UiChartAxis { Title = "Revenue in Millios", LabelFormat = "{value}M" },
Series = new List<UiChartSeries>
{
new UiChartSeries { Type = UiChartSeriesType.Polar, Width = 2, XName = "Period", YName = "ProductRevenue_A", Name = "Product A", DrawType = UiChartDrawType.Area, Opacity = 0.5 },
new UiChartSeries { Type = UiChartSeriesType.Polar, Width = 2, XName = "Period", YName = "ProductRevenue_B", Name = "Product B", DrawType = UiChartDrawType.Area, Opacity = 0.5 },
new UiChartSeries { Type = UiChartSeriesType.Polar, Width = 2, XName = "Period", YName = "ProductRevenue_C", Name = "Product C", DrawType = UiChartDrawType.Area, Opacity = 0.5 }
}
})
@Html.UiChart(new UiChartOptions
{
Id = "radarChart",
Title = "Average Sales Comparison",
Data = (IEnumerable<object>)ViewData["ChartPoints"],
Tooltip = new UiChartTooltip { Enable = true, EnableHighlight = true },
Legend = new UiChartLegend { EnableHighlight = true },
PrimaryXAxis = new UiChartAxis { ValueType = UiChartValueType.Category, Interval = 1 },
PrimaryYAxis = new UiChartAxis { Title = "Revenue in Millios", LabelFormat = "{value}M" },
Series = new List<UiChartSeries>
{
new UiChartSeries { Type = UiChartSeriesType.Polar, Width = 2, XName = "Period", YName = "ProductRevenue_A", Name = "Product A", DrawType = UiChartDrawType.Area, Opacity = 0.5 },
new UiChartSeries { Type = UiChartSeriesType.Polar, Width = 2, XName = "Period", YName = "ProductRevenue_B", Name = "Product B", DrawType = UiChartDrawType.Area, Opacity = 0.5 },
new UiChartSeries { Type = UiChartSeriesType.Polar, Width = 2, XName = "Period", YName = "ProductRevenue_C", Name = "Product C", DrawType = UiChartDrawType.Area, Opacity = 0.5 }
}
})
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/RadarChart.cshtml; it draws what ViewData holds.
public ActionResult RadarChart()
{
List<PolarAreaChartData> ChartPoints = new List<PolarAreaChartData>
{
new PolarAreaChartData { Period = "2000", ProductRevenue_A = 4 , ProductRevenue_B = 2.6, ProductRevenue_C = 2.8},
new PolarAreaChartData { Period = "2001", ProductRevenue_A = 3.0, ProductRevenue_B = 2.8, ProductRevenue_C = 2.5 },
new PolarAreaChartData { Period = "2002", ProductRevenue_A = 3.8, ProductRevenue_B = 2.6, ProductRevenue_C = 2.8 },
new PolarAreaChartData { Period = "2003", ProductRevenue_A = 3.4, ProductRevenue_B = 3 , ProductRevenue_C = 3.2 },
new PolarAreaChartData { Period = "2004", ProductRevenue_A = 3.2, ProductRevenue_B = 3.6, ProductRevenue_C = 2.9 },
new PolarAreaChartData { Period = "2005", ProductRevenue_A = 3.9, ProductRevenue_B = 3 , ProductRevenue_C = 2 }
};
ViewData["ChartPoints"] = ChartPoints;
ViewData["data"] = new string[] { "Polar", "Radar" };
return View();
}
public class PolarAreaChartData
{
public string Period { get; set; }
public double ProductRevenue_A { get; set; }
public double ProductRevenue_B { get; set; }
public double ProductRevenue_C { 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 polar and radar charts with an area 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 a point or tap on a point in touch enabled devices.