Skip to content
IzzyBlazor

Enter all results ↑ ↓ move Esc close

Drill-down

Since 0.1.0-alpha.22
Bars, slices and tiles that open the level below them, such as a year's months, with the level in the page's address.

Revenue by year, month and day

To drill into a chart, put a ChartDrillLevel in it for each level, from the top, in place of the chart's Argument. Select a year's bar to see its months, and a month's to see its days.

Static

Preview

Revenue
Arrow keys move between values; Escape hides the tooltip. Enter opens the level below.

Code

DrillRevenue.razor
@* A store's revenue by year, then month, then day: each bar opens the level below it, and the
   breadcrumb goes back up. The level is in the page's address, so it works with no script. *@
<Chart id="store-revenue" Items="_orders" Title="Revenue" Drill="revenue">
    <ChartDrillLevel Argument="o => o.Date.Year" Name="Year" />
    <ChartDrillLevel Argument='o => o.Date.ToString("MMM")' Name="Month" />
    <ChartDrillLevel Argument="o => o.Date.Day" Name="Day" />
    <ChartValueAxis Format="C0" />
    <ChartBarSeries Value="o => o.Total" Name="Revenue" />
</Chart>

@code {
    private record Order(DateOnly Date, decimal Total);

    // Three years of a web store's orders, one row a day: more each year, a summer dip, and the
    // holidays' peak in late November and December.
    private static readonly Order[] _orders = Enumerable.Range(0, 3 * 365).Select(i =>
    {
        var date = new DateOnly(2024, 1, 1).AddDays(i);
        var season = date.Month switch { 11 => 1.45m, 12 => 1.6m, 7 or 8 => 0.85m, _ => 1m };
        var weekend = date.DayOfWeek is DayOfWeek.Saturday or DayOfWeek.Sunday ? 0.8m : 1m;
        return new Order(date, Math.Round((4200 + i * 3.1m + i * 37 % 29 * 41) * season * weekend));
    }).ToArray();
}

The chart groups its items by each level's argument and adds up every series. Aggregate on a series sets how: Sum by default, or Avg, Min, Max or Count.

The level is in the page's address, here ?revenue=2025&revenue=Nov, so a level can be bookmarked and the browser's Back goes up one. Drill names the address's key; give each chart that drills on a page its own.

From the keyboard, move to an item and press Enter: the plot keeps focus and says the new level. The data table's first column links each item to its level, with or without script. The breadcrumb links back up.

PieChart, FunnelChart and TreemapChart drill the same way.

Connection lost

Rejoining the server…