Example of Secondary Axis and Filters in ASP.NET MVC Charts Control
This example draws the amount and the number of orders on two axes, and reloads them from the server with a date range and a shipped filter.
@Html.AntiForgeryToken()
@Html.UiChart(new UiChartOptions
{
Id = "ordersChart",
Title = "Orders per month",
DataUrl = Url.Action("MonthlyOrders", "ChartDemo"),
DataUrlParams = new { from = new DateTime(2026, 1, 1), to = new DateTime(2026, 8, 31), shippedOnly = false },
Tooltip = new UiChartTooltip { Shared = true },
PrimaryYAxis = new UiChartAxis { Title = "Amount", LabelFormat = "C0" },
Axes = new List<UiChartAxis>
{
new UiChartAxis { Name = "orders", Title = "Orders", OpposedPosition = true, LabelFormat = "N0" }
},
Currency = "PHP",
OnLoaded = "ChartDemo.onLoaded",
Series = new List<UiChartSeries>
{
new UiChartSeries { Type = UiChartSeriesType.Column, XName = "Month", YName = "Amount", Name = "Amount" },
new UiChartSeries { Type = UiChartSeriesType.Line, XName = "Month", YName = "Orders", Name = "Orders", YAxisName = "orders", ShowMarker = true }
}
})
@Html.AntiForgeryToken()
<form class="row g-2 align-items-end mb-2" onsubmit="ChartDemo.filterOrders(); return false;">
<div class="col-auto"><label class="form-label small mb-0" for="ordersFrom">From</label><input id="ordersFrom" type="date" class="form-control form-control-sm" value="2026-01-01"></div>
<div class="col-auto"><label class="form-label small mb-0" for="ordersTo">To</label><input id="ordersTo" type="date" class="form-control form-control-sm" value="2026-08-31"></div>
<div class="col-auto form-check ms-2"><input id="ordersShipped" type="checkbox" class="form-check-input"><label class="form-check-label small" for="ordersShipped">Shipped only</label></div>
<div class="col-auto"><button type="submit" class="btn btn-primary btn-sm">Apply</button></div>
<div class="col-auto"><button type="button" class="btn btn-outline-secondary btn-sm" onclick="Lumen.get('ordersChart').print()">Print</button></div>
</form>
@Html.UiChart(new UiChartOptions
{
Id = "ordersChart",
Title = "Orders per month",
DataUrl = Url.Action("MonthlyOrders", "ChartDemo"),
DataUrlParams = new { from = new DateTime(2026, 1, 1), to = new DateTime(2026, 8, 31), shippedOnly = false },
Tooltip = new UiChartTooltip { Shared = true },
PrimaryYAxis = new UiChartAxis { Title = "Amount", LabelFormat = "C0" },
Axes = new List<UiChartAxis>
{
new UiChartAxis { Name = "orders", Title = "Orders", OpposedPosition = true, LabelFormat = "N0" }
},
Currency = "PHP",
OnLoaded = "ChartDemo.onLoaded",
Series = new List<UiChartSeries>
{
new UiChartSeries { Type = UiChartSeriesType.Column, XName = "Month", YName = "Amount", Name = "Amount" },
new UiChartSeries { Type = UiChartSeriesType.Line, XName = "Month", YName = "Orders", Name = "Orders", YAxisName = "orders", ShowMarker = true }
}
})
@section below {
<h3>Event log</h3>
<ul id="eventLog" style="font-family:monospace;font-size:12px;max-height:200px;overflow-y:auto;border:1px solid var(--ui-border, #dadce3);padding:8px;"></ul>
}
@section scripts {
<script>
window.ChartDemo = (function () {
'use strict';
function log(message) {
var list = document.getElementById('eventLog');
if (!list) { return; }
var item = document.createElement('li');
item.textContent = new Date().toLocaleTimeString() + ' - ' + message;
list.insertBefore(item, list.firstChild);
}
return {
onLoaded: function (rows, chartId) {
log(chartId + ': loaded ' + rows.length + ' row(s)');
},
filterOrders: function () {
var params = {
from: document.getElementById('ordersFrom').value || null,
to: document.getElementById('ordersTo').value || null,
shippedOnly: document.getElementById('ordersShipped').checked
};
log('ordersChart: reload(' + JSON.stringify(params) + ')');
Lumen.get('ordersChart').reload(params);
}
};
})();
</script>
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web.Mvc;
using Lumen.UI.Mvc;
using Lumen.UI.Mvc.Demo.Models;
// With a DataUrl the chart POSTs JSON and accepts a plain array of rows or { result: [...] }.
namespace Lumen.UI.Mvc.Demo.Controllers
{
/// <summary>Separately navigable chart samples and their data endpoints.</summary>
public partial class ChartDemoController : Controller
{
/// <summary>
/// Chart DataUrl with filters: the chart posts its DataUrlParams (or reload(params)) as JSON, and
/// MVC binds them to these parameters. Totals and order counts per month.
/// </summary>
[HttpPost]
[ValidateJsonAntiForgeryToken]
public ActionResult MonthlyOrders(DateTime? from, DateTime? to, bool shippedOnly = false)
{
lock (SampleOrders.Sync)
{
var months = SampleOrders.All
.Where(o => (!from.HasValue || o.OrderDate >= from.Value.Date) &&
(!to.HasValue || o.OrderDate <= to.Value.Date) &&
(!shippedOnly || o.Shipped))
.GroupBy(o => new DateTime(o.OrderDate.Year, o.OrderDate.Month, 1))
.OrderBy(g => g.Key)
.Select(g => new { Month = g.Key.ToString("MMM yyyy"), Amount = g.Sum(o => o.Amount), Orders = g.Count() })
.ToList();
return Json(new { result = months });
}
}
}
}
namespace Lumen.UI.Mvc.Demo.Models
{
public class Order
{
public int Id { get; set; }
public string OrderNo { get; set; }
public DateTime OrderDate { get; set; }
public string Customer { get; set; }
/// <summary>Key of the customer (see SampleOrders.Customers), to show a foreign key column.</summary>
public int CustomerId { get; set; }
/// <summary>North, South, East or West: a column with few values, to show grouping and a dropdown editor.</summary>
public string Region { get; set; }
public decimal Amount { get; set; }
public bool Shipped { get; set; }
/// <summary>Long free text, to show text wrapping in the grid.</summary>
public string Notes { get; set; }
}
}
namespace Lumen.UI.Mvc.Demo.Models
{
/// <summary>In-memory test data for the grid and chart demos. A real app would query a database instead.</summary>
public static class SampleOrders
{
/// <summary>Lock held while reading or changing <see cref="All"/> (the grid demo edits it).</summary>
public static readonly object Sync = new object();
private static readonly string[] Customers =
{
"Santos Trading", "Reyes Hardware", "Dela Cruz Foods", "Bautista Auto Parts",
"Garcia Textiles", "Mendoza Electronics", "Torres Logistics", "Flores Bakery"
};
// Long notes to show text wrapping; some contain one very long word (a part number without spaces),
// which is broken inside the word only because it is wider than the column.
private static readonly string[] Notes =
{
"Deliver to the back entrance before 10 AM; the front gate is closed on weekends and public holidays.",
"Customer asked for partial delivery: send the available items now and the rest when back in stock.",
"Replacement part PN-XJ9000-ULTRAHEAVYDUTY-STAINLESSSTEELFLANGEASSEMBLY-REV7 must be checked before shipping.",
"Fragile.",
"Invoice must show the purchase order number, the project code and the name of the receiving warehouse.",
"Supercalifragilisticexpialidociousnessmaximizationprogramme discount applied at checkout.",
"Call the site supervisor thirty minutes before arrival so the loading bay can be cleared.",
"Standard delivery."
};
/// <summary>The values of Order.Region: the grouping demo's groups and the dropdown editor's choices.</summary>
public static readonly string[] Regions = { "North", "South", "East", "West" };
public static readonly List<Order> All = Build();
private static List<Order> Build()
{
var orders = new List<Order>();
var start = new DateTime(2026, 1, 5);
for (int i = 1; i <= 57; i++)
{
orders.Add(new Order
{
Id = i,
OrderNo = "SO-" + (10000 + i),
OrderDate = start.AddDays(i * 3 % 240),
Customer = Customers[i % Customers.Length],
CustomerId = i % Customers.Length + 1,
Region = Regions[i * 7 % Regions.Length],
Amount = 500m + (i * 137 % 4500),
Shipped = i % 3 != 0,
Notes = Notes[i % Notes.Length]
});
}
return orders;
}
}
}
@* 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. *@
The amount uses the primary axis (left, C0); the order count uses an axis from Axes (Name = "orders", OpposedPosition = true), picked by YAxisName. Fields below call chart.reload({ from, to, shippedOnly }), replacing DataUrlParams.