Example of Pie with Various Radius in ASP.NET MVC Charts Control
This Pie Chart example gives each slice its own radius, while the angle of a slice still follows its value.
@Html.UiChart(new UiChartOptions
{
Id = "variousRadiusChart",
Title = "Sales and satisfaction by region",
Data = (IEnumerable<object>)ViewData["ChartData"],
Height = "420px",
Legend = new UiChartLegend { Position = UiChartLegendPosition.Right },
Series = new List<UiChartSeries>
{
new UiChartSeries { Type = UiChartSeriesType.Pie, XName = "Region", YName = "Sales", Name = "Sales", Radius = "70%", RadiusMapping = "Satisfaction", ShowDataLabel = true }
}
})
@using System.Linq
@Html.UiChart(new UiChartOptions
{
Id = "variousRadiusChart",
Title = "Sales and satisfaction by region",
Data = (IEnumerable<object>)ViewData["ChartData"],
Height = "420px",
Legend = new UiChartLegend { Position = UiChartLegendPosition.Right },
Series = new List<UiChartSeries>
{
new UiChartSeries { Type = UiChartSeriesType.Pie, XName = "Region", YName = "Sales", Name = "Sales", Radius = "70%", RadiusMapping = "Satisfaction", ShowDataLabel = true }
}
})
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/PieVariousRadius.cshtml; it draws what ViewData holds.
public ActionResult PieVariousRadius()
{
ViewData["ChartData"] = new[]
{
new { Region = "Luzon", Sales = 60300, Satisfaction = 92 }, new { Region = "Visayas", Sales = 36900, Satisfaction = 74 },
new { Region = "Mindanao", Sales = 28700, Satisfaction = 58 }, new { Region = "Metro Manila", Sales = 70400, Satisfaction = 100 },
new { Region = "Palawan", Sales = 12100, Satisfaction = 81 }
}.ToList();
return View();
}
}
}
@* 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. *@
RadiusMapping names the row field with the radius of each slice (a percentage of Radius). The angle of a slice still follows its value, so area and reach tell two different things.