CandlestickChart
candlestickChart · Charts · interactive
Charts: a scale, its ticks, and a line or area drawn from data.
Import
cpp
#include "gbui/widgets/chart.hpp"Example
cpp
ChartResult candlestickChart(Ui& ui, const Interaction& input, std::string_view id, const std::vector<Candle>& candles, const CandlestickOptions& options = {});cpp
ChartResult candlestickChart(Ui& ui, const Interaction& input, std::string_view id, const std::vector<Candle>& candles, ChartView& view, const CandlestickOptions& options = {}, const ChartZoom& zoom = {});Open, high, low and close per period. The one chart here whose scale deliberately does not reach zero. Every other chart in this file widens its range to include the baseline, because a bar that does not start at zero misstates the ratio between two bars. A price has no such baseline — forcing one on a stock that trades between 180 and 190 squeezes the entire year into the top five percent of the plot and hides the only thing the chart was drawn to show.
The same candles, showing only view of them — the overload a price chart and its volume share, so sweeping either zooms both.
API
CandlestickOptions
| 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. |
categoryPadding | float | 0.3f | Share of each period's slot left as gap, 0 to 0.9. |
maxBodyWidth | float | 14.0f | A ceiling on the body, in pixels, whatever the slot allows. A candle is a mark, not a bar: zooming in should make it taller and put more air around it, not fatten it. Without the ceiling a chart zoomed to a dozen periods draws them as forty-pixel bricks, which is the width of a bar chart's column and reads as one. The default barely bites at a full view — forty-odd candles across a card land near it anyway — and does all its work once the reader has swept a range. |
categories | std::vector<std::string> | ||
categoryAxis | float | 22.0f | Room for the category names. Zero draws none. |
rising optional | std::optional<Token> | Unset takes the theme's added/removed colours, which are already the two a reader of this application associates with up and down. | |
falling optional | std::optional<Token> | As above, for the other direction. | |
hollowRising | bool | false | Draw rising candles as an outline instead of a solid body. The other common convention, and worth having: on a dense chart the hollow bodies recede and the falling ones stand out, which is what a reader watching for drops actually wants. |
lineWidth | float | 1.0f | Width of the wick, and of a hollow body's outline. |
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. |
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. |