Example of Polar Scatter in ASP.NET Core Charts Control
This sample shows GDP growth of different countries for a few years in the polar and radar charts using the scatter series.
${x}
GDP: ${y}%
GDP: ${y}%
@Html.UiChart(new UiChartOptions
{
Id = "polarScatterChart",
Title = "GDP by Countries",
Data = (IEnumerable<object>)ViewData["Chartpoints"],
Tooltip = new UiChartTooltip { Enable = true, EnableHighlight = true, Template = "#tipPolarScatter" },
Legend = new UiChartLegend { EnableHighlight = true },
PrimaryXAxis = new UiChartAxis { ValueType = UiChartValueType.Category, Interval = 1 },
PrimaryYAxis = new UiChartAxis { Interval = 2, Minimum = 0, Maximum = 8 },
Series = new List<UiChartSeries>
{
new UiChartSeries { Type = UiChartSeriesType.Polar, Width = 2, XName = "Country", YName = "GDP_2013", Name = "2015", DrawType = UiChartDrawType.Scatter, Marker = new UiChartMarker { Height = 7, Width = 7 } },
new UiChartSeries { Type = UiChartSeriesType.Polar, Width = 2, XName = "Country", YName = "GDP_2014", Name = "2016", DrawType = UiChartDrawType.Scatter, Marker = new UiChartMarker { Height = 7, Width = 7, Shape = UiChartMarkerShape.Diamond } },
new UiChartSeries { Type = UiChartSeriesType.Polar, Width = 2, XName = "Country", YName = "GDP_2015", Name = "2017", DrawType = UiChartDrawType.Scatter, Marker = new UiChartMarker { Height = 7, Width = 7, Shape = UiChartMarkerShape.Triangle } }
}
})
<template id="tipPolarScatter"><b>${x}</b> <br>GDP: <b>${y}%</b></template>
@Html.UiChart(new UiChartOptions
{
Id = "polarScatterChart",
Title = "GDP by Countries",
Data = (IEnumerable<object>)ViewData["Chartpoints"],
Tooltip = new UiChartTooltip { Enable = true, EnableHighlight = true, Template = "#tipPolarScatter" },
Legend = new UiChartLegend { EnableHighlight = true },
PrimaryXAxis = new UiChartAxis { ValueType = UiChartValueType.Category, Interval = 1 },
PrimaryYAxis = new UiChartAxis { Interval = 2, Minimum = 0, Maximum = 8 },
Series = new List<UiChartSeries>
{
new UiChartSeries { Type = UiChartSeriesType.Polar, Width = 2, XName = "Country", YName = "GDP_2013", Name = "2015", DrawType = UiChartDrawType.Scatter, Marker = new UiChartMarker { Height = 7, Width = 7 } },
new UiChartSeries { Type = UiChartSeriesType.Polar, Width = 2, XName = "Country", YName = "GDP_2014", Name = "2016", DrawType = UiChartDrawType.Scatter, Marker = new UiChartMarker { Height = 7, Width = 7, Shape = UiChartMarkerShape.Diamond } },
new UiChartSeries { Type = UiChartSeriesType.Polar, Width = 2, XName = "Country", YName = "GDP_2015", Name = "2017", DrawType = UiChartDrawType.Scatter, Marker = new UiChartMarker { Height = 7, Width = 7, Shape = UiChartMarkerShape.Triangle } }
}
})
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/PolarScatter.cshtml; it draws what ViewData holds.
public ActionResult PolarScatter()
{
List<PolarScatterData> Chartpoints = new List<PolarScatterData>
{
new PolarScatterData { TooltipMappingName= "Myanmar", Country = "Myanmar", GDP_2013 = 7.3, GDP_2014 = 6.3, GDP_2015 = 7.5 },
new PolarScatterData { TooltipMappingName= "India", Country = "India", GDP_2013 = 7.9, GDP_2014 = 6.8, GDP_2015 = 7.2 },
new PolarScatterData { TooltipMappingName= "Bangladesh", Country = "Bangladesh", GDP_2013 = 6.8, GDP_2014 = 6.9, GDP_2015 = 6.9 },
new PolarScatterData { TooltipMappingName= "Cambodia", Country = "Cambodia", GDP_2013 = 7.0, GDP_2014 = 7.0, GDP_2015 = 6.9 },
new PolarScatterData { TooltipMappingName= "China", Country = "China", GDP_2013 = 6.9, GDP_2014 = 6.7, GDP_2015 = 6.6 },
new PolarScatterData { TooltipMappingName= "Bhutan", Country = "Bhutan", GDP_2013 = 6.1, GDP_2014 = 6.2, GDP_2015 = 5.9 },
new PolarScatterData { TooltipMappingName= "Iceland", Country = "Iceland", GDP_2013 = 4.1, GDP_2014 = 7.2, GDP_2015 = 5.7 },
new PolarScatterData { TooltipMappingName= "Nepal", Country = "Nepal", GDP_2013 = 2.7, GDP_2014 = 0.6, GDP_2015 = 5.5 },
new PolarScatterData { TooltipMappingName= "Pakistan", Country = "Pakistan", GDP_2013 = 4.0, GDP_2014 = 4.7, GDP_2015 = 5.0 },
new PolarScatterData { TooltipMappingName= "Poland", Country = "Poland", GDP_2013 = 3.9, GDP_2014 = 2.7, GDP_2015 = 3.4 },
new PolarScatterData { TooltipMappingName= "Australia", Country = "Australia", GDP_2013 = 2.4, GDP_2014 = 2.5, GDP_2015 = 3.1 },
new PolarScatterData { TooltipMappingName= "Korea", Country = "Korea", GDP_2013 = 2.8, GDP_2014 = 2.8, GDP_2015 = 2.7 },
new PolarScatterData { TooltipMappingName= "Singapore", Country = "Singapore", GDP_2013 = 1.9, GDP_2014 = 2.0, GDP_2015 = 2 },
new PolarScatterData { TooltipMappingName= "Canada", Country = "Canada", GDP_2013 = 0.9, GDP_2014 = 1.4, GDP_2015 = 1.9 },
new PolarScatterData { TooltipMappingName= "Germany", Country = "Germany", GDP_2013 = 1.5, GDP_2014 = 1.8, GDP_2015 = 1.6 },
new PolarScatterData { TooltipMappingName= "Denmark", Country = "Denmark", GDP_2013 = 1.6, GDP_2014 = 1.1, GDP_2015 = 1.5 },
new PolarScatterData { TooltipMappingName= "France", Country = "France", GDP_2013 = 1.3, GDP_2014 = 1.3, GDP_2015 = 1.4 },
new PolarScatterData { TooltipMappingName= "Austria", Country = "Austria", GDP_2013 = 1.0, GDP_2014 = 1.5, GDP_2015 = 1.4 }
};
ViewData["Chartpoints"] = Chartpoints;
ViewData["data"] = new string[] {"Polar", "Radar" };
return View();
}
public class PolarScatterData
{
public string TooltipMappingName { get; set; }
public string Country { get; set; }
public double GDP_2013 { get; set; }
public double GDP_2014 { get; set; }
public double GDP_2015 { 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 scatter series. Switching between polar and radar series can be done using the 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.