DeepWorks Studios Blazor Component Library

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

DwsChartBoxPlot

Shows how the values of one or more samples are spread: each box spans the middle half of its values (first to third quartile) with a line at the median, the whiskers reach out to the rest, and points beyond them are outliers. The chart fills its container on any screen, its colors are theme colors, and hovering, focusing or tapping a box shows its numbers. The arrow keys move between the boxes.

API Reference

Basic

Only ChartData is needed: one box per label with its raw values. The chart works out the quartiles, the median, the whiskers (1.5 times the box, Tukey) and the outliers, and rounds the value axis to readable ticks.

Response time per endpoint (ms)
  • /login
  • /search
  • /orders
  • /reports
Show Code
BoxPlotChart.razor
<DwsChartBoxPlot Name="BoxPlotChartDemo_Basic" ChartData="@_responseTimes" Title="Response time per endpoint (ms)" />
BoxPlotChart.razor.cs
private readonly DwsChartBoxPlotData _responseTimes = new DwsChartBoxPlotData()
    .Add("/login", 42, 45, 48, 51, 52, 55, 57, 58, 60, 63, 66, 70, 118)
    .Add("/search", 80, 92, 95, 101, 110, 114, 120, 126, 133, 140, 152, 171, 240, 262)
    .Add("/orders", 61, 66, 70, 72, 75, 79, 83, 86, 90, 97)
    .Add("/reports", 150, 170, 188, 205, 214, 230, 251, 266, 290, 318, 335, 12);

Orientation and axis title

Orientation Horizontal lays the boxes on their side, which suits long labels; ValueAxisTitle names the value axis.

Delivery time
  • Standard (national)
  • Express (national)
  • Standard (international)
  • Freight
Show Code
BoxPlotChart.razor
<DwsSwitch Name="BoxPlotChartDemo_Horizontal" @bind-Value="_horizontal" Label="Horizontal" />

<DwsChartBoxPlot Name="BoxPlotChartDemo_Orientation" ChartData="@_deliveryDays" ValueFormat="0.# 'days'"
                 Orientation="@(_horizontal ? DwsLayoutOrientation.Horizontal : DwsLayoutOrientation.Vertical)"
                 ValueAxisTitle="Delivery time" />
BoxPlotChart.razor.cs
private bool _horizontal = true;

private readonly DwsChartBoxPlotData _deliveryDays = new DwsChartBoxPlotData()
    .Add("Standard (national)", 2, 2, 3, 3, 3, 3, 4, 4, 4, 5, 5, 6)
    .Add("Express (national)", 1, 1, 1, 1, 1, 1, 2, 2, 2, 3, 6, 7)
    .Add("Standard (international)", 5, 6, 7, 7, 8, 8, 9, 10, 11, 12, 14, 21)
    .Add("Freight", 9, 10, 12, 13, 13, 14, 15, 16, 18, 19);

Mean marker

ShowMean marks the mean with a diamond, so a skewed sample shows its mean away from the median.

  • Standard (national)
  • Express (national)
  • Standard (international)
  • Freight
Show Code
BoxPlotChart.razor
<DwsSwitch Name="BoxPlotChartDemo_ShowMean" @bind-Value="_showMean" Label="ShowMean" />
<DwsChartBoxPlot Name="BoxPlotChartDemo_MeanChart" ChartData="@_deliveryDays" ValueFormat="0.# 'days'" ShowMean="@_showMean" />
BoxPlotChart.razor.cs
private bool _showMean = true;

private readonly DwsChartBoxPlotData _deliveryDays = new DwsChartBoxPlotData()
    .Add("Standard (national)", 2, 2, 3, 3, 3, 3, 4, 4, 4, 5, 5, 6)
    .Add("Express (national)", 1, 1, 1, 1, 1, 1, 2, 2, 2, 3, 6, 7)
    .Add("Standard (international)", 5, 6, 7, 7, 8, 8, 9, 10, 11, 12, 14, 21)
    .Add("Freight", 9, 10, 12, 13, 13, 14, 15, 16, 18, 19);

Wrapping labels

WrapLabels (on by default) lets a label that is too long for its lane take a second line before it is cut off with an ellipsis.

  • Standard (national)
  • Express (national)
  • Standard (international)
  • Freight
