Example of Polar Column in ASP.NET Core Charts Control
This sample shows the top 10 mobile markets by the number of subscriptions in polar and radar charts using column series.
${text}
${series} : ${y}
${series} : ${y}
@Html.UiChart(new UiChartOptions
{
Id = "polarColumnChart",
Title = "Top 10 Mobile Markets by Number of Subscriptions",
Data = (IEnumerable<object>)ViewData["ChartPoints"],
Tooltip = new UiChartTooltip { Enable = true, EnableHighlight = true, Template = "#tipPolarColumn" },
Legend = new UiChartLegend { EnableHighlight = true },
PrimaryXAxis = new UiChartAxis { ValueType = UiChartValueType.Category, Interval = 1 },
PrimaryYAxis = new UiChartAxis { LabelFormat = "{value}M" },
Series = new List<UiChartSeries>
{
new UiChartSeries { Type = UiChartSeriesType.Polar, Width = 2, XName = "Country", YName = "Population", Name = "Population", DrawType = UiChartDrawType.Column },
new UiChartSeries { Type = UiChartSeriesType.Polar, Width = 2, XName = "Country", YName = "MobileSubscriber", Name = "Mobile Subscriptions", DrawType = UiChartDrawType.Column },
new UiChartSeries { Type = UiChartSeriesType.Polar, Width = 2, XName = "Country", YName = "NetworkSubscriber", Name = "3G/4G Subscriptions", DrawType = UiChartDrawType.Column }
}
})
<template id="tipPolarColumn"><b>${text}</b> <br> ${series} : <b>${y}</b></template>
@Html.UiChart(new UiChartOptions
{
Id = "polarColumnChart",
Title = "Top 10 Mobile Markets by Number of Subscriptions",
Data = (IEnumerable<object>)ViewData["ChartPoints"],
Tooltip = new UiChartTooltip { Enable = true, EnableHighlight = true, Template = "#tipPolarColumn" },
Legend = new UiChartLegend { EnableHighlight = true },
PrimaryXAxis = new UiChartAxis { ValueType = UiChartValueType.Category, Interval = 1 },
PrimaryYAxis = new UiChartAxis { LabelFormat = "{value}M" },
Series = new List<UiChartSeries>
{
new UiChartSeries { Type = UiChartSeriesType.Polar, Width = 2, XName = "Country", YName = "Population", Name = "Population", DrawType = UiChartDrawType.Column },
new UiChartSeries { Type = UiChartSeriesType.Polar, Width = 2, XName = "Country", YName = "MobileSubscriber", Name = "Mobile Subscriptions", DrawType = UiChartDrawType.Column },
new UiChartSeries { Type = UiChartSeriesType.Polar, Width = 2, XName = "Country", YName = "NetworkSubscriber", Name = "3G/4G Subscriptions", DrawType = UiChartDrawType.Column }
}
})
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/PolarColumn.cshtml; it draws what ViewData holds.
public ActionResult PolarColumn()
{
List<PolarColumnData> ChartPoints = new List<PolarColumnData>
{
new PolarColumnData { TooltipMappingName= "Japan", Country = "Japan", MobileSubscriber = 137.9, Population = 127.6, NetworkSubscriber = 108.8 },
new PolarColumnData { TooltipMappingName= "Indonesia", Country = "Indonesia", MobileSubscriber = 85.0, Population = 246.9, NetworkSubscriber = 45.5 },
new PolarColumnData { TooltipMappingName= "Russia", Country = "Russia", MobileSubscriber = 237.1, Population = 143.5, NetworkSubscriber = 41.2 },
new PolarColumnData { TooltipMappingName= "Vietnam", Country = "Vietnam", MobileSubscriber = 127.7, Population = 88.8, NetworkSubscriber = 18.0 },
new PolarColumnData { TooltipMappingName= "Pakistan", Country = "Pakistan", MobileSubscriber = 126.1, Population = 179.2 },
new PolarColumnData { TooltipMappingName= "Nigeria", Country = "Nigeria", MobileSubscriber = 175.0, Population = 168.8, NetworkSubscriber = 12.7 },
new PolarColumnData { TooltipMappingName= "Germany", Country = "Germany", MobileSubscriber = 113.6, Population = 81.9, NetworkSubscriber = 46.0 },
new PolarColumnData { TooltipMappingName= "Bangladesh", Country = "Bangladesh", MobileSubscriber = 116.0, Population = 154.7, NetworkSubscriber = 34.6 },
new PolarColumnData { TooltipMappingName= "Philippines", Country = "Philippines", MobileSubscriber = 109.5, Population = 96.7, NetworkSubscriber = 16.6 },
new PolarColumnData { TooltipMappingName= "Mexico", Country = "Mexico", MobileSubscriber = 102.7, Population = 120.8, NetworkSubscriber = 19.8 }
};
ViewData["ChartPoints"] = ChartPoints;
ViewData["data"] = new string[] { "Polar", "Radar" };
return View();
}
public class PolarColumnData
{
public string TooltipMappingName { get; set; }
public string Country { get; set; }
public double MobileSubscriber { get; set; }
public double Population { get; set; }
public double NetworkSubscriber { 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 a 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 a point or tap on a point in touch enabled devices.