The Candlestick Series type
Candlestick Series or JavaScript Stock Charts can be created using the FastCandlestickRenderableSeries type📘.
tip
The JavaScript Candlestick Chart Example can be found in the SciChart.Js Examples Suite > Candlestick Chart on Github, or our live demo at scichart.com/demo.
Above: The JavaScript Candlestick Series Chart example from the SciChart.js Demo
Create a Candlestick Series
To create a Javascript Candlestick Chart with SciChart.js, use the following code:
- TS
- Builder API (JSON Config)
// Demonstrates how to create a Candlestick chart with SciChart.js
const {
SciChartSurface,
CategoryAxis,
NumericAxis,
FastCandlestickRenderableSeries,
OhlcDataSeries,
SciChartJsNavyTheme
} = SciChart;
// or, for npm, import { SciChartSurface, ... } from "scichart"
const { wasmContext, sciChartSurface } = await SciChartSurface.create(divElementId, {
theme: new SciChartJsNavyTheme()
});
sciChartSurface.xAxes.add(new CategoryAxis(wasmContext));
sciChartSurface.yAxes.add(
new NumericAxis(wasmContext, {
labelPrefix: "$",
labelPrecision: 2
})
);
// Data format is { dateValues[], openValues[], highValues[], lowValues[], closeValues[] }
const { dateValues, openValues, highValues, lowValues, closeValues, volumeValues } = await getCandles(
"BTCUSDT",
"1h",
100
);
// Create and add the Candlestick series
const candlestickSeries = new FastCandlestickRenderableSeries(wasmContext, {
dataSeries: new OhlcDataSeries(wasmContext, {
xValues: dateValues,
openValues,
highValues,
lowValues,
closeValues
}),
strokeThickness: 1,
dataPointWidth: 0.7,
brushUp: "#33ff3377",
brushDown: "#ff333377",
strokeUp: "#77ff77",
strokeDown: "#ff7777"
});
sciChartSurface.renderableSeries.add(candlestickSeries);
// Demonstrates how to create a line chart with SciChart.js using the Builder API
const { chartBuilder, ESeriesType, EThemeProviderType, EAxisType } = SciChart;
// or, for npm, import { chartBuilder, ... } from "scichart"
// Data format is { dateValues[], openValues[], highValues[], lowValues[], closeValues[] }
const { dateValues, openValues, highValues, lowValues, closeValues, volumeValues } = await getCandles(
"BTCUSDT",
"1h",
100
);
const { wasmContext, sciChartSurface } = await chartBuilder.build2DChart(divElementId, {
surface: { theme: { type: EThemeProviderType.Dark } },
xAxes: [{ type: EAxisType.CategoryAxis }],
yAxes: [{ type: EAxisType.NumericAxis, options: { labelPrefix: "$", labelPrecision: 2 } }],
series: [
{
type: ESeriesType.CandlestickSeries,
ohlcData: {
xValues: dateValues,
openValues,
highValues,
lowValues,
closeValues
},
options: {
dataPointWidth: 0.7,
brushUp: "#33ff3377",
brushDown: "#ff333377",
strokeUp: "#77ff77",
strokeDown: "#ff7777",
strokeThickness: 1
}
}
]
});
This results in the following output:
The above example makes a web call to Binance to fetch Bitcoin/USD prices. If you see a blank chart, check the Js console as this web call may be blocked. You can always edit the Codepen to substitute your own data!
In the example above:
- A Candlestick Series instance is created and added to the SciChartSurface.renderableSeries