Show Code
BoxPlotChart.razor
<DwsSwitch Name="BoxPlotChartDemo_WrapLabelsSwitch" @bind-Value="_wrapLabels" Label="WrapLabels" />
<DwsChartBoxPlot Name="BoxPlotChartDemo_WrapLabelsChart" ChartData="@_deliveryDays" ValueFormat="0.# 'days'"
                 Orientation="DwsLayoutOrientation.Vertical" WrapLabels="@_wrapLabels" />
BoxPlotChart.razor.cs
private bool _wrapLabels = true;

private readonly DwsChartBoxPlotData _deliveryDays = new DwsChartBoxPlotData()
    .Add("Standard (national)", 2, 2, 3, 3, 3, 3, 4, 4, 4, 5, 5, 6)
    .Add("Express (national)", 1, 1, 1, 1, 1, 1, 2, 2, 2, 3, 6, 7)
    .Add("Standard (international)", 5, 6, 7, 7, 8, 8, 9, 10, 11, 12, 14, 21)
    .Add("Freight", 9, 10, 12, 13, 13, 14, 15, 16, 18, 19);

Theme colors

Colors lists the theme colors (DwsColor) given to the boxes in turn, so the chart follows the active theme; an item's own Color wins. Without Colors the boxes take Primary, Accent, Success, Warning, Info, Error and Secondary.

  • /login
  • /search
  • /orders
  • /reports
Show Code
BoxPlotChart.razor
@foreach ((string label, DwsColor[]? colors) in _palettes)
{
    <DwsButton Name="@($"BoxPlotChartDemo_Palette_{label.Replace(" ", string.Empty)}")"
               Appearance="@(_palette == colors ? DwsAppearance.Filled : DwsAppearance.Outline)"
               ButtonSize="DwsSize.Small"
               OnClick="() => _palette = colors">@label</DwsButton>
}

<DwsChartBoxPlot Name="BoxPlotChartDemo_Colors" ChartData="@_responseTimes" Colors="@_palette" />
BoxPlotChart.razor.cs
private readonly (string Label, DwsColor[]? Colors)[] _palettes =
[
    ("Default", null),
    ("Primary only", [DwsColor.Primary]),
    ("Info and Warning", [DwsColor.Info, DwsColor.Warning]),
];

private DwsColor[]? _palette;

// One box in its own color:
// new DwsChartBoxPlotItem { Label = "/admin", Values = [...], Color = DwsColor.Error }

private readonly DwsChartBoxPlotData _responseTimes = new DwsChartBoxPlotData()
    .Add("/login", 42, 45, 48, 51, 52, 55, 57, 58, 60, 63, 66, 70, 118)
    .Add("/search", 80, 92, 95, 101, 110, 114, 120, 126, 133, 140, 152, 171, 240, 262)
    .Add("/orders", 61, 66, 70, 72, 75, 79, 83, 86, 90, 97)
    .Add("/reports", 150, 170, 188, 205, 214, 230, 251, 266, 290, 318, 335, 12);

Width and height

Width, Height, MinWidth, MaxWidth, MinHeight and MaxHeight size the chart in pixels, caption and legend included; with a height the plot takes what is left. Drag the corner of the box: this chart is 320px high and keeps between 220px and 640px wide.

  • /login
  • /search
  • /orders
  • /reports
Show Code
BoxPlotChart.razor
<div class="boxplot-demo-resizable">
    <DwsChartBoxPlot Name="BoxPlotChartDemo_Size" ChartData="@_responseTimes" Height="320" MinWidth="220" MaxWidth="640" />
</div>

<style>
    .boxplot-demo-resizable {
        resize: horizontal;
        overflow: auto;
        width: 100%;
        min-width: 240px;
        padding: 0.5rem;
        border: 1px dashed var(--secondary);
    }
</style>
BoxPlotChart.razor.cs
private readonly DwsChartBoxPlotData _responseTimes = new DwsChartBoxPlotData()
    .Add("/login", 42, 45, 48, 51, 52, 55, 57, 58, 60, 63, 66, 70, 118)
    .Add("/search", 80, 92, 95, 101, 110, 114, 120, 126, 133, 140, 152, 171, 240, 262)
    .Add("/orders", 61, 66, 70, 72, 75, 79, 83, 86, 90, 97)
    .Add("/reports", 150, 170, 188, 205, 214, 230, 251, 266, 290, 318, 335, 12);

Precomputed summaries

AddSummary draws a box from numbers computed elsewhere (minimum, quartiles, median, maximum and any outliers), for data too large to send to the browser.

Exam scores per class
  • Class 9a
  • Class 9b
  • Class 9c
