DeepWorks Studios Blazor Component Library

Demo user Administrator ยท Blazor Server Library 20261206222504-6e8ff32.dirty

DwsChartRangeArea

Shows one or more series as bands between a low and a high value per category, such as the coldest and warmest temperature of every month. The drawing stretches to any width and height while its lines and labels keep their size, the colors are theme colors, and hovering, focusing or tapping a category shows the range of every series there. The arrow keys move between the categories, and the legend shows or hides a series. Like every DWS component the chart takes part in the permission system through its Name: in the page's permission select mode a click selects the whole chart instead of a category.

API Reference

Basic

Only ChartData is needed: the category labels plus a series with one (low, high) range per category. The value axis runs between round numbers around the data, and the band takes the theme's Primary color.

Daily low and high in Berlin (°C)
  • Berlin
Show Code
RangeAreaChart.razor
<DwsChartRangeArea Name='RangeAreaChartDemo_Basic' ChartData='@_berlin' Title='Daily low and high in Berlin (°C)' />
RangeAreaChart.razor.cs
private static readonly string[] Months = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"];

// Average daily low and high per month in °C: one (low, high) per category.
private readonly DwsChartRangeAreaData _berlin = new DwsChartRangeAreaData(Months)
    .AddSeries("Berlin", DwsColor.Primary,
        (-2, 3), (-2, 5), (1, 9), (4, 15), (9, 19), (12, 22), (14, 24), (14, 24), (10, 19), (6, 13), (2, 7), (-1, 4));

Several series and theme colors

Each series has a theme color (DwsColor), so the chart follows the active theme; switch the theme to see it. A series without a color (Undefined) takes the next color of the default palette: Primary, Warning, Success, Error, Info, Accent, Secondary.

  • Oslo
  • Berlin
  • Madrid
Show Code
RangeAreaChart.razor
<div class='d-flex flex-wrap gap-2 mb-2'>
    @foreach ((string label, DwsColor[] colors) in _palettes)
    {
        <DwsButton Name='@($"RangeAreaChartDemo_Palette_{label.Replace(" ", string.Empty)}")'
                   Appearance='@(_palette == colors ? DwsAppearance.Filled : DwsAppearance.Outline)'
                   ButtonSize='DwsSize.Small'
                   OnClick='() => SelectPalette(colors)'>@label</DwsButton>
    }
</div>
<DwsChartRangeArea Name='RangeAreaChartDemo_Colors' ChartData='@_cities' ValueFormat='0 °C' />
RangeAreaChart.razor.cs
private static readonly DwsColor[] DefaultPalette = [DwsColor.Undefined, DwsColor.Undefined, DwsColor.Undefined];

private readonly (string Label, DwsColor[] Colors)[] _palettes =
[
    ("Default palette", DefaultPalette),
    ("Info, Success, Warning", [DwsColor.Info, DwsColor.Success, DwsColor.Warning]),
    ("Link, Accent, Error", [DwsColor.Link, DwsColor.Accent, DwsColor.Error]),
];

private DwsColor[] _palette = DefaultPalette;

// New data, so the chart sees the new colors.
private void SelectPalette(DwsColor[] colors)
{
    _palette = colors;
    _cities = BuildCities(colors);
}

private static DwsChartRangeAreaData BuildCities(DwsColor[] colors) => new DwsChartRangeAreaData(Months)
    .AddSeries("Oslo", colors[0],
        (-7, -2), (-7, -1), (-4, 4), (1, 10), (6, 16), (10, 20), (13, 22), (12, 21), (8, 16), (3, 9), (-1, 3), (-5, -1))
    .AddSeries("Berlin", colors[1],
        (-2, 3), (-2, 5), (1, 9), (4, 15), (9, 19), (12, 22), (14, 24), (14, 24), (10, 19), (6, 13), (2, 7), (-1, 4))
    .AddSeries("Madrid", colors[2],
        (3, 10), (4, 12), (6, 16), (8, 18), (12, 22), (17, 28), (19, 32), (19, 31), (16, 26), (11, 19), (6, 13), (3, 10));

private DwsChartRangeAreaData _cities = BuildCities([DwsColor.Undefined, DwsColor.Undefined, DwsColor.Undefined]);

Gaps

A null range leaves a gap in the band (the tooltip says "No value"); a lone range between two gaps is drawn as a line. These are 60 days of a share price, with three days missing.

  • Share price
