Skip to content
IzzyBlazor

Enter all results ↑ ↓ move Esc close

RangeSelector

Since 0.1.0-alpha.22
Chooses a span of dates, numbers or names on a strip that draws the whole range small: on its own it picks a range to filter by, and as ChartRangeSelector it zooms a chart.

A range selector is a strip that draws a whole range small, such as a year of days, with a window over the part chosen. It suits long runs of dates, where the reader looks closer at a month and needs to see where it sits in the year. To pick a range of plain numbers, such as prices, use a RangeSlider; for two dates typed or picked from a calendar, a DateRangeField.

A strip under a chart

In an upright Chart, put <ChartRangeSelector /> after the series. The strip sits under the plot and draws the chart's series small, and the window is the part of the chart in view. Dragging the window pans the chart, and dragging a handle widens or narrows it.

Static

Preview

Daily high temperature, Chicago, 2023 to 2025
Arrow keys move between values; plus and minus zoom, 0 zooms out; Escape hides the tooltip.

Code

Usage.razor
@* Three years of daily highs, opening on the last three months: the plot shows the days, and
   the strip the seasons around them. *@
<Chart Items="_days" Argument="d => d.Date" Title="Daily high temperature, Chicago, 2023 to 2025" View="_lastQuarter">
    <ChartValueAxis Format="0'°F'" />
    <ChartLineSeries Value="d => d.High" Name="High" />
    <ChartRangeSelector />
</Chart>

@code {
    private record Day(DateOnly Date, double High);

    private readonly ChartView _lastQuarter = new(new DateOnly(2025, 10, 1), null);

    private readonly Day[] _days = Highs();

    // A seasonal curve (coldest in late January, warmest in late July) and weather that lasts a
    // few days: each day's departure from normal carries over from the day before.
    private static Day[] Highs()
    {
        var random = new Random(11);
        var first = new DateOnly(2023, 1, 1);
        var departure = 0.0;
        return Enumerable.Range(0, new DateOnly(2025, 12, 31).DayNumber - first.DayNumber + 1).Select(i =>
        {
            var date = first.AddDays(i);
            var normal = 58 - 27 * Math.Cos((date.DayOfYear - 22) / 365.0 * 2 * Math.PI);
            departure = departure * 0.75 + (random.NextDouble() - 0.5) * 12;
            return new Day(date, Math.Round(normal + departure));
        }).ToArray();
    }
}

Add this example to a page with the izzy CLI:

bash
izzy add component RangeSelector --at <file>:<line>

View opens the chart on the last three months, so the plot shows the days and the strip the three years of seasons around them. A range selector suits a long series like this one, read up close a part at a time.

Clicking the strip outside the window moves the window there. The chart's axis names the dates, so the strip keeps only its coarsest labels, inside it, and each handle's flag shows its date only while the handle is pointed at, focused or dragged. HideFlags leaves the flags out; screen readers still hear each handle's value.

Range buttons in a chart

To add buttons for the last 1, 3 and 6 months, the year to date, a year and everything, set Ranges. The pressed button is the span in view.

Static

Preview

Acme Corp. share price, daily close
Arrow keys move between values; plus and minus zoom, 0 zooms out; Escape hides the tooltip.

Code

InChart.razor
@* Two years of a share's closing prices on trading days, with a range selector and buttons for
   common spans back from the last close. *@
<Chart Items="_closes" Argument="c => c.Date" Title="Acme Corp. share price, daily close">
    <ChartValueAxis Format="C2" />
    <ChartLineSeries Value="c => c.Price" Name="Close" />
    <ChartRangeSelector Ranges />
</Chart>

@code {
    private record Close(DateOnly Date, decimal Price);

    private readonly Close[] _closes = Closes();

    // A random walk with a slow climb, on weekdays from November 2024 to October 2026.
    private static Close[] Closes()
    {
        var random = new Random(7);
        var price = 42.0;
        var closes = new List<Close>();
        for (var date = new DateOnly(2024, 11, 1); date <= new DateOnly(2026, 10, 30); date = date.AddDays(1))
        {
            if (date.DayOfWeek is DayOfWeek.Saturday or DayOfWeek.Sunday)
            {
                continue;
            }

            price *= 1.0006 + (random.NextDouble() - 0.5) * 0.034;
            closes.Add(new Close(date, Math.Round((decimal)price, 2)));
        }

        return [.. closes];
    }
}