Show Code
BoxPlotChart.razor
<DwsChartBoxPlot Name="BoxPlotChartDemo_Summary" ChartData="@_examScores" ValueFormat="0" Title="Exam scores per class" />
BoxPlotChart.razor.cs
// Minimum, Q1, median, Q3, maximum, then any outliers.
private readonly DwsChartBoxPlotData _examScores = new DwsChartBoxPlotData()
    .AddSummary("Class 9a", 38, 55, 64, 72, 88, 12, 97)
    .AddSummary("Class 9b", 45, 61, 70, 79, 95)
    .AddSummary("Class 9c", 30, 48, 57, 66, 84, 8);

Fixed value axis

Min and Max fix the ends of the value axis, so exam scores always run from 0 to 100.

  • Class 9a
  • Class 9b
  • Class 9c
Show Code
BoxPlotChart.razor
<DwsChartBoxPlot Name="BoxPlotChartDemo_FixedAxisChart" ChartData="@_examScores" Min="0" Max="100" ValueFormat="0" />
BoxPlotChart.razor.cs
// Minimum, Q1, median, Q3, maximum, then any outliers.
private readonly DwsChartBoxPlotData _examScores = new DwsChartBoxPlotData()
    .AddSummary("Class 9a", 38, 55, 64, 72, 88, 12, 97)
    .AddSummary("Class 9b", 45, 61, 70, 79, 95)
    .AddSummary("Class 9c", 30, 48, 57, 66, 84, 8);

Response times of an API

A day of requests to five endpoints of a shop API, with their full, long paths as labels. Lying boxes (Orientation Horizontal) give long labels the width of the chart; on a phone they wrap, and a label that is still too long is cut, with the full text in its title (shown on hover). The diamond is the mean, the dots are the slow requests beyond the whiskers. On a phone, tap a box to pin its tooltip; tap elsewhere or press Escape to close it.

Response time

The invoice download is the slowest endpoint and the one that varies most.

Show Code
BoxPlotChart.razor
<DwsChartBoxPlot Name='BoxPlotChartDemo_Endpoints' ChartData='@_endpoints' Orientation='DwsLayoutOrientation.Horizontal' ValueFormat="0 'ms'"
                 ValueAxisTitle='Response time' ShowMean='true' WithLegend='false'
                 Caption='The invoice download is the slowest endpoint and the one that varies most.' />
BoxPlotChart.razor.cs
private readonly DwsChartBoxPlotData _endpoints = BuildEndpoints();

// 60 requests per endpoint: a typical time, a spread, and a few slow ones; the same numbers on every visit.
private static DwsChartBoxPlotData BuildEndpoints()
{
    (string Path, double Typical, double Spread)[] endpoints =
    [
        ("GET /api/v2/catalogue/products?category={id}&sort=popularity", 85, 30),
        ("POST /api/v2/checkout/{cartId}/payment-intent", 240, 60),
        ("GET /api/v2/customers/{id}/orders/{orderId}/invoice.pdf", 420, 180),
        ("PUT /api/v2/customers/{id}/addresses/{addressId}", 60, 15),
        ("GET /api/v2/search/suggestions?query={text}", 35, 12),
    ];

    Random random = new(5);
    DwsChartBoxPlotData data = new();

    foreach ((string path, double typical, double spread) in endpoints)
    {
        double[] times = [.. Enumerable.Range(0, 60).Select(index => Math.Round(index % 17 == 0
            ? typical + spread * (3 + random.NextDouble() * 2)
            : typical + spread * (random.NextDouble() + random.NextDouble() - 1)))];
        data.Add(path, times);
    }

    return data;
}

On a phone: caption, loading and empty content