Show Code
RangeAreaChart.razor
<DwsChartRangeArea Name='RangeAreaChartDemo_Gaps' ChartData='@_prices' ValueFormat='0.00 €' Height='280' />
RangeAreaChart.razor.cs
// 60 trading days of a share's daily low and high; days 20, 40 and 42 have no data, so day 41 stands alone.
private static DwsChartRangeAreaData BuildPrices()
{
    Random random = new(42);
    DateOnly start = new(2026, 6, 1);
    double price = 48;
    List<string> days = [];
    List<(double Low, double High)?> ranges = [];

    for (int day = 0; day < 60; day++)
    {
        days.Add(start.AddDays(day).ToString("d MMM", CultureInfo.InvariantCulture));
        price = Math.Max(5, price + (random.NextDouble() - 0.45) * 2.4);
        double spread = 0.6 + random.NextDouble() * 1.8;
        ranges.Add(day is 20 or 40 or 42 ? null : (Math.Round(price - spread / 2, 2), Math.Round(price + spread / 2, 2)));
    }

    return new DwsChartRangeAreaData(days).AddSeries("Share price", DwsColor.Success, [.. ranges]);
}

Many categories

With many categories only some are labelled, at most 12 spread evenly; CategoryLabelStep sets the step itself - here every 7th day.

  • Share price
Show Code
RangeAreaChart.razor
<DwsChartRangeArea Name='RangeAreaChartDemo_LabelsChart' ChartData='@_prices' ValueFormat='0.00 €' CategoryLabelStep='7' Height='280' />
RangeAreaChart.razor.cs
// 60 trading days of a share's daily low and high; days 20, 40 and 42 have no data, so day 41 stands alone.
private static DwsChartRangeAreaData BuildPrices()
{
    Random random = new(42);
    DateOnly start = new(2026, 6, 1);
    double price = 48;
    List<string> days = [];
    List<(double Low, double High)?> ranges = [];

    for (int day = 0; day < 60; day++)
    {
        days.Add(start.AddDays(day).ToString("d MMM", CultureInfo.InvariantCulture));
        price = Math.Max(5, price + (random.NextDouble() - 0.45) * 2.4);
        double spread = 0.6 + random.NextDouble() * 1.8;
        ranges.Add(day is 20 or 40 or 42 ? null : (Math.Round(price - spread / 2, 2), Math.Round(price + spread / 2, 2)));
    }

    return new DwsChartRangeAreaData(days).AddSeries("Share price", DwsColor.Success, [.. ranges]);
}

Centre line

A series can carry a centre value per category next to its low and high - a mean, a median, the measured value inside a tolerance band (CenterValues, or AddSeriesWithCenter with (low, center, high) tuples). ShowCenterLine (on by default) draws it as a dashed line inside the band, marks it in the active category and names it in the tooltip and the accessible text ("7.1 to 8.9, center 8"). Null leaves a gap in the line; a series without centre values is drawn as before. The CSV export gets a column for it.

Response time per hour (ms): fastest, median, slowest
  • Production
  • Staging
Show Code
Razor
<DwsSwitch Name='RangeAreaChartDemo_Center_Switch' @bind-Value='_showCenterLine' Label='ShowCenterLine' />
<DwsChartRangeArea Name='RangeAreaChartDemo_Center' ChartData='@_responseTimes' Title='Response time per hour (ms): fastest, median, slowest'
                   ShowCenterLine='@_showCenterLine' Height='340' />
C#
private bool _showCenterLine = true;

// (low, center, high) per category; null leaves a gap in the band and the line.
private readonly DwsChartRangeAreaData _responseTimes = new DwsChartRangeAreaData(["08:00", "09:00", "10:00", "11:00", "12:00", "13:00", "14:00"])
    .AddSeriesWithCenter("Production", DwsColor.Primary, (120, 180, 420), (130, 210, 510), (140, 260, 690), (135, 240, 640), (125, 200, 480), (120, 190, 450), (118, 185, 430))
    .AddSeriesWithCenter("Staging", DwsColor.Warning, (300, 520, 900), (310, 540, 980), (330, 600, 1100), null, (320, 560, 1020), (305, 530, 940), (300, 525, 910));

// Or on an existing series: series.CenterValues = [180, 210, 260];

No data

Without categories or series the chart shows NoDataText, or the localized default when it is not set.

