Skip to content

ScatterChart

scatterChart · Charts · interactive

Charts: a scale, its ticks, and a line or area drawn from data.

Import

cpp
#include "gbui/widgets/chart.hpp"

Example

Nothing is downloaded until you press it.

cpp
ScatterResult scatterChart(Ui& ui, const Interaction& input, std::string_view id, const std::vector<PointSeries>& series, const ScatterOptions& options = {});

Points on two continuous scales — a scatter, or a bubble chart when the points carry weights. The first chart here with a real x scale. Every other one indexes its samples along the bottom: sample 0 at the left, sample n at the right, evenly spaced whatever their x values are. That is right for a series over time and wrong for a correlation, where the whole question is where the points sit against each other on both axes. Hit testing is by distance to the nearest dot rather than by column, because a scatter has no columns — two points can share an x and mean different things.

API

ScatterOptions

OptionTypeDefaultWhat it does
xScaleScale0.0, 0.0Fixed bounds for each axis. Left alone, both come from the data.
yScaleScale0.0, 0.0As above, for the other one.
autoScalebooltrue
tickCount optionalstd::optional<int>
axisWidth optionalstd::optional<float>
heightfloat220.0f
grid optionalstd::optional<bool>
hoverbooltrue
valueFormatstd::string_view"%.0f"
xFormatstd::string_view"%.0f"The same, for the x value. Two formats because the axes are two different quantities — seconds against dollars.
xAxisfloat20.0fRoom under the plot for the x labels. Zero draws none.
minRadiusfloat5.0fThe radii the weights are spread across, when there are weights.
maxRadiusfloat26.0f
fillAlphafloat0.6fHow solid a dot is. Under one on purpose: overlapping points then read as denser rather than hiding each other, and density is most of the information in a crowded scatter.
hitRadiusfloat14.0fHow near the pointer has to be, in pixels, to pick a dot.
tooltipChartTooltip
legendChartLegend
namestd::string_viewWhat the chart is of — "Revenue by month". A chart is the one thing on a screen a reader gets nothing from: the shapes carry all of it, and the numbers behind them are the caller's. A name and a Figure role are the least that makes it navigable, and they are not the whole answer — see the note in docs/reference/accessibility.

Released under the LGPL-3.0-or-later licence.