React OHLC Chart

For this example, we demonstrate how to create a React OHLC Chart or Stock Chart using SciChart.js. This is our powerful JavaScript Chart Component.

Fullscreen

Edit

 Edit

Docs

drawExample.ts

index.tsx

theme.ts

data.ts

Copy to clipboard
Minimise
Fullscreen
1import { closeValues, dateValues as xValues, highValues, lowValues, openValues } from "./data";
2import {
3    CategoryAxis,
4    ENumericFormat,
5    FastOhlcRenderableSeries,
6    MouseWheelZoomModifier,
7    NumericAxis,
8    NumberRange,
9    OhlcDataSeries,
10    SciChartSurface,
11    SmartDateLabelProvider,
12    SweepAnimation,
13    ZoomExtentsModifier,
14    ZoomPanModifier,
15    SciChartJsNavyTheme,
16    DiscontinuousDateAxis,
17} from "scichart";
18
19export const drawExample = async (rootElement: string | HTMLDivElement) => {
20    // Create a SciChartSurface
21    const { sciChartSurface, wasmContext } = await SciChartSurface.create(rootElement, {
22        theme: new SciChartJsNavyTheme(),
23    });
24
25    // Add DiscontinuousDateAxis - which collapses gaps in stock market data
26    sciChartSurface.xAxes.add(
27        new DiscontinuousDateAxis(wasmContext, {
28            labelProvider: new SmartDateLabelProvider(),
29            growBy: new NumberRange(0.05, 0.05),
30        })
31    );
32
33    // Create a NumericAxis on the YAxis with 4 Decimal Places
34    sciChartSurface.yAxes.add(
35        new NumericAxis(wasmContext, {
36            visibleRange: new NumberRange(1.1, 1.2),
37            growBy: new NumberRange(0.1, 0.1),
38            labelFormat: ENumericFormat.Decimal,
39            labelPrecision: 4,
40        })
41    );
42
43    // Create the Ohlc series and add to the chart
44    sciChartSurface.renderableSeries.add(
45        new FastOhlcRenderableSeries(wasmContext, {
46            dataSeries: new OhlcDataSeries(wasmContext, { xValues, openValues, highValues, lowValues, closeValues }),
47            strokeThickness: 1,
48            dataPointWidth: 0.7,
49            strokeUp: "#50ff50",
50            strokeDown: "#ff5050",
51            animation: new SweepAnimation({ duration: 800, fadeEffect: true }),
52        })
53    );
54
55    // Optional: Add some interactivity modifiers
56    sciChartSurface.chartModifiers.add(
57        new ZoomExtentsModifier(),
58        new ZoomPanModifier({ enableZoom: true }),
59        new MouseWheelZoomModifier()
60    );
61
62    sciChartSurface.zoomExtents();
63    return { sciChartSurface, wasmContext };
64};
65

React OHLC Chart

Overview

This React OHLC Chart example demonstrates how to create a high-performance, interactive stock chart using SciChart.js within a React application. The example is specifically designed to render OHLC (Open-High-Low-Close) financial data, showcasing advanced customization options and smooth animations for real-time visualization.

Technical Implementation

The chart is initialized using the <SciChartReact/> component, which delegates the chart setup to a function that creates a SciChartSurface. Within this function, developers add a CategoryAxis configured with a SmartDateLabelProvider for handling non-contiguous stock market dates, and a NumericAxis tailored to display financial values with a fixed decimal precision. The actual OHLC data is processed using an OhlcDataSeries, as documented in the OhlcDataSeries API. Furthermore, the addition of a SweepAnimation improves the user experience by animating the rendering of the chart series, following best practices as explained in the Series Startup Animations documentation.

Features and Capabilities

The implementation showcases several advanced features including real-time data streaming capabilities, advanced axis customization, and dynamic updates. The chart integrates multiple interactivity modifiers such as ZoomExtentsModifier, ZoomPanModifier, and MouseWheelZoomModifier, which enhance user engagement by allowing seamless zooming and panning. These interactivity features are in line with the guidelines outlined in the Adding Zooming and Panning Behavior documentation.

Integration and Best Practices

Within the React framework, the <SciChartReact/> component simplifies chart initialization and lifecycle management, supporting robust integration as discussed in the React Charts with SciChart.js introduction. Developers are encouraged to use this component to maintain responsive design and efficient resource management in their applications. Additionally, the example leverages WebGL rendering to ensure optimal performance even with large financial datasets. This combination of React integration and advanced rendering techniques provides a strong foundation for building scalable data visualization solutions.

For further customization and modifications, developers can consult the Axis LabelProviders documentation to explore additional options for formatting and styling chart axes.

react Chart Examples & Demos

See Also: Financial Charts (9 Demos)

React Candlestick Chart | Online JavaScript Chart Examples

React Candlestick Chart

Discover how to create a React Candlestick Chart or Stock Chart using SciChart.js. For high Performance JavaScript Charts, get your free demo now.

React Realtime Ticking Stock Chart | SciChart.js Demo

React Realtime Ticking Stock Charts

Create a React Realtime Ticking Candlestick / Stock Chart with live ticking and updating, using the high performance SciChart.js chart library. Get free demo now.

NEW!
React Orderbook Heatmap | React Charts | SciChart.js Demo

Order Book Heatmap

Create a React heatmap chart showing historical orderbook levels, using the high performance SciChart.js chart library. Get free demo now.

React Multi-Pane Stock Chart using Subcharts | View JavaScript Charts

React Multi-Pane Stock Charts using Subcharts

Create a React Multi-Pane Candlestick / Stock Chart with indicator panels, synchronized zooming, panning and cursors. Get your free trial of SciChart.js now.

Tenor Curves Demo | React Charts | SciChart.js Demo

Tenor Curves Demo

Demonstrating the capability of SciChart.js to create a composite 2D &amp; 3D Chart application. An example like this could be used to visualize Tenor curves in a financial setting, or other 2D/3D data combined on a single screen.

React Multi-Pane Stock Chart | View JavaScript Charts

React Multi-Pane Stock Charts using Sync Multi-Chart

Create a React Multi-Pane Candlestick / Stock Chart with indicator panels, synchronized zooming, panning and cursors. Get your free trial of SciChart.js now.

React Market Depth Chart | React Charts | SciChart.js Demo

React Market Depth Chart

Create a React Depth Chart, using the high performance SciChart.js chart library. Get free demo now.

React Chart Hoverable Buy Sell Marker Annotations | SciChart

React Chart Hoverable Buy Sell Marker Annotations

Demonstrates how to place Buy/Sell arrow markers on a React Stock Chart using SciChart.js - Annotations API

React User Annotated Stock Chart | React Charts | SciChart.js

React User Annotated Stock Chart

This demo shows you how to create a <strong>{frameworkName} User Annotated Stock Chart</strong> using SciChart.js. Custom modifiers allow you to add lines and markers, then use the built in serialisation functions to save and reload the chart, including the data and all your custom annotations.

SciChart Ltd, 16 Beaufort Court, Admirals Way, Docklands, London, E14 9XL.