Example of Multi Axis Combination in ASP.NET Core Charts Control
This example draws columns and two lines on three value axes: revenue, orders and margin.
@Html.UiChart(new UiChartOptions
{
Id = "multiAxisChart",
Title = "Revenue, orders and margin",
Data = (IEnumerable<object>)ViewData["ChartData"],
Height = "400px",
Tooltip = new UiChartTooltip { Shared = true },
Legend = new UiChartLegend { Position = UiChartLegendPosition.Top },
PrimaryYAxis = new UiChartAxis { Title = "Revenue", LabelFormat = "N0" },
Axes = new List<UiChartAxis>
{
new UiChartAxis { Name = "orders", Title = "Orders", OpposedPosition = true, LabelFormat = "N0" },
new UiChartAxis { Name = "margin", Title = "Margin %", OpposedPosition = true, LabelFormat = "{value}%", Minimum = 0, Maximum = 40 }
},
Series = new List<UiChartSeries>
{
new UiChartSeries { Type = UiChartSeriesType.Column, XName = "MonthName", YName = "Revenue", Name = "Revenue" },
new UiChartSeries { Type = UiChartSeriesType.Line, XName = "MonthName", YName = "Orders", Name = "Orders", YAxisName = "orders", ShowMarker = true },
new UiChartSeries { Type = UiChartSeriesType.Spline, XName = "MonthName", YName = "Margin", Name = "Margin", YAxisName = "margin", ShowMarker = true }
}
})
@using System.Linq
@using Lumen.UI.Mvc.Demo.Models
@Html.UiChart(new UiChartOptions
{
Id = "multiAxisChart",
Title = "Revenue, orders and margin",
Data = (IEnumerable<object>)ViewData["ChartData"],
Height = "400px",
Tooltip = new UiChartTooltip { Shared = true },
Legend = new UiChartLegend { Position = UiChartLegendPosition.Top },
PrimaryYAxis = new UiChartAxis { Title = "Revenue", LabelFormat = "N0" },
Axes = new List<UiChartAxis>
{
new UiChartAxis { Name = "orders", Title = "Orders", OpposedPosition = true, LabelFormat = "N0" },
new UiChartAxis { Name = "margin", Title = "Margin %", OpposedPosition = true, LabelFormat = "{value}%", Minimum = 0, Maximum = 40 }
},
Series = new List<UiChartSeries>
{
new UiChartSeries { Type = UiChartSeriesType.Column, XName = "MonthName", YName = "Revenue", Name = "Revenue" },
new UiChartSeries { Type = UiChartSeriesType.Line, XName = "MonthName", YName = "Orders", Name = "Orders", YAxisName = "orders", ShowMarker = true },
new UiChartSeries { Type = UiChartSeriesType.Spline, XName = "MonthName", YName = "Margin", Name = "Margin", YAxisName = "margin", ShowMarker = 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/MultiAxisCombination.cshtml; it draws what ViewData holds.
public ActionResult MultiAxisCombination()
{
ViewData["ChartData"] = MonthlySalesData().Select((m, i) => new { m.MonthName, Revenue = m.Online, Orders = (int)(m.Online / 95), Margin = 18 + ((i + 1) * 7 % 11) }).ToList();
return View();
}
/// <summary>The sales of one month per channel: the rows of the Line, Column and Area samples.</summary>
public class SalesData
{
public string MonthName { get; set; }
public double Online { get; set; }
public double Retail { get; set; }
public double Wholesale { get; set; }
public double Target { get; set; }
}
private static List<SalesData> MonthlySalesData()
{
var list = new List<SalesData>();
for (int m = 0; m < 12; m++)
{
list.Add(new SalesData
{
MonthName = new DateTime(2026, 1, 1).AddMonths(m).ToString("MMM"),
Online = 18000 + m * 1400 + (m % 3) * 2100,
Retail = 26000 + (m % 4) * 1800 - m * 300,
Wholesale = 12000 + m * 900 + (m % 2) * 3000,
Target = 60000 + m * 1500
});
}
return list;
}
}
}
@* 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. *@
Three value axes in one chart: revenue (columns, left), orders (line, right) and margin in percent (spline, a second axis on the right). Each axis is declared in Axes and picked by YAxisName.