Price Scale Modes
The primary y-axis has four modes:
chart.setPriceScale('logarithmic')
chart.setPriceScale('percent')
chart.setPriceScale('indexed', { indexBase: 100 })
chart.setPriceScale('linear')
Or at construction:
const chart = new ApexStock(el, {
priceScale: { mode: 'percent' },
// ...
})
| Mode | Axis reads | Options |
|---|---|---|
'linear' | Price. The default | |
'logarithmic' | Price, on a log axis | logBase, default 10 |
'percent' | Percent change from a baseline | base, defaults to the first bar's close |
'indexed' | An index where the baseline reads indexBase | indexBase, default 100 |
getPriceScale() returns { mode, base, logBase, indexBase }.
Only one of them changes the data
This is the important distinction. percent and indexed are affine relabelings of the axis: the same numbers are drawn in the same places, with different tick text. Nothing else on the chart has to know about them, so indicators, drawings, annotations and trading price lines stay in true price space and are unaffected. A stop loss at 187.40 is still at 187.40.
logarithmic is the one that genuinely changes the gridline distribution, because that is what a log axis is for.
What persists
The mode survives a theme switch, a chart-type switch, and appendData. Under appendData in percent or indexed mode the baseline is recomputed from the current first bar, so a scrolling window rebases rather than drifting.
It is captured by getState() and fires an event on change:
chart.on('priceScaleChange', ({ mode, base, logBase, indexBase }) => {})
Not the same as comparison mode
Percent-change appears in two places and they are separate systems:
priceScale: { mode: 'percent' } | Comparison mode 'percent' | |
|---|---|---|
| Applies to | The primary y-axis label | The normalization of several instruments |
| Baselines on | The series' first bar, or an explicit base | The comparison baseline policy, 'common' by default |
| Affects | Axis text only | What each comparison line plots |
They can be used together, and they answer different questions: one is how the primary's own axis is labelled, the other is how several instruments are made comparable.
See also
- Comparison Mode for normalizing several instruments
- Zoom & Pan for the x-axis window
- Options for the rest of the construction options