Skip to content

BarChart

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

Bars, columns or lollipops over a shared scale. One function rather than four because they differ only in how a value is turned into a rectangle: transposing the axes gives a bar chart from a column chart, stacking changes where each bar starts, and a lollipop is a bar drawn as a stem. Splitting them would mean four copies of the scale, the axis, the grid and the hit testing.

The same bars, showing only view of the categories and letting the reader move it. The view is the caller's, like everything else here, and sharing one is the point: a volume chart handed the same ChartView as the price chart above it zooms when that one is swept, because they are looking at the same window of the same data rather than each keeping their own idea of it.

API

BarChartOptions

OptionTypeDefaultWhat it does
scaleScale0.0, 0.0Fixed bounds. Left as they are, the chart takes them from the data.
autoScalebooltrue
tickCount optionalstd::optional<int>Each of these falls back to Design::chart when unset.
axisWidth optionalstd::optional<float>Room for the value labels. Zero draws none.
heightfloat160.0f
grid optionalstd::optional<bool>
hoverbooltrue
valueFormatstd::string_view"%.0f"std::snprintf style, for the value labels and readouts.
horizontalboolfalseBars run left to right from a category axis down the side, instead of bottom to top from one along the bottom. Long category names are the usual reason: horizontal gives them room to be read.
groupingBarGrouping
Grouped · Stacked
BarGrouping::GroupedHow several series share a category: side by side, or on top of each other.
shapeBarShape
Bar · Lollipop
BarShape::BarA filled rectangle from the baseline, or a stem with a dot at the value.
categoryPaddingfloat0.28fShare of each category's slot left as gap, 0 to 0.9.
seriesGapfloat2.0fBetween the bars of different series in one category, in pixels.
radiusfloat2.0f
categoriesstd::vector<std::string>Names along the category axis. Fewer than there are values leaves the rest unlabelled rather than renumbering them.
categoryAxisfloat22.0fRoom for the category names. Zero draws none.
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.