Charts
Chart analysis
Trendlines (linear, exponential, logarithmic, polynomial, power, moving average) with forecasts, technical indicators in panes, and empty-point handling.
Trendlines
series.trendlines adds fitted lines to a series:
{ xField: 'x', yField: 'y', trendlines: [{ kind: 'polynomial', order: 3, forecast: { forward: 5 }, name: 'Trend' }] }
kind is 'linear', 'exponential', 'logarithmic', 'polynomial'
(order 2 to 6), 'power' or 'movingAverage' (period); the math
lives in the internal chart engine. forecast: { forward, backward } extends the line, intercept forces it through (0, intercept), name and color label it; each trendline gets its own
legend entry and tooltip. markers (true or marker options,
default off) draws points on the line, one per data point up to 256 on a
fitted line; tooltip: false leaves the line out of the tooltip and
keyboard focus (default: the series' tooltip).
Trendlines and empty points
Open demoFit a linear, exponential, logarithmic, polynomial, power or moving-average trendline with a forecast, a forced intercept and markers, and choose how missing values are drawn.
Scatter chart: Monthly units with a trendline, 1 series, Month from 5 to 30. Units: 24 points, minimum 40, maximum 153, trending up.
| Month | Units |
|---|---|
| 1 | 40 |
| 2 | 52 |
| 3 | 41 |
| 4 | 45 |
| 5 | 63 |
| 6 | 57 |
| 7 | 54 |
| 8 | 72 |
| 9 | 75 |
| 10 | 66 |
| 11 | 81 |
| 12 | 93 |
| 13 | 83 |
| 14 | 91 |
| 15 | 109 |
| 16 | 104 |
| 17 | 104 |
| 18 | 124 |
| 19 | 127 |
| 20 | 121 |
| 21 | 139 |
| 22 | 150 |
| 23 | 142 |
| 24 | 153 |
Line chart: Sensor readings with missing values, 1 series, x from 8:00 to 19:00. Reading: 8 points, minimum 12, maximum 19, trending up.
| x | Reading |
|---|---|
| 8:00 | 12 |
| 9:00 | 14 |
| 10:00 | |
| 11:00 | 17 |
| 12:00 | 19 |
| 13:00 | |
| 14:00 | |
| 15:00 | 18 |
| 16:00 | 16 |
| 17:00 | 15 |
| 18:00 | |
| 19:00 | 13 |
Technical indicators
indicators computes indicators over a series, reactively (a new array is
a new layout; there is no refresh method):
import { technicalIndicators } from '@salmonui/charts/chart/indicators';
<Chart
data={prices}
panes={{ rows: ['70%', '30%'] }}
axes={[{ id: 'oscillator', direction: 'y', pane: { row: 1 }, min: 0, max: 100 }]}
series={[{ id: 'price', type: 'candle', xField: 'date', openField: 'open', highField: 'high', lowField: 'low', closeField: 'close', volumeField: 'volume' }]}
indicators={[
{ kind: 'sma', seriesId: 'price', period: 20 },
{ kind: 'bollinger', seriesId: 'price', period: 20, deviations: 2 },
{ kind: 'rsi', seriesId: 'price', yAxis: 'oscillator', zones: { upper: 70, lower: 30 } },
]}
features={[technicalIndicators]}
/>
kind |
Options | Drawn as |
|---|---|---|
'sma', 'ema', 'tma' |
period (14), field ('close', 'open', 'high', 'low') |
a line on the series axis |
'momentum', 'rsi' |
period, zones (RSI: 70 / 30) |
a line; zones are two axis lines and a band |
'atr', 'accumulationDistribution' |
period; A/D reads series.volumeField |
a line |
'bollinger' |
period (20), deviations (2) |
a range area and the middle line |
'macd' |
fastPeriod (12), slowPeriod (26), signalPeriod (9), display: 'line' | 'histogram' | 'both' |
MACD and signal lines, histogram columns |
'stochastic' |
kPeriod (14), dPeriod (3), zones (80 / 20) |
%K and %D lines |
The moving averages and Bollinger bands share the price axis. Every other
kind goes to indicator.yAxis, usually an axis in its own pane
(panes, axis.pane, see Chart axes), or to a
generated secondary axis when none is named. name and color
(a data color) label and color it; each indicator series has a legend
entry and tooltip.
Loading
Indicators are an opt-in feature: pass features={[technicalIndicators]} from
@salmonui/charts/chart/indicators. The feature renders on the server and
the client alike; a chart without it never loads the indicator code (and
warns in development when indicators is set). Trendlines are part of
@salmonui/charts/chart itself.
Technical indicators
Open demoMoving averages and Bollinger bands over a candle series, and RSI, momentum, ATR, accumulation distribution, MACD or stochastic in a lower pane, with zones and MACD display options.
Candlestick chart: Technical indicators. No data.
| x | Price |
|---|---|
| Apr 1 | O 50 H 50.8 L 49.3 C 50 V 5,000 |
| Apr 2 | O 52.21 H 54.52 L 51.26 C 53.42 V 6,777 |
| Apr 3 | O 52.3 H 53.7 L 49.88 C 51.08 V 8,554 |
| Apr 4 | O 51.23 H 52.06 L 49.78 C 51.26 V 6,331 |
| Apr 5 | O 51.65 H 53.95 L 50.95 C 52.85 V 8,108 |
| Apr 6 | O 53.99 H 55.39 L 51.81 C 52.76 V 5,885 |
| Apr 7 | O 55.81 H 56.66 L 54.61 C 55.86 V 7,662 |
| Apr 8 | O 55.39 H 57.67 L 53.94 C 56.57 V 5,439 |
| Apr 9 | O 54.22 H 55.62 L 52.27 C 52.97 V 7,216 |
| Apr 10 | O 54.81 H 55.68 L 53.86 C 54.88 V 8,993 |
| Apr 11 | O 57.01 H 59.28 L 55.81 C 58.18 V 6,770 |
| Apr 12 | O 58.22 H 59.62 L 55.52 C 56.97 V 8,547 |
| Apr 13 | O 57.19 H 58.09 L 56.49 C 57.29 V 6,324 |
| Apr 14 | O 55.86 H 58.12 L 54.91 C 57.02 V 8,101 |
| Apr 15 | O 56.49 H 57.89 L 54.03 C 55.23 V 5,878 |
| Apr 16 | O 58.38 H 59.3 L 56.93 C 58.5 V 7,655 |
| Apr 17 | O 58.87 H 61.11 L 58.17 C 60.01 V 5,432 |
| Apr 18 | O 57.24 H 58.64 L 55.01 C 55.96 V 7,209 |
| Apr 19 | O 55.78 H 56.72 L 54.58 C 55.92 V 8,986 |
| Apr 20 | O 56.42 H 58.65 L 54.97 C 57.55 V 6,763 |
| Apr 21 | O 57.92 H 59.32 L 55.93 C 56.63 V 8,540 |
| Apr 22 | O 57.68 H 58.64 L 56.73 C 57.84 V 6,317 |
| Apr 23 | O 55.57 H 57.79 L 54.37 C 56.69 V 8,094 |
| Apr 24 | O 54.12 H 55.52 L 51.38 C 52.83 V 5,871 |
| Apr 25 | O 54.82 H 55.81 L 54.12 C 55.01 V 7,648 |
| Apr 26 | O 55.96 H 58.16 L 55.01 C 57.06 V 5,425 |
| Apr 27 | O 55.13 H 56.53 L 52.63 C 53.83 V 7,202 |
| Apr 28 | O 52.77 H 53.78 L 51.32 C 52.98 V 8,979 |
| Apr 29 | O 51.54 H 53.73 L 50.84 C 52.63 V 6,756 |
| Apr 30 | O 52.42 H 53.82 L 50.16 C 51.11 V 8,533 |
| May 1 | O 53.3 H 54.34 L 52.1 C 53.54 V 6,310 |
| May 2 | O 52.08 H 54.26 L 50.63 C 53.16 V 8,087 |
| May 3 | O 49.75 H 51.15 L 47.74 C 48.44 V 5,864 |
| May 4 | O 48.97 H 50.03 L 48.02 C 49.23 V 7,641 |
| May 5 | O 50.16 H 52.32 L 48.96 C 51.22 V 5,418 |
| May 6 | O 50.92 H 52.32 L 48.14 C 49.59 V 7,195 |
| May 7 | O 49.54 H 50.62 L 48.84 C 49.82 V 8,972 |
| May 8 | O 47.51 H 49.65 L 46.56 C 48.55 V 6,749 |
| May 9 | O 47.36 H 48.76 L 44.83 C 46.03 V 8,526 |
| May 10 | O 48.96 H 50.06 L 47.51 C 49.26 V 6,303 |
| May 11 | O 49.69 H 51.82 L 48.99 C 50.72 V 8,080 |
| May 12 | O 48.33 H 49.73 L 46.04 C 46.99 V 5,857 |
| May 13 | O 46.81 H 47.94 L 45.61 C 47.14 V 7,634 |
| May 14 | O 47.41 H 49.52 L 45.96 C 48.42 V 5,411 |
| May 15 | O 49.4 H 50.8 L 47.36 C 48.06 V 7,188 |
| May 16 | O 50.14 H 51.29 L 49.19 C 50.49 V 8,965 |
| May 17 | O 48.91 H 51 L 47.71 C 49.9 V 6,742 |
| May 18 | O 47.98 H 49.38 L 45.18 C 46.63 V 8,519 |
| May 19 | O 49.29 H 50.46 L 48.59 C 49.66 V 6,296 |
| May 20 | O 51.58 H 53.66 L 50.63 C 52.56 V 8,073 |
| May 21 | O 52.25 H 53.65 L 49.69 C 50.89 V 5,850 |
| May 22 | O 51.15 H 52.34 L 49.7 C 51.54 V 7,627 |
| May 23 | O 50.8 H 52.86 L 50.1 C 51.76 V 5,404 |
| May 24 | O 52.67 H 54.07 L 50.36 C 51.31 V 7,181 |
| May 25 | O 55.05 H 56.27 L 53.85 C 55.47 V 8,958 |
| May 26 | O 55.5 H 57.55 L 54.05 C 56.45 V 6,735 |
| May 27 | O 54.46 H 55.86 L 52.39 C 53.09 V 8,512 |
| May 28 | O 54.56 H 55.8 L 53.61 C 55 V 6,289 |
| May 29 | O 56.77 H 58.79 L 55.57 C 57.69 V 8,066 |
| May 30 | O 58.96 H 60.36 L 56.14 C 57.59 V 5,843 |
| May 31 | O 59.02 H 60.28 L 58.32 C 59.48 V 7,620 |
| Jun 1 | O 57.91 H 59.92 L 56.96 C 58.82 V 5,397 |
| Jun 2 | O 58.29 H 59.69 L 55.71 C 56.91 V 7,174 |
| Jun 3 | O 60.57 H 61.85 L 59.12 C 61.05 V 8,951 |
| Jun 4 | O 62.32 H 64.31 L 61.62 C 63.21 V 6,728 |
| Jun 5 | O 61.82 H 63.22 L 59.49 C 60.44 V 8,505 |
| Jun 6 | O 60.56 H 61.87 L 59.36 C 61.07 V 6,282 |
| Jun 7 | O 61.06 H 63.03 L 59.61 C 61.93 V 8,059 |
| Jun 8 | O 63.17 H 64.57 L 61.08 C 61.78 V 5,836 |
| Jun 9 | O 64.27 H 65.6 L 63.32 C 64.8 V 7,613 |
| Jun 10 | O 63.14 H 65.09 L 61.94 C 63.99 V 5,390 |
| Jun 11 | O 61.7 H 63.1 L 58.86 C 60.31 V 7,167 |
| Jun 12 | O 62.23 H 63.58 L 61.53 C 62.78 V 8,944 |
| Jun 13 | O 64.01 H 65.95 L 63.06 C 64.85 V 6,721 |
| Jun 14 | O 64.39 H 65.79 L 61.8 C 63 V 8,498 |
| Jun 15 | O 62.66 H 64.03 L 61.21 C 63.23 V 6,275 |
| Jun 16 | O 61.1 H 63.02 L 60.4 C 61.92 V 8,052 |
| Jun 17 | O 61.66 H 63.06 L 59.31 C 60.26 V 5,829 |
| Jun 18 | O 63.07 H 64.46 L 61.87 C 63.66 V 7,606 |
| Jun 19 | O 62.76 H 64.65 L 61.31 C 63.55 V 5,383 |
| Jun 20 | O 60.58 H 61.98 L 58.49 C 59.19 V 7,160 |
| Jun 21 | O 59.08 H 60.49 L 58.13 C 59.69 V 8,937 |
| Jun 22 | O 59.73 H 61.61 L 58.53 C 60.51 V 6,714 |
| Jun 23 | O 60.83 H 62.23 L 57.99 C 59.44 V 8,491 |
| Jun 24 | O 59.98 H 61.41 L 59.28 C 60.61 V 6,268 |
| Jun 25 | O 57.61 H 59.46 L 56.66 C 58.36 V 8,045 |
| Jun 26 | O 56.37 H 57.77 L 53.77 C 54.97 V 5,822 |
| Jun 27 | O 57.27 H 58.72 L 55.82 C 57.92 V 7,599 |
| Jun 28 | O 58.17 H 60.01 L 57.47 C 58.91 V 5,376 |
| Jun 29 | O 56.98 H 58.38 L 54.63 C 55.58 V 7,153 |
Empty points
series.emptyPoints decides what a missing value does: 'gap' (default)
breaks the line, 'zero' plots 0, 'average' the mean of the neighbors,
'drop' skips the point.
The trendlines demo above also switches emptyPoints. ChartTrendline
and ChartIndicator are in the API reference,
technicalIndicators in
@salmonui/charts/chart/indicators.