BarChart
barChart · Charts · interactive
Charts: a scale, its ticks, and a line or area drawn from data.
Import
#include "gbui/widgets/chart.hpp"Example
Nothing is downloaded until you press it.
ChartResult barChart(Ui& ui, const Interaction& input, std::string_view id, const std::vector<Series>& series, const BarChartOptions& options = {});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
| Option | Type | Default | What it does |
|---|---|---|---|
scale | Scale | 0.0, 0.0 | Fixed bounds. Left as they are, the chart takes them from the data. |
autoScale | bool | true | |
tickCount optional | std::optional<int> | Each of these falls back to Design::chart when unset. | |
axisWidth optional | std::optional<float> | Room for the value labels. Zero draws none. | |
height | float | 160.0f | |
grid optional | std::optional<bool> | ||
hover | bool | true | |
valueFormat | std::string_view | "%.0f" | std::snprintf style, for the value labels and readouts. |
horizontal | bool | false | Bars 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. |
grouping | BarGroupingGrouped · Stacked | BarGrouping::Grouped | How several series share a category: side by side, or on top of each other. |
shape | BarShapeBar · Lollipop | BarShape::Bar | A filled rectangle from the baseline, or a stem with a dot at the value. |
categoryPadding | float | 0.28f | Share of each category's slot left as gap, 0 to 0.9. |
seriesGap | float | 2.0f | Between the bars of different series in one category, in pixels. |
radius | float | 2.0f | |
categories | std::vector<std::string> | Names along the category axis. Fewer than there are values leaves the rest unlabelled rather than renumbering them. | |
categoryAxis | float | 22.0f | Room for the category names. Zero draws none. |
tooltip | ChartTooltip | ||
link | ChartLink* | nullptr | Ties 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. |
legend | ChartLegend | The key drawn under the chart, and the focus a click on it gives. | |
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. |