Stock Chart
ProCandles with a range navigator and preset ranges, a volume pane, SMA / EMA / Bollinger overlays and an RSI or MACD pane. Indicators are computed over the whole history and every value is in the table. Pure SVG.
</>sv-stock-chart chartstockcandlestickohlcfinancialnavigatorindicatorssmaemabollingerrsimacd
import { SvStockChartComponent } from '@styloviz-pro/charts/stock-chart';Demo & usage
Basic usage
Usage example — open the gallery for the full interactive demo.
Pro
An interactive demo for this component lives in the gallery.
Open live demoMore examples
Preset ranges, two-way range
Moving averages
Bollinger bands
RSI or MACD pane
The figures without the chart
When to use
A long price history where the reader needs to zoom into a period without losing where it sits in the whole. Technical analysis: moving averages, Bollinger bands, RSI or MACD read against the candles they were computed from. For a short history with no indicators, the Candlestick chart is simpler and has no navigator to explain.
Async states
- loading
- empty
- error
- retry
Inputs
| Name | Type | Default | Description |
|---|---|---|---|
| loading | boolean | false | True while the sessions are being fetched. |
| error | SvDataError | string | null | null | Load failure. Use `toSvDataError()` from `@styloviz/core` to normalize an `HttpErrorResponse`. |
| emptyMessage | string | 'No sessions to plot' | Copy for the no-data state. |
| filtered | boolean | false | True when the emptiness is caused by a filter rather than an empty set. |
| sessions | readonly SvCandle[] | [] | Trading sessions, oldest first — the WHOLE history, not the part in view. The navigator draws all of it and the indicators are computed over all of it, so a 50-session average has a value on the first session in view. Same rules as `sv-candlestick-chart`: the axis is ordinal (do not pad weekends), labels are printed verbatim and need not be unique. |
| splits | readonly SvCandleSplit[] | [] | Share splits to back-adjust across — see `sv-candlestick-chart`. The indicators are computed on the adjusted prices, so a split is not a crash in the moving averages either. |
| priceScale | SvPriceScale | 'linear' | How the price axis is spaced; `log` falls back to linear when it cannot be drawn. |
| minSlotWidth | number | 3 | Narrowest slot, in pixels, a single session may be drawn in before consecutive sessions in view are merged into one candle. `0` turns merging off. |
| range | SvStockRange | null (two-way) | null | The sessions in view, by position: `{ start, end }` with `end` excluded. Positions count the sessions that could be drawn — the same as in `sessions` unless one was dropped for a missing price. Two-way: the navigator and the presets write it, so a host can persist or restore it. `null` shows the newest `defaultWindow` and keeps following the newest session as a live feed appends them. |
| defaultWindow | number | 0 | Sessions in view while `range` is `null` — the newest ones. `0` shows them all. |
| rangePresets | readonly SvStockRangePreset[] | [] | Preset buttons above the plot, e.g. `{ label: '1M', sessions: 21 }`; `sessions: 0` is "all". |
| showNavigator | boolean | true | Draw the navigator — the whole history in miniature, with the range in view as a draggable window. |
| overlays | readonly SvStockOverlay[] | [] | Indicators drawn over the prices: `{ type: 'sma' | 'ema', period }` or `{ type: 'bollinger', period?: 20, multiplier?: 2 }`, each with an optional `color`. Computed over the whole history by `svSma` / `svEma` / `svBollinger` from `@styloviz/core` (re-exported by `@styloviz/data`). |
| oscillator | SvStockOscillator | null | null | An oscillator in its own pane: `{ type: 'rsi', period?: 14 }` or `{ type: 'macd', fast?: 12, slow?: 26, signal?: 9 }`. |
| showVolume | boolean | true | Draw the volume pane beneath the prices, when the sessions carry volume. |
| width | number | 720 | Plot width in pixels. |
| height | number | 520 | Plot height in pixels, every pane and the navigator included. |
| upColor | string | 'var(--color-accent-500)' | Colour for a rising session. |
| downColor | string | 'var(--color-danger-500)' | Colour for a falling session. |
| pricePrefix | string | '' | Currency or unit prefix for prices, e.g. `$`. |
| title | string | '' | Chart title, rendered above the plot. |
| ariaLabel | string | '' | Accessible name override. Falls back to a generated summary. |
| customClass | string | '' | Extra CSS classes applied to the root wrapper. |
Outputs
| Event | Payload type | Description |
|---|---|---|
| retry | void | The host should re-run the failed load. |
| sessionHover | SvStockSessionEvent | Emitted when a session is hovered or keyboard-focused. |
| sessionSelect | SvStockSessionEvent | Emitted when a session is clicked or activated with Enter/Space. |
| rangeChange | SvStockRange | null | Emits the new `range` whenever it changes — the output half of `[(range)]`. |
Customization & theming
`defaultWindow` (sessions in view while `range` is null), `rangePresets` (buttons over the plot; `sessions: 0` is "all") and `showNavigator`. `overlays`: `sma` / `ema` with a `period`, or `bollinger` with `period` (20) and `multiplier` (2); each takes an optional `color`. Periods are rounded to whole sessions, at least one. `oscillator`: `rsi` (`period` 14, Wilder) or `macd` (`fast` 12, `slow` 26, `signal` 9). `showVolume`, `priceScale` (linear or log, with the fallback named), `splits` (back-adjusted before the indicators are computed) and `minSlotWidth` merging, as on the Candlestick chart. Up and down colours, a currency prefix, plot size.
Best practices
Do: Pass the WHOLE history, not the part you want on screen. Indicators are computed over every session and then cut to the view, so a 50-session average has a value on the first session in view. Computed on the slice, it would be blank for most of a quarter — or a shorter average wearing the wrong name. Do: Bind `[(range)]` when the view should survive a reload. It is two-way: the navigator and the presets write it, and a range saved against a longer history is clamped to the nearest valid one rather than drawing an empty chart. Leave it `null` to follow the newest `defaultWindow` sessions as a live feed appends them. Don't: Do not pad weekends, holidays or halts — the axis is ordinal, exactly as on the Candlestick chart. A padded session is a candle that never traded, and it would also shift every moving average by a session that did not happen. Don't: Do not swap MACD's periods to make it draw. A fast period that is not shorter than the slow one is refused and said under the chart, because silently swapping them draws an indicator nobody asked for. Tip: The same arithmetic is public: `svSma`, `svEma`, `svBollinger`, `svRsi` and `svMacd` from `@styloviz/data` return an array the length of their input with `null` through each warm-up, so a server report and the chart agree to the cent.
Accessibility
The navigator is three sliders — the window (pans) and its two handles (resize) — each named and with a value text giving the first and last session in view. Arrows step one session, Page Up/Down a tenth of the history, Home/End go to the ends. Pointer drags on the strip do the same jobs. The candles are ONE tab stop: arrows walk the sessions in view, Home/End jump to the ends, Enter/Space select. Each candle is named with its direction as a word and all four prices. Every indicator line is named in words in the legend and has its own column in `sv-data-summary-table`, beside the prices, for every session in view. A warm-up cell is blank, never zero — a zero is a price. The note under the chart says which part of the history is in view, and when an indicator's warm-up reaches into it, where the line begins and why. Preset buttons are native buttons with `aria-pressed` on the one matching the view.
Feedback on Stock Chart
Spotted a gap in this page, or something that didn't work as described? Comments are GitHub Discussions in the public styloviz/community repo, so posting needs a GitHub account.