Example of Polar Stacked Area in ASP.NET MVC Charts Control
This sample shows GDP growth of various countries for a few years in the polar and radar charts using the stacked area series.
${x}
GDP: ${y}USD
GDP: ${y}USD
@Html.UiChart(new UiChartOptions
{
Id = "polarStackedAreaChart",
Title = "GDP in current prices (USD Billion)",
Data = (IEnumerable<object>)ViewData["ChartPoints"],
Tooltip = new UiChartTooltip { Enable = true, EnableHighlight = true, Template = "#tipPolarStackedArea" },
Legend = new UiChartLegend { EnableHighlight = true },
PrimaryXAxis = new UiChartAxis { ValueType = UiChartValueType.Category, Interval = 1 },
Series = new List<UiChartSeries>
{
new UiChartSeries { Type = UiChartSeriesType.Polar, Width = 2, XName = "Country", YName = "GDP_2013", Name = "2013", DrawType = UiChartDrawType.StackingArea },
new UiChartSeries { Type = UiChartSeriesType.Polar, Width = 2, XName = "Country", YName = "GDP_2014", Name = "2014", DrawType = UiChartDrawType.StackingArea },
new UiChartSeries { Type = UiChartSeriesType.Polar, Width = 2, XName = "Country", YName = "GDP_2015", Name = "2015", DrawType = UiChartDrawType.StackingArea },
new UiChartSeries { Type = UiChartSeriesType.Polar, Width = 2, XName = "Country", YName = "GDP_2016", Name = "2016", DrawType = UiChartDrawType.StackingArea }
}
})
<template id="tipPolarStackedArea"><b>${x}</b><br>GDP: <b>${y}USD</b></template>
@Html.UiChart(new UiChartOptions
{
Id = "polarStackedAreaChart",
Title = "GDP in current prices (USD Billion)",
Data = (IEnumerable<object>)ViewData["ChartPoints"],
Tooltip = new UiChartTooltip { Enable = true, EnableHighlight = true, Template = "#tipPolarStackedArea" },
Legend = new UiChartLegend { EnableHighlight = true },
PrimaryXAxis = new UiChartAxis { ValueType = UiChartValueType.Category, Interval = 1 },
Series = new List<UiChartSeries>
{
new UiChartSeries { Type = UiChartSeriesType.Polar, Width = 2, XName = "Country", YName = "GDP_2013", Name = "2013", DrawType = UiChartDrawType.StackingArea },
new UiChartSeries { Type = UiChartSeriesType.Polar, Width = 2, XName = "Country", YName = "GDP_2014", Name = "2014", DrawType = UiChartDrawType.StackingArea },
new UiChartSeries { Type = UiChartSeriesType.Polar, Width = 2, XName = "Country", YName = "GDP_2015", Name = "2015", DrawType = UiChartDrawType.StackingArea },
new UiChartSeries { Type = UiChartSeriesType.Polar, Width = 2, XName = "Country", YName = "GDP_2016", Name = "2016", DrawType = UiChartDrawType.StackingArea }
}
})
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/PolarStackedArea.cshtml; it draws what ViewData holds.
public ActionResult PolarStackedArea()
{
List<PolarStackedAreaData> ChartPoints = new List<PolarStackedAreaData>
{
new PolarStackedAreaData { Country = "Japan", GDP_2013 = 5156, GDP_2014 = 4849, GDP_2015 = 4382, GDP_2016 = 4939 },
new PolarStackedAreaData { Country = "Germany", GDP_2013 = 3754, GDP_2014 = 3885, GDP_2015 = 3365, GDP_2016 = 3467 },
new PolarStackedAreaData { Country = "France", GDP_2013 = 2809, GDP_2014 = 2844, GDP_2015 = 2420, GDP_2016 = 2463 },
new PolarStackedAreaData { Country = "United Kingdom", GDP_2013 = 2721, GDP_2014 = 3002, GDP_2015 = 2863, GDP_2016 = 2629 },
new PolarStackedAreaData { Country = "Brazil", GDP_2013 = 2472, GDP_2014 = 2456, GDP_2015 = 1801, GDP_2016 = 1799 },
new PolarStackedAreaData { Country = "Russia", GDP_2013 = 2231, GDP_2014 = 2064, GDP_2015 = 1366, GDP_2016 = 1281 },
new PolarStackedAreaData { Country = "Italy", GDP_2013 = 2131, GDP_2014 = 2155, GDP_2015 = 1826, GDP_2016 = 1851 },
new PolarStackedAreaData { Country = "India", GDP_2013 = 1857, GDP_2014 = 2034, GDP_2015 = 2088, GDP_2016 = 2256 },
new PolarStackedAreaData { Country = "Canada", GDP_2013 = 1843, GDP_2014 = 1793, GDP_2015 = 1553, GDP_2016 = 1529 }
};
ViewData["ChartPoints"] = ChartPoints;
ViewData["data"] = new string[]{ "Polar", "Radar"};
return View();
}
public class PolarStackedAreaData
{
public string Country { get; set; }
public double GDP_2013 { get; set; }
public double GDP_2014 { get; set; }
public double GDP_2015 { get; set; }
public double GDP_2016 { 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 polar and radar charts with stacking 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.