DeepWorks Studios Blazor Component Library

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

DwsChartBubble

Shows points with three values each: X and Y place a bubble, and the third value sets its area. The chart fills its container on any screen, keeps its text readable and its bubbles round, and takes its colors from the theme. Hovering, focusing or tapping a bubble shows its values, the arrow keys move between bubbles, and the legend shows and hides series.

API Reference

Basic

Only ChartData is needed: one or more series, each with points of X, Y and Size. The axes reach out to round values around the data, the largest size gets the largest bubble, and series without a color take the theme colors in turn.

Products by price and rating
  • Headphones
  • Speakers
  • Accessories
Show Code
BubbleChart.razor
<DwsChartBubble Name="BubbleChartDemo_Basic" ChartData="@_products" Title="Products by price and rating"
                XAxisTitle="Price (€)" YAxisTitle="Rating" SizeTitle="Units sold" />
BubbleChart.razor.cs
// Products by price (X), average rating (Y) and units sold (Size).
private readonly DwsChartBubbleData _products = new DwsChartBubbleData()
    .AddSeries("Headphones", DwsColor.Undefined,
        new(49, 3.9, 1200, "Basic"), new(129, 4.4, 860, "Studio"), new(249, 4.7, 410, "Pro"), new(349, 4.5, 150, "Wireless Max"))
    .AddSeries("Speakers", DwsColor.Undefined,
        new(79, 4.1, 640, "Mini"), new(199, 4.3, 520, "Room"), new(399, 4.6, 230, "Tower"))
    .AddSeries("Accessories", DwsColor.Undefined,
        new(9, 3.6, 2400, "Cable"), new(19, 4.0, 1800, "Case"), new(39, 4.2, 950, "Stand"));

Theme colors

A series takes its Color (a DwsColor); series without one take the next color of Colors, or the default palette. All colors are theme variables, so the chart follows the active theme: switch between light and dark in the settings.

  • North
  • South
  • East
  • West
Show Code
BubbleChart.razor
<div class="d-flex flex-wrap gap-2 mb-3">
    @foreach ((string label, DwsColor[]? colors) in _palettes)
    {
        <DwsButton Name="@($"BubbleChartDemo_Palette_{label.Replace(" ", string.Empty)}")"
                   Appearance="@(_palette == colors ? DwsAppearance.Filled : DwsAppearance.Outline)"
                   ButtonSize="DwsSize.Small"
                   OnClick="() => _palette = colors">@label</DwsButton>
    }
</div>
<DwsChartBubble Name="BubbleChartDemo_Colors" ChartData="@_regions" Colors="@_palette"
                XAxisTitle="Marketing spend (k€)" YAxisTitle="Revenue (k€)" SizeTitle="Customers" />
BubbleChart.razor.cs
// Sales regions: marketing spend (X), revenue (Y) and customers (Size), per quarter.
private readonly DwsChartBubbleData _regions = new DwsChartBubbleData()
    .AddSeries("North", DwsColor.Undefined, new(120, 820, 340, "Q1"), new(150, 910, 380, "Q2"), new(170, 1040, 420, "Q3"), new(140, 980, 400, "Q4"))
    .AddSeries("South", DwsColor.Undefined, new(80, 610, 260, "Q1"), new(95, 700, 300, "Q2"), new(110, 690, 310, "Q3"), new(130, 860, 350, "Q4"))
    .AddSeries("East", DwsColor.Undefined, new(60, 420, 150, "Q1"), new(70, 480, 180, "Q2"), new(90, 560, 210, "Q3"), new(100, 600, 230, "Q4"))
    .AddSeries("West", DwsColor.Undefined, new(150, 760, 290, "Q1"), new(160, 800, 310, "Q2"), new(155, 790, 300, "Q3"), new(175, 900, 330, "Q4"));

// Series of their own color: .AddSeries("North", DwsColor.Success, ...)
private readonly (string Label, DwsColor[]? Colors)[] _palettes =
[
    ("Default", null),
    ("Primary and Accent", [DwsColor.Primary, DwsColor.Accent, DwsColor.Link, DwsColor.Info]),
    ("Status", [DwsColor.Success, DwsColor.Info, DwsColor.Warning, DwsColor.Error]),
];

