Skip to content

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

Nothing is downloaded until you press it.

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

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.
categoryPaddingfloat0.3fShare of each period's slot left as gap, 0 to 0.9.
maxBodyWidthfloat14.0fA 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.
categoriesstd::vector<std::string>
categoryAxisfloat22.0fRoom for the category names. Zero draws none.
rising optionalstd::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 optionalstd::optional<Token>As above, for the other direction.
hollowRisingboolfalseDraw 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.
lineWidthfloat1.0fWidth of the wick, and of a hollow body's outline.
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.
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.