Example of Pyramid Chart in ASP.NET Core Charts Control
This Pyramid Chart example shows the same stages as a pyramid, with gaps between the segments.
@* 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 = "pyramidChart",
Title = "Website visitors",
Data = (IEnumerable<object>)ViewData["ChartData"],
Height = "380px",
Series = new List<UiChartSeries>
{
new UiChartSeries { Type = UiChartSeriesType.Pyramid, XName = "Stage", YName = "Count", Name = "Visitors", ShowDataLabel = true, GapRatio = 0.03 }
}
})
@Html.UiChart(new UiChartOptions
{
Id = "pyramidChart",
Title = "Website visitors",
Data = (IEnumerable<object>)ViewData["ChartData"],
Height = "380px",
Series = new List<UiChartSeries>
{
new UiChartSeries { Type = UiChartSeriesType.Pyramid, XName = "Stage", YName = "Count", Name = "Visitors", ShowDataLabel = true, GapRatio = 0.03 }
}
})
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/PyramidChart.cshtml; it draws what ViewData holds.
public ActionResult PyramidChart()
{
ViewData["ChartData"] = FunnelStages();
return View();
}
/// <summary>One stage of the visitors' way: the rows of the Funnel and Pyramid samples.</summary>
public class FunnelData
{
public string Stage { get; set; }
public int Count { get; set; }
}
private static List<FunnelData> FunnelStages()
{
return new List<FunnelData>
{
new FunnelData { Stage = "Renewed", Count = 182 },
new FunnelData { Stage = "Subscribed", Count = 273 },
new FunnelData { Stage = "Support", Count = 559 },
new FunnelData { Stage = "Downloaded", Count = 768 },
new FunnelData { Stage = "Visited", Count = 1000 }
};
}
}
}
@* 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. *@
The first point at the top. PyramidMode = Surface would make areas, not heights, follow values.