Stock Chart

Pro

Candles 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

Pro

Usage example — open the gallery for the full interactive demo.

Pro

An interactive demo for this component lives in the gallery.

Open live demo

More examples

Preset ranges, two-way range

Pro

Moving averages

Pro

Bollinger bands

Pro

RSI or MACD pane

Pro

The figures without the chart

Pro

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

NameTypeDefaultDescription
loadingbooleanfalseTrue while the sessions are being fetched.
errorSvDataError | string | nullnullLoad failure. Use `toSvDataError()` from `@styloviz/core` to normalize an `HttpErrorResponse`.
emptyMessagestring'No sessions to plot'Copy for the no-data state.
filteredbooleanfalseTrue when the emptiness is caused by a filter rather than an empty set.
sessionsreadonly 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.
splitsreadonly 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.
priceScaleSvPriceScale'linear'How the price axis is spaced; `log` falls back to linear when it cannot be drawn.
minSlotWidthnumber3Narrowest slot, in pixels, a single session may be drawn in before consecutive sessions in view are merged into one candle. `0` turns merging off.
rangeSvStockRange | null (two-way)nullThe 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.
defaultWindownumber0Sessions in view while `range` is `null` — the newest ones. `0` shows them all.
rangePresetsreadonly SvStockRangePreset[][]Preset buttons above the plot, e.g. `{ label: '1M', sessions: 21 }`; `sessions: 0` is "all".
showNavigatorbooleantrueDraw the navigator — the whole history in miniature, with the range in view as a draggable window.
overlaysreadonly 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`).
oscillatorSvStockOscillator | nullnullAn oscillator in its own pane: `{ type: 'rsi', period?: 14 }` or `{ type: 'macd', fast?: 12, slow?: 26, signal?: 9 }`.
showVolumebooleantrueDraw the volume pane beneath the prices, when the sessions carry volume.
widthnumber720Plot width in pixels.
heightnumber520Plot height in pixels, every pane and the navigator included.
upColorstring'var(--color-accent-500)'Colour for a rising session.
downColorstring'var(--color-danger-500)'Colour for a falling session.
pricePrefixstring''Currency or unit prefix for prices, e.g. `$`.
titlestring''Chart title, rendered above the plot.
ariaLabelstring''Accessible name override. Falls back to a generated summary.
customClassstring''Extra CSS classes applied to the root wrapper.

Outputs

EventPayload typeDescription
retryvoidThe host should re-run the failed load.
sessionHoverSvStockSessionEventEmitted when a session is hovered or keyboard-focused.
sessionSelectSvStockSessionEventEmitted when a session is clicked or activated with Enter/Space.
rangeChangeSvStockRange | nullEmits 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.

Loads giscus.app and GitHub — nothing is fetched until you click.