Skip to content

LineChart

lineChart · 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
ChartResult lineChart(Ui& ui, const Interaction& input, std::string_view id, const std::vector<Series>& series, const ChartOptions& options = {});
cpp
ChartResult lineChart(Ui& ui, const Interaction& input, std::string_view id, const std::vector<Series>& series, ChartView& view, const ChartOptions& options = {}, const ChartZoom& zoom = {});

Draws one or more series over a shared scale. The geometry is built here and handed to Ui::draw, so the whole chart is one node plus its labels rather than a widget per mark. Hit testing is on the index — the pointer's x is turned back into a sample number — which is what lets a tooltip name the right point instead of the nearest pixel.

The same chart, showing only view of the data and letting the reader move it. The view is the caller's, like every other piece of state here — which is what lets two charts share one, so panning a line chart pans the bars under it.

API

ChartOptions

OptionTypeDefaultWhat it does
scaleScale0.0, 0.0Fixed bounds. Left as they are, the chart takes them from the data — which is what a live readout wants and what a comparison does not.
autoScalebooltrue
tickCount optionalstd::optional<int>Each of these falls back to Design::chart when it is not set, so a dashboard configures its charts once instead of per call site.
axisWidth optionalstd::optional<float>Room for the value labels down the left. Zero draws none.
heightfloat120.0f
grid optionalstd::optional<bool>
hoverbooltrueA crosshair and a readout following the pointer.
valueFormatstd::string_view"%.0f"Printed beside a hovered value; "%.0f" style, as std::snprintf takes.
categoriesstd::vector<std::string>Names for the samples, used as the readout's heading.
tooltipChartTooltip
linkChartLink*nullptrTies this chart's readout to the other charts sharing the same ChartLink, so pointing at a sample in one points at it in all of them. Null leaves the chart on its own.
legendChartLegendThe key drawn under the chart, and the focus a click on it gives.
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.