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
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
| Option | Type | Default | What it does |
|---|---|---|---|
xScale | Scale | 0.0, 0.0 | Fixed bounds for each axis. Left alone, both come from the data. |
yScale | Scale | 0.0, 0.0 | As above, for the other one. |
autoScale | bool | true | |
tickCount optional | std::optional<int> | ||
axisWidth optional | std::optional<float> | ||
height | float | 220.0f | |
grid optional | std::optional<bool> | ||
hover | bool | true | |
valueFormat | std::string_view | "%.0f" | |
xFormat | std::string_view | "%.0f" | The same, for the x value. Two formats because the axes are two different quantities — seconds against dollars. |
xAxis | float | 20.0f | Room under the plot for the x labels. Zero draws none. |
minRadius | float | 5.0f | The radii the weights are spread across, when there are weights. |
maxRadius | float | 26.0f | |
fillAlpha | float | 0.6f | How 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. |
hitRadius | float | 14.0f | How near the pointer has to be, in pixels, to pick a dot. |
tooltip | ChartTooltip | ||
legend | ChartLegend | ||
name | std::string_view | What 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. |