No data to display
Show Code
RangeAreaChart.razor
<DwsChartRangeArea Name='RangeAreaChartDemo_Empty' ChartData='null' />

Interface-Description

Name Typ Parameters Description
GetDataAsCsv string CultureInfo? culture The data the chart was given as CSV text (RFC 4180, CRLF, a header line): one row per mark in data order, the values as passed in. Null writes numbers the invariant way with commas between the cells; a culture writes them its way with its list separator. Text a spreadsheet would run as a formula gets an apostrophe in front.
ExportDataAsync Task string? fileName, CultureInfo? culture Downloads GetDataAsCsv() as a .csv file (UTF-8 with a byte order mark). Null names the file after the chart's title, else its Name.
FocusAsync ValueTask bool containedInScrollableList Focuses the category that takes part in the tab order: the first one, or the one the user was on last. Does nothing while the chart is hidden, empty, disabled or in permission select mode.
Name Typ Default Description
ChartData DwsChartRangeAreaData? null What to draw: Categories (labels, left to right) and Series (each with a Name, a DwsColor, one DwsChartRangeAreaRange? (Low, High) per category and an optional Tag). AddSeries(name, color, (low, high)...) chains series. A null range leaves a gap; NaN or infinity does too, and a low above its high is swapped (both logged as a warning). A series with more ranges than labels adds categories labelled with their number. Null, or no category or series, shows NoDataText.
Title string? null Caption above the chart, also its accessible name.
NoDataText string? null Text shown when there is nothing to draw. Null uses the localized "No data to display".
EmptyContent RenderFragment? null Shown instead of NoDataText when there is nothing to draw.
IsLoading bool false The data is still on its way: a spinner with the localized "Loading..." instead of the drawing (under static SSR the same, without motion). Also sets the component's loading state.
Caption string? null A sentence under the chart (source, note, takeaway) in a <p class="dws-chart-caption">, referenced by the chart's aria-describedby.
Width int? null Width in px. Never wider than the container unless MinWidth asks for more. Null fills the container.
Height int? null Height in px, caption, axis labels and legend included; the drawing stretches to what is left. Null gives the drawing 16rem.
MinWidth int? null Smallest width in px; the only size that may make the chart wider than its container.
MaxWidth int? null Largest width in px, and never more than the container.
MinHeight int? null Smallest height in px; the drawing grows to fill it.
MaxHeight int? null Largest height in px; the drawing shrinks to fit it, down to 6rem.
Min double? null Bottom of the value axis. Null uses the lowest value of the visible series, rounded down to a tick. Values below it are drawn at the bottom edge. Min above Max is swapped with a warning.
Max double? null Top of the value axis. Null uses the highest value of the visible series, rounded up to a tick.
TickCount int 5 About how many values the value axis labels; the axis picks round steps (1, 2, 2.5 or 5 times a power of ten) near it. Clamped to 2-20 with a warning.
ValueFormat string "#,0.##" .NET format string for the axis labels, the tooltip and the accessible names, applied in the current UI culture. An invalid format falls back to the default with a warning.
FillOpacity double 0.3 How strongly a band is filled with its color, 0 (edges only) to 1 (solid).
ShowLines bool true Draws the upper and lower edge of each band as a line in the series color.
ShowGrid bool true Draws a horizontal grid line at each labelled value.
ShowCenterLine bool true Draws the centre values of the series that have some (DwsChartRangeAreaSeries.CenterValues, or DwsChartRangeAreaData.AddSeriesWithCenter) as a dashed line inside the band, marks them in the active category and names them in the tooltip and the accessible text. DwsChartRangeAreaValue.Center holds the value for a TooltipTemplate.
ShowValueAxis bool true Shows the value labels on the left.
ShowCategoryAxis bool true Shows the category labels below the drawing.
CategoryLabelStep int? null Labels every n-th category. Null labels at most 12, spread evenly; 1 labels all of them (long labels are cut off with an ellipsis).
WithLegend bool true Shows a legend with the name and color of every series.
LegendPosition DwsChartLegendPosition Bottom Bottom, Top, Left or Right of the drawing. Left and Right put the legend beside it as a column, and move it below on screens narrower than 576px.
AllowSeriesToggle bool true Makes each legend entry a toggle button (aria-pressed) that shows or hides its series; the value axis follows the visible series. A hidden series stays in the legend, struck through. Off while disabled or in permission select mode.
ShowTooltip bool true Shows the range of every visible series in the hovered or focused category. On touch screens tapping a category shows it; Escape hides it until the next category.
TooltipTemplate RenderFragment<DwsChartRangeAreaCategory>? null Content of the tooltip. Null shows the category label and each series' name and range.
HighlightOnHover bool true While the pointer is on a legend entry, fades every other series.
Name Typ Description
OnCategoryClick EventCallback<DwsChartRangeAreaCategory> Raised when a category is clicked, tapped or activated with Enter/Space. Not raised while disabled or in permission select mode (a click then selects the chart).
OnCategoryHover EventCallback<DwsChartRangeAreaCategory?> Raised when the pointer or focus enters a category, and with null when neither is on one any more: also when the chart stops reacting (disabled, permission select mode) or new data no longer has the category.
OnSeriesToggle EventCallback<DwsChartRangeAreaSeriesToggleEventArgs> Raised after the legend showed or hid a series, with the Series, its SeriesIndex and whether it is Visible now.
Name Typ Default Description
Element ElementReference The associated web component. May be null if accessed before the component is rendered.
ComponentGuid Guid Unique identifier for the component.
TypeString string The name of the component type, obtained from reflection.
Authorized_RegisterEnabled bool false Indicates whether this component is enabled through a permission registry.
Authorized_RegisterSelected bool false Indicates whether this component is selected in permission selection mode.
GetInitializedState bool false Returns whether the component is initialized.
GetRenderModeState DwsRenderMode Returns the current render mode.
GetComponentState DwsComponentStateType Returns the current component state.
GetIsInteractiveState bool false Returns whether the component is interactive.
GetIsPrerenderingState bool false Returns whether the component is prerendering.
GetComponentLoadingState bool false Returns whether the component is loading.
IsFormBusy bool false Whether the DwsForm (or DwsFormBusyRegion) around the component is locked because its submit handler is running. The state itself is the cascaded FormBusyState (IDwsFormBusyState).
Name Typ Parameters Description
DebugInfo void Logs debug information about the component.
UpdateState void Updates the component's state and triggers StateHasChanged.
UpdateStateAsync Task Asynchronously updates the component's state and triggers StateHasChanged.
Dispose void Disposes the component and releases resources.
FocusAsync ValueTask bool containedInScrollableList Sets focus to the component's element.
Name Typ Default Description
Name string Required unique identifier for the component within its container.
Visible bool true Determines if the component is visible in the UI.
Disabled bool false Disables the form control, ensuring it doesn't participate in form submission.
ComponentNameSpace string The namespace for permission-based access control.
PermissionKey string? null A stable key that takes the place of Name in the generated permission namespace (Page.PermissionKey): the stored permission survives a rename, and components that share a key share one permission entry. Null: keyed by Name. Read once, when the component registers; an explicit ComponentNameSpace wins.
Class string Optional CSS class names.
Style string Optional in-line styles.
Tag object An optional user-defined object to store any additional data with the component.
BackReference DwsReference A reference to the enclosing component.
ID string The HTML ID attribute for the component.
AdditionalAttributes Dictionary<string, object> Additional HTML attributes for the component's root element.
IgnorePermissionChecks bool false Bypasses all permission checks for this component.
IgnorePermissionSelection bool false Ignore permission selection mode for this component.
IgnoreFormBusy bool false Takes the component out of the submit lock of the DwsForm (or DwsFormBusyRegion) around it: IsFormBusy stays false for it.
Name Typ Description
OnInitializedCallbackStarted EventCallback Callback when OnInitialized starts.
OnInitializedCallback EventCallback Callback during OnInitialized.
OnInitializedCallbackCompleted EventCallback Callback when OnInitialized completes.
OnInitializedAsyncCallbackStarted EventCallback Callback when OnInitializedAsync starts.
OnInitializedAsyncCallback EventCallback Callback during OnInitializedAsync.
OnInitializedAsyncCallbackCompleted EventCallback Callback when OnInitializedAsync completes.
OnIsComponentLoadingChanged EventCallback<bool> Callback when IsComponentLoading changes.
OnCurrentRenderModeChanged EventCallback<DwsRenderMode> Callback when CurrentRenderMode changes.
OnComponentStateChanged EventCallback<DwsComponentStateType> Callback when ComponentState changes.
An error has occurred. This app may no longer respond until reloaded.