Stock Market widgets — plotting your own data (CSV)
Every Stock* chart widget in LightGUI's C++ XFrame set renders from one shared type, xframe::OHLCVSeries (widgets/components/StockData.h). Out of the box each widget ships with deterministic synthetic template data so demos and screenshots are reproducible with no network and no live market data. To plot your own data, load a CSV file into that same series type — the loader lives in StockData.h next to the model, and every series-plotting widget has a one-call way to use it.
The CSV format
One bar per line:
date,open,high,low,close,volume
2026-11-02,150.00,151.20,149.40,150.60,1200000
2026-11-03,150.60,152.10,150.10,151.80,980000- Header row: optional. When the first non-empty line is a header, columns are matched by name and may appear in any order. Recognised names (case-insensitive):
date,timestamp,time,window_start,open,high,low,close,volume(orvol). Anything else (ticker,transactions,adj_close, …) is ignored — Massive aggregates exports load as-is. Without a header the columns are positional:date,open,high,low,close,volume. - Required columns:
open,high,low,close. A header missing any of these is an error. - Dates are read as UTC:
YYYY-MM-DD,YYYY/MM/DD,YYYY-MM-DD HH:MM:SS(or aTseparator, optional trailingZ), or a bare epoch timestamp: seconds (≥ 1e9), milliseconds (≥ 1e12), nanoseconds (≥ 1e15, Massivewindow_start). volumeis optional and defaults to 0. A missing date column — or a headerless 5-column fileopen,high,low,close,volume— gets sequential daily timestamps starting 2026-01-01 UTC.- Blank lines are skipped; a row that does not parse is skipped and counted. Double-quoted fields, CRLF and a UTF-8 BOM are handled. Well-formed rows satisfy
high >= max(open, close)andlow <= min(open, close); the loader keeps the file's values as-is.
Loader API
// From a file. Returns the series; empty + `error` set on failure
// (unreadable file, header missing open/high/low/close, no valid rows).
OHLCVSeries load_ohlcv_csv(const std::string& path, std::string& error,
int* skipped = nullptr);
// From text (same rules; used by the unit tests).
OHLCVSeries parse_ohlcv_csv_text(const std::string& text, std::string& error,
int* skipped = nullptr);error is empty on success — that is the success test. skipped (when given) receives the number of malformed rows skipped.
Single-series charts: load_csv
On all 15 single-series widgets (StockCandlestickChart, StockOHLCBarChart, StockLineChart, StockAreaChart, StockHeikinAshi, StockRenko, StockHollowCandles, StockBaselineChart, StockVolumeBars, StockVolumeCandles, StockVolumeProfile, StockAccumulationDistribution, StockMoneyFlowChart, StockOBVChart, StockVWAP):
StockCandlestickChart w(display, screen, window, gc, &styles, 20, 20, 720, 480);
std::string err;
if (!w.load_csv("aapl_30d.csv", err)) {
std::fprintf(stderr, "cannot load CSV: %s\n", err.c_str());
// The old series is untouched: the chart keeps drawing what it had.
}
w.draw(); // now plots the CSV bars; view resets to show all of themload_csv loads the file and, on success, calls set_series, which resets the view and rebuilds derived data (Heikin-Ashi candles, Renko bricks, the baseline). The same thing spelled out: auto series = xframe::load_ohlcv_csv("aapl_30d.csv", err); if (err.empty()) w.set_series(series); — or pass the loaded series straight to the constructor.
Multi-series charts: add_series_csv
On all 8 comparative widgets (StockOverlayChart, StockMultiSymbolChart, StockIndexedComparison, StockRelativePerformance, StockRatioChart, StockSpreadChart, StockCorrelationView, StockSectorComparison):
StockMultiSymbolChart w(display, screen, window, gc, &styles, 20, 20, 720, 480);
w.clear_series(); // drop the SYM-A/SYM-B/SYM-C template series
std::string err;
w.add_series_csv("aapl_30d.csv", "AAPL", err); // returns false on error
w.add_series_csv("msft_30d.csv", "MSFT", err); // each file is one symbol
w.draw();Clear / populate
w.set_series(xframe::OHLCVSeries{}); // single-series: clear the chart
w.clear_series(); // single-series: same thing
// multi-series:
w.clear_series(); // remove every series
w.add_series_csv("aapl_30d.csv", "AAPL", err); // populate, one file per symbolThere is no add_point: bars are replaced wholesale. item_count() reports how many items are plotted — bars for most widgets, Heikin-Ashi candles for StockHeikinAshi, bricks for StockRenko (30 CSV bars build 25 bricks at the default brick size), and the longest series length for the comparative widgets.
What this does not cover
Drawing / annotation tools (14) — StockTrendline, StockFibRetracement, StockFibExtension, StockPitchfork, StockParallelChannel, StockRectangle, StockEllipse, StockArrow, StockBrush, StockHorizontalLine, StockVerticalLine, StockMeasureTool, StockPriceLabel, StockTextAnnotation — take coordinates (add_point, set_anchor, set_high_low, set_pivots), not a data series. They do draw a background candle series, replaceable with set_series(xframe::load_ohlcv_csv(path, err)).
The 250 Ind* indicator widgets take a series only through their constructor — they have no set_series. Pass a loaded series there: IndSMA w(display, screen, window, gc, &styles, 20, 20, 760, 520, series);
Limits
- No streaming / live updates: the whole file is read at once. To show new bars, re-load the file and call
load_csv/set_seriesagain. - No network, no API keys, no live market data: the loader reads a local file only.
- A file with no valid rows is an error, not an empty chart:
load_csvreturnsfalseand the previous series stays in place. - Dates are read as UTC; the charts plot bars by index, not by clock time.
Tests and fixtures
Repo: tests/data/ohlcv_sample.csv (30 daily bars, first close 150.60, last close 152.25) and tests/data/ohlcv_sample_b.csv (second symbol). widgets/tests/csv_unit_test.cpp covers the parser (Massive format, headerless files, all four date forms, malformed rows, error cases). widgets/tests/test_stock_csv.py screenshots every in-scope widget with the fixture and checks the CSV plot differs from the template plot: 23/23 widgets PASS. Full write-up: docs/stock-market-csv-data.md.