DeepWorks Studios Blazor Component Library

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

DwsChartScatter

Shows how two values relate: every point is placed by its X and Y value. The chart fills its container on any screen and keeps its text readable; each series takes a theme color and a marker shape, so series stay apart in any theme and without color, and can show their trend line. Hovering, focusing or tapping a point shows its values, the arrow keys move between points, and the legend shows and hides series.

API Reference

Basic

Only ChartData is needed: one or more series, each with points of X and Y. The axes reach out to round values around the data, and series without a color or marker take the theme colors and the shapes circle, square, diamond and triangle in turn.

Study time and exam score
  • Class A
  • Class B
Show Code
ScatterChart.razor
<DwsChartScatter Name='ScatterChartDemo_Basic' ChartData='@_study' Title='Study time and exam score' XAxisTitle='Hours of study' YAxisTitle='Score' />
ScatterChart.razor.cs
// Students of two classes: hours of study (X) and exam score (Y).
private readonly DwsChartScatterData _study = new DwsChartScatterData()
    .AddSeries("Class A", DwsColor.Undefined,
        new(2, 48, "Anna"), new(3.5, 55, "Ben"), new(5, 61, "Clara"), new(6, 70, "David"), new(7.5, 68, "Emma"),
        new(8, 79, "Felix"), new(9.5, 84, "Greta"), new(11, 88, "Hannes"))
    .AddSeries("Class B", DwsColor.Undefined,
        new(1, 40, "Ida"), new(2.5, 52, "Jonas"), new(4, 50, "Klara"), new(4.5, 63, "Lukas"), new(6.5, 60, "Mia"),
        new(7, 74, "Noah"), new(9, 71, "Olivia"), new(10, 83, "Paul"));

Theme colors and markers

A series takes its Color (a DwsColor) and its Marker (DwsChartScatterMarker); series without a color 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.

  • Hamburg
  • Munich
  • Berlin
Show Code
ScatterChart.razor
<div class='d-flex flex-wrap gap-2 mb-3'>
    @foreach ((string label, DwsColor[]? colors) in _palettes)
    {
        <DwsButton Name='@($"ScatterChartDemo_Palette_{label.Replace(" ", string.Empty)}")' Appearance='@(_palette == colors ? DwsAppearance.Filled : DwsAppearance.Outline)' ButtonSize='DwsSize.Small' OnClick='() => _palette = colors'>@label</DwsButton>
    }
</div>
<DwsChartScatter Name='ScatterChartDemo_Colors' ChartData='@_cities' Colors='@_palette' XAxisTitle='Temperature (°C)' YAxisTitle='Ice cream sales' />
ScatterChart.razor.cs
// Days in three cities: temperature in °C (X) and ice cream sold (Y).
private readonly DwsChartScatterData _cities = new DwsChartScatterData()
    .AddSeries("Hamburg", DwsColor.Undefined,
        new(12, 180, "Mon"), new(15, 230, "Tue"), new(17, 260, "Wed"), new(19, 310, "Thu"), new(22, 380, "Fri"))
    .AddSeries("Munich", DwsColor.Undefined,
        new(14, 210, "Mon"), new(18, 290, "Tue"), new(21, 350, "Wed"), new(24, 420, "Thu"), new(26, 470, "Fri"))
    .AddSeries("Berlin", DwsColor.Undefined, DwsChartScatterMarker.Triangle,
        [new(13, 240, "Mon"), new(16, 250, "Tue"), new(20, 330, "Wed"), new(23, 400, "Thu"), new(25, 430, "Fri")]);

// Series of their own color: .AddSeries("Hamburg", 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;

No data

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

No data to display
Show Code
ScatterChart.razor
<DwsChartScatter Name='ScatterChartDemo_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 point 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).
GetTrendLine DwsChartScatterTrend? int seriesIndex The least-squares trend line of the series at this position (Slope, Intercept, RSquared, Count, MinX, MaxX, ValueAt(x)), whether or not it is drawn. Null for a series with fewer than two points or all at the same X.
Name Typ Default Description
ChartData DwsChartScatterData? null The series to draw: each DwsChartScatterSeries has a Name, a Color (DwsColor; Undefined takes the next palette color), a Marker (DwsChartScatterMarker; Auto takes Circle, Square, Diamond, Triangle in turn), an optional Tag and Points of X, Y and an optional Label and Tag. AddSeries(name, color, points...), AddSeries(name, color, marker, [points]) and AddPoint(x, y, 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.
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.
MarkerSize int 10 Width and height in px of every marker (at least 4). Each point stays a touch target of at least 24px, and the plot is inset by half a marker so points 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). Points outside a fixed range stay at the edge.
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.
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.
ShowTrendLine bool false Draws the least-squares trend line of every shown series with at least two different X, from its lowest to its highest X, dashed in the series' color and cut off at the axes' range.
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, with its color and marker.
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 and trend line, clicking it again shows it. The axes keep their range. Series stay hidden while the data keeps the same number of series.
NearestPointPicking bool true Where several points lie under the mouse pointer, the one whose center is nearest gets the hover and the click instead of the one drawn last, so a point half hidden under a later series can be reached. Done by a script that raises that point; no round trip to .NET. Touch is not affected. Points on exactly the same spot still cover each other.
ShowTooltip bool true Shows the values of the hovered, focused or tapped point. Escape hides it until the next point; a tap on the empty plot puts a tapped point's tooltip away.
TooltipTemplate RenderFragment<DwsChartScatterItem>? null Content of the tooltip. Null shows the name and the two values.
HighlightOnHover bool true Fades the other series (and their trend lines) while the pointer is on a point 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. The trend line is not drawn on a logarithmic axis.
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<DwsChartScatterItem>> 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.
OnPointClick EventCallback<DwsChartScatterItem> Raised when a point is clicked, tapped or activated with Enter/Space. Not raised while disabled or in permission select mode (a click then selects the chart).
OnPointHover EventCallback<DwsChartScatterItem?> Raised when the pointer, focus or a tap enters a point, and with null when none is on a point any more: also when the chart stops reacting or the point's series is hidden.
OnLegendItemClick EventCallback<DwsChartScatterSeries> 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.