The chart measures its own width (not the window's) and lays its labels out for it: as many axis labels as fit, labels at the edges run inward, long labels are cut at a word with the full text in their title and tooltip, and the legend goes below. On a touch screen a tap shows the nearest mark's tooltip until the next tap elsewhere or Escape. Caption puts a sentence under the chart that is also its accessible description, IsLoading shows a spinner instead of the drawing, and EmptyContent replaces the no-data text.

  • Standard (national)
  • Express (national)
  • Standard (international)
  • Freight

Delivery days per shipping method, drawn 320px wide.

Nothing recorded yet - data appears here after the first import.

Show Code
BoxPlotChart.razor
<button @onclick='() => _phoneLoading = !_phoneLoading'>IsLoading = @_phoneLoading</button>

<div style='max-width: 320px;'>
    <DwsChartBoxPlot Name='BoxPlotChartDemo_Phone' ChartData='@DeliveryDays' IsLoading='@_phoneLoading' Caption='Delivery days per shipping method, drawn 320px wide.' />
</div>

<DwsChartBoxPlot Name='BoxPlotChartDemo_EmptyContent' ChartData='null'>
    <EmptyContent>
        <DwsTypography Name='BoxPlotChartDemo_EmptyContentText' Typography='DwsTypographyType.Paragraph'>Nothing recorded yet - data appears here after the first import.</DwsTypography>
    </EmptyContent>
</DwsChartBoxPlot>

Empty

Without a box the chart shows NoDataText (or the localized default).

No data to display
Show Code
BoxPlotChart.razor
<DwsChartBoxPlot Name="BoxPlotChartDemo_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 box 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 DwsChartBoxPlotData? null The boxes to draw, in order. Add(label, values...) adds a box from raw values (NaN and infinity are ignored with a warning); AddSummary(label, minimum, q1, median, q3, maximum, outliers...) one from numbers computed elsewhere. Items (DwsChartBoxPlotItem) also carry an optional Mean, Color and Tag. An item with neither values nor a complete summary is left out with a warning. Null, or no drawable box, 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 and legend included; the plot takes what is left. Null gives the plot 16rem (horizontal: 3rem per box, at least 8rem).
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 plot grows to fill it.
MaxHeight int? null Largest height in px; the plot shrinks to fit it.
Orientation DwsLayoutOrientation DwsLayoutOrientation.Vertical Vertical: upright boxes side by side, value axis on the left. Horizontal: boxes on their side, one under the other, value axis below (better for long labels).
Colors IReadOnlyList<DwsColor>? null Theme colors given to the boxes in turn; an item's own Color wins. Null or empty uses Primary, Accent, Success, Warning, Info, Error and Secondary. Outlines are mixed half with the text color, so they keep 3:1 contrast in every theme.
Whiskers DwsChartBoxPlotWhiskers DwsChartBoxPlotWhiskers.Tukey For boxes from raw values: Tukey ends the whiskers at the furthest value within 1.5 times the box and draws the rest as outliers; MinMax runs them to the smallest and largest value. Quartiles are interpolated linearly (as Excel's QUARTILE.INC).
Min double? null Low end of the value axis. Null rounds the lowest drawn value down to a tick. Min greater than Max swaps the two with a warning.
Max double? null High end of the value axis. Null rounds the highest drawn value up to a tick.
ShowOutliers bool true Draws the outliers as points.
ShowMean bool false Marks the mean of each box with a diamond.
ShowGrid bool true Draws a grid line at every tick of the value axis.
ValueFormat string "#,0.##" .NET number format for the axis, the tooltip and the accessible names, in the current UI culture. An invalid format falls back to the default with a warning.
WrapLabels bool true Lets a category label that is too long for its lane wrap onto a second line; only what still does not fit is cut off with an ellipsis (the tooltip and the accessible name keep the full label). False keeps every label on one line.
ValueAxisTitle string? null Title of the value axis, for what the numbers are and their unit. Printed beside the tick labels of upright boxes (reading bottom to top) and below those of boxes on their side. Null prints none.
WithLegend bool true Shows a legend naming each box with its color. Hovering an entry fades the other boxes.
LegendPosition DwsChartLegendPosition DwsChartLegendPosition.Bottom Bottom, Top, Right or Left of the plot. Right and Left move below it on screens narrower than 576px.
ShowTooltip bool true Shows the numbers of the hovered or focused box; on touch screens a tap shows it. Escape hides it until the next box.
TooltipTemplate RenderFragment<DwsChartBoxPlotBox>? null Content of the tooltip. The box has Index, Item (with Tag), Label, Summary (Minimum, LowerQuartile, Median, UpperQuartile, Maximum, Mean, Outliers, Count), Color and Format. Null shows the label and the numbers.
HighlightOnHover bool true Fades the other boxes while the pointer or focus is on a box or its legend entry.
Name Typ Description
OnBoxClick EventCallback<DwsChartBoxPlotBox> Raised when a box is clicked, tapped or activated with Enter/Space. Not raised while disabled or in permission select mode (a click then selects the chart).
OnBoxHover EventCallback<DwsChartBoxPlotBox?> Raised when the pointer or focus enters a box, and with null when neither is on a box any more: also when the chart stops reacting (disabled, permission select mode) or new data no longer has the box.
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.