A button whose span would show everything is left out, so a chart of four months has no 6M or 1Y. A range selector turns on the chart's zoom, so the plot zooms by dragging, the wheel and the keys too. To open the chart on part of its arguments, or to learn in C# what's in view, set the chart's View; see Zoom.

The strip moves with IzzyBlazor's script, with no round trip, on static pages too. With JavaScript off, it shows the part in view and nothing moves. A ChartRangeSelector needs an upright chart; in a chart with bars across, it throws.

Filtering by a date range

On its own, a RangeSelector picks a range to use elsewhere, such as the dates a grid lists or a total sums. Give it the Items to draw, what each is at as Argument, a Label, and one or more series inside it, such as a ChartAreaSeries. Bind the range with @bind-View.

Always Interactive

Preview

Order dates
Plus and minus zoom, 0 zooms out, arrows pan.

115 orders from Oct 1 to Oct 31, $49,019

Orders in range
OrderCustomerDate Total
24554Wide World ImportersOct 1$200.50
24555Fabrikam Inc.Oct 1$254.20
24556Adventure WorksOct 1$307.90
24557Contoso Ltd.Oct 1$361.60
24558Litware Inc.Oct 1$415.30

Code

Filter.razor
@* A range selector on its own over six months of daily revenue, filtering the orders below to
   the dates chosen. *@
<RangeSelector Items="Days" Argument="d => d.Date" Label="Order dates" Ranges
               @bind-View="_range" @bind-View:after="Narrow">
    <ChartAreaSeries Value="d => d.Revenue" Name="Revenue" />
</RangeSelector>

<TextBlock Size="TextSize.Sm" Color="Color.Muted">
    @_shown.Length orders from @First.ToString("MMM d") to @Last.ToString("MMM d"), @_shown.Sum(o => o.Total).ToString("C0")
</TextBlock>

<DataGrid Items="_shown" ItemKey="o => o.Number.ToString()" PageSize="5" Caption="Orders in range">
    <Columns>
        <PropertyColumn Property="o => o.Number" Title="Order" Align="CellAlign.Start" />
        <PropertyColumn Property="o => o.Customer" />
        <PropertyColumn Property="o => o.Date" Format="MMM d" Sortable />
        <PropertyColumn Property="o => o.Total" Format="C" Sortable />
    </Columns>
</DataGrid>

@code {
    private record Order(int Number, string Customer, DateOnly Date, decimal Total);

    private record Day(DateOnly Date, decimal Revenue);

    private static readonly string[] Customers =
        ["Northwind Traders", "Contoso Ltd.", "Fabrikam Inc.", "Tailspin Toys", "Litware Inc.", "Adventure Works", "Wide World Importers"];

    // About 4 orders a day from May through October, fewer at weekends.
    private static readonly Order[] Orders = Enumerable.Range(0, 184)
        .SelectMany(day =>
        {
            var date = new DateOnly(2026, 5, 1).AddDays(day);
            var count = date.DayOfWeek is DayOfWeek.Saturday or DayOfWeek.Sunday ? 1 + day % 2 : 3 + day * 7 % 4;
            return Enumerable.Range(0, count).Select(n => (Date: date, Seed: day * 5 + n));
        })
        .Select((o, i) => new Order(24_001 + i, Customers[o.Seed * 3 % Customers.Length], o.Date, Math.Round(80m + o.Seed * 53.7m % 640m, 2)))
        .ToArray();

    private static readonly Day[] Days = Orders.GroupBy(o => o.Date).Select(g => new Day(g.Key, g.Sum(o => o.Total))).ToArray();

    // Opens on the last month, as the 1M button shows it: null is the data's own end.
    private ChartView? _range = new(new DateOnly(2026, 10, 1), null);

    private DateOnly First => _range?.From as DateOnly? ?? Days[0].Date;

    private DateOnly Last => _range?.To as DateOnly? ?? Days[^1].Date;

    private Order[] _shown = [];

    protected override void OnInitialized() => Narrow();

    private void Narrow() => _shown = Orders.Where(o => o.Date >= First && o.Date <= Last).ToArray();
}

View is a ChartView: From and To are the first and last arguments chosen, both included, as the argument's own type (a DateOnly here). A null end is the data's own end, and a null view is everything. The view is reported as each drag or key settles, not while dragging, so it suits a query per change.

