Skip to content

DonutChart

donutChart · 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
DonutResult donutChart(Ui& ui, const Interaction& input, std::string_view id, const std::vector<Slice>& slices, DonutState& state, const DonutOptions& options = {});

A donut, or a pie when thickness is 1. Proof that the canvas node carries more than polylines: each wedge is two arcs and two lines, and an arc is cubics. Nothing here is a special case in the painter — it is the same vector layer the icons ride on.

API

DonutOptions

OptionTypeDefaultWhat it does
sizefloat150.0f
thickness optionalstd::optional<float>How thick the ring is, as a share of the radius. 1 is a full pie. Unset takes the design's.
padAngle optionalstd::optional<float>A gap between wedges, in degrees, so neighbouring colours do not merge.
startAnglefloat-90.0fWhere the first wedge starts. -90 puts it at twelve o'clock, which is where every reader expects a donut to begin.
hoverGrowfloat4.0fThe hovered wedge grows outward by this much.
focusGrowfloat10.0fHow much further a focused wedge pulls out of the ring.
dimAlphafloat0.3fWhat the wedges that were not singled out fade to.
legendbooltrue
legendMaxHeightfloatkAutoA ceiling on the legend before it scrolls, so a chart with forty contributors does not grow taller than the ring beside it. kAuto matches the donut.
tooltipChartTooltipThe readout beside the hovered wedge. A donut's legend already names every slice, so this one is about the number — which the legend has no room for once there are more than a handful.
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.