private DwsColor[]? _palette;

Value formats

XValueFormat, YValueFormat and SizeValueFormat format the values of the axes and the tooltip in the current culture.

Show Code
BubbleChart.razor
<DwsChartBubble Name="BubbleChartDemo_FormatsChart" ChartData="@_risks" WithLegend="false"
                XValueFormat="0'%'" YValueFormat="0'%'" SizeValueFormat="#,0 €" />
BubbleChart.razor.cs
// Project risks: likelihood (X) and impact (Y) in percent, and cost (Size) in euros.
private readonly DwsChartBubbleData _risks = new DwsChartBubbleData()
    .AddSeries("Risks", DwsColor.Error,
        new(15, 85, 120000, "Data center outage"), new(40, 60, 45000, "Key person leaves"), new(65, 35, 20000, "Supplier delay"),
        new(80, 20, 8000, "Minor bugs in release"), new(30, 30, 15000, "Budget overrun"), new(55, 70, 60000, "Security incident"));

Empty

Without any point the chart shows NoDataText (or the localized default).

No data to display
Show Code
BubbleChart.razor
<DwsChartBubble Name="BubbleChartDemo_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.
SelectRangeAsync(double xMin, double xMax, double yMin, double yMax, bool additive = false) Task Selects the marks between these values of the axes. Works without AllowBrushSelection too.
ClearSelectionAsync Task Clears the selection. The property SelectedPoints returns the selected marks of the shown series.
ResetZoomAsync Task Shows everything again.
ZoomToAsync Task Shows the part between the given ends (as axis values); cut back to the whole range and to MaxZoom. Works without AllowZoom too. IsZoomed tells whether the view is zoomed.
FocusAsync ValueTask bool containedInScrollableList Focuses the bubble that takes part in the tab order: the leftmost of the first shown series, or the one the user was on last. Does nothing while the chart is hidden, empty, disabled or in permission select mode.
IsSeriesVisible bool int seriesIndex Whether the series at this position in ChartData.Series is shown (not hidden through the legend).
Name Typ Default Description
ChartData DwsChartBubbleData? null The series to draw: each DwsChartBubbleSeries has a Name, a Color (DwsColor; Undefined takes the next palette color), an optional Tag and Points of X, Y, Size and an optional Label and Tag. AddSeries(name, color, points...) and AddPoint(x, y, size, label) chain. A point with NaN or infinity is left out (logged as a warning). Null, or no point at all, 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.
XAxisTitle string? null Title below the horizontal axis; also names X in the tooltip and the accessible names. Null shows no title and "X" in the tooltip.
YAxisTitle string? null Title beside the vertical axis, reading upwards; also names Y in the tooltip. Null shows no title and "Y" in the tooltip.
SizeTitle string? null Names the bubble size in the tooltip and the accessible names. Null uses the localized "Size".
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, axes and legend included; the plot takes what is left. Null gives the plot a height that suits the screen (14rem to 22rem).
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.
MinBubbleSize int 8 Diameter in px of the smallest bubble: sizes of zero or less, and bubbles that would be smaller, get it (at least 2).
MaxBubbleSize int 48 Diameter in px of the bubble with the largest size; the area of the others grows with their size. The plot is inset by half of it, so bubbles at the ends of the axes stay inside.
XMin double? null Low end of the horizontal axis. Null reaches out to a round value below the lowest X. Above XMax the two are swapped (logged).
XMax double? null High end of the horizontal axis. Null reaches out to a round value above the highest X.
YMin double? null Low end of the vertical axis. Null reaches out to a round value below the lowest Y. Above YMax the two are swapped (logged).
YMax double? null High end of the vertical axis. Null reaches out to a round value above the highest Y.
TickCount int 5 About how many tick marks each axis gets (2 to 20); the axes pick steps of 1, 2, 2.5 or 5 times a power of ten.
ShowGrid bool true Draws grid lines at the tick marks.
ShowBubbleLabels bool true Writes the label of a point inside its bubble where the bubble is large enough for the whole label on one line (at least 24px wide); a label that does not fit is left out. The text is black or white, whichever stands out from the bubble's color.
XValueFormat string "#,0.##" .NET format string for X values (tick labels, tooltip, accessible names), in the current UI culture. An invalid format falls back to the default (logged once).
YValueFormat string "#,0.##" .NET format string for Y values, in the current UI culture.
SizeValueFormat string "#,0.##" .NET format string for sizes, in the current UI culture.
Colors IReadOnlyList<DwsColor>? null Theme colors for the series without a Color of their own, in turn. Null or empty uses Primary, Success, Warning, Error, Info, Accent, Link and Secondary. Colors are CSS theme variables, so the chart follows the active theme.
WithLegend bool true Shows a legend with one entry per series.
LegendPosition DwsChartLegendPosition Bottom Bottom, Top, Left or Right of the plot. Left and Right move below it on screens narrower than 576px.
ToggleSeriesOnLegendClick bool true Clicking a legend entry (a toggle button with aria-pressed) hides its series, clicking it again shows it. The axes keep their range. Series stay hidden while the data keeps the same number of series.
ShowTooltip bool true Shows the values of the hovered, focused or tapped bubble. Escape hides it until the next bubble; a tap on the empty plot puts a tapped bubble's tooltip away.
TooltipTemplate RenderFragment<DwsChartBubbleItem>? null Content of the tooltip. Null shows the name and the three values.
HighlightOnHover bool true Fades the other series while the pointer is on a bubble or a legend entry.
XScale DwsChartAxisScale DwsChartAxisScale.Linear How the horizontal axis places its values: Linear, or Log10 (equal factors take equal room, tick marks at the powers of ten; within one decade also at 2 and 5 times them). Values of zero or less are left out on a logarithmic axis, with one warning; XMin / XMax must be above zero there.
YScale DwsChartAxisScale DwsChartAxisScale.Linear How the vertical axis places its values; see XScale.
AllowZoom bool false Lets the user zoom and move the view: Ctrl / Cmd + wheel (the plain wheel while the plot has the keyboard focus), pinch, drag, and on the keyboard + / - / 0 and - with the focus on the plot itself - the arrow keys. The plot becomes a Tab stop. Needs interactivity.
MaxZoom double 20 How far the user can zoom in: the smallest part shown is one in this many, on each axis.
ShowZoomReset bool true Shows a button in the corner that shows everything again, while the view is zoomed.
AllowBrushSelection bool false Lets the user select marks: by dragging a rectangle over the plot with the mouse or a pen (Ctrl / Cmd adds to the selection), or with the keyboard - Shift and an arrow key add the next mark in that direction, Shift and Space add or remove the focused one, Escape clears. With AllowZoom a plain drag moves the view and Shift and a drag selects. A finger dragged over the chart scrolls the page. Needs interactivity for the pointer.
Name Typ Description
OnZoomChanged EventCallback<DwsChartZoomEventArgs> Raised when the part shown changed, by the user or a method: XMin, XMax, YMin, YMax (as axis values) and IsZoomed.
OnRangeSelected EventCallback<DwsChartRangeSelectedEventArgs<DwsChartBubbleItem>> Raised when the selection changed: Items (every selected mark), XMin, XMax, YMin, YMax (the rectangle that was dragged, in the values of the axes; null when the selection changed another way) and ByKeyboard.
OnBubbleClick EventCallback<DwsChartBubbleItem> Raised when a bubble is clicked, tapped or activated with Enter/Space. Not raised while disabled or in permission select mode (a click then selects the chart).
OnBubbleHover EventCallback<DwsChartBubbleItem?> Raised when the pointer, focus or a tap enters a bubble, and with null when none is on a bubble any more: also when the chart stops reacting or the bubble's series is hidden.
OnLegendItemClick EventCallback<DwsChartBubbleSeries> Raised when a legend entry is clicked or activated, after its series was shown or hidden. With ToggleSeriesOnLegendClick false the entries are buttons only while this has a handler.
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.