Reporting the range needs an interactive page. On static pages the strip still moves, but C# doesn't learn the range.

Spans of your own

For spans the app names, such as fiscal quarters, set Presets to a list of DateRangePreset, each a label and its first and last days. They show as buttons beside the Ranges ones, or in their place. DateRangePreset.Common(today) gives the same spans as DateRangeField's.

razor
<ChartRangeSelector Presets="quarters" />

@code {
    private readonly DateRangePreset[] quarters =
    [
        new("Q1 FY26", new(2025, 7, 1), new(2025, 9, 30)),
        new("Q2 FY26", new(2025, 10, 1), new(2025, 12, 31)),
        new("Q3 FY26", new(2026, 1, 1), new(2026, 3, 31)),
    ];
}

The strip is 4rem tall; Height sets another.

Labels and localization

Screen readers hear the strip's Label as the name of its group, and each handle by name with the argument it's at. The other words come from the app's text. To set them for the whole app, see Text and other languages.

Labels and localization
IzzyTextSetsDefault
RangeSelectorNameThe strip's name when it has no Label"Range in view"
RangeSelectorStart, RangeSelectorEndThe handles' names"Start", "End"
RangeMonths, RangeYearToDate, RangeYear, RangeAllThe range buttons' text; {0} is the number of months"{0}M", "YTD", "1Y", "All"
RangeMonthName, RangeMonthsName, RangeYearToDateName, RangeYearNameThe range buttons' names for screen readers"Last month", "Last {0} months", "Year to date", "Last year"

Mode support

What works in each mode, RangeSelector
FeatureStaticInteractive
Under a chart's plot, the chart's series drawn small, zooming the chartYesYes
On its own, a range over its own items, to filter a grid or sum a totalYesYes
A window with two handles, each with its value in a flag (under a chart, while the handle is in use), and the rest shadedYesYes
Buttons for the last 1, 3 and 6 months, the year to date, a year and everything, or spans of your ownYesYes
Dragging the window or a handle, a click on the strip, and the keys on each handleYesYes
The range chosen reported to C# (@bind-View)NoYes
On its own, zooming several charts at once by their `Sync` nameYesYes

Static: static server-side rendering, with no circuit and no WebAssembly. Interactive: Server, WebAssembly or Auto.

Without JavaScript

Every page starts as plain HTML: before IzzyBlazor's script loads on a static page, while an interactive page prerenders, and with JavaScript off. With JavaScript off, the strip shows the range View sets, and its handles and buttons don't move it.

Accessibility

  • The strip is a group named by Label. Its drawing and its dates are hidden from screen readers; in a chart, "Show data" lists every value.
  • Each handle is a slider, the start first. Screen readers hear its name, "Start" or "End", and the argument it's at.
  • The range buttons are buttons with full names, such as "Last 3 months", and the one in view is pressed.
  • In a chart, screen readers hear the range now in view after each change.

Keyboard navigation

On a handle

RangeSelector keys, On a handle
Press this keyTo do this
Right or UpMove the handle one item later
Left or DownMove the handle one item earlier
Page Up or Page DownMove the handle a tenth of the range later or earlier
Home or EndMove the handle to the first or last item, as far as the other handle allows

Parameters

RangeSelector parameters
PropTypeDefault
ItemsThe items it draws, one point per series for each.IEnumerable<TItem>?Required
ArgumentWhat each item is at along the strip, such as d => d.Day: dates, numbers or names.Expression<Func<TItem, object?>>?Required
@bind-ViewThe range chosen, from one argument to another (null: everything).ChartView?
ChildContentThe series it draws, such as <ChartAreaSeries Value="d => d.Visits" />.RenderFragment?
SyncThe Sync name of the charts it zooms, such as Sync="sales", with no round trip, on a static page too.string?
LabelIts name for screen readers.string?
RangesButtons for common spans back from the last date: 1 month, 3 and 6 months, the year to date, a year, and all.boolfalse
PresetsSpans of your own to choose in a click, by their first and last days, beside or in place of Ranges.IEnumerable<DateRangePreset>?
HeightThe strip's height.Length?
HideFlagsLeaves out the flags over the handles that say where the range starts and ends.boolfalse

See also

  • ChartRangeSelector: a strip under a chart's plot for zooming it: the chart's series drawn small, with a window over the part in view.

Connection lost

Rejoining the server…