JavaScript OHLC Chart

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

Fullscreen

Edit

 Edit

Docs

drawExample.ts

index.html

vanilla.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

Ohlc Chart - JavaScript

Overview

This example demonstrates how to create an Ohlc Chart (Open-High-Low-Close Chart) using JavaScript with SciChart.js. It is designed to visually represent financial market data, making it ideal for stock trading applications and financial data analysis.

Technical Implementation

The chart is initialized by calling the asynchronous function that creates a SciChartSurface using SciChartSurface.create. A CategoryAxis is added and configured with a SmartDateLabelProvider to effectively handle non-contiguous stock market dates, and a NumericAxis is used to display financial values with precise formatting. Financial data is managed via an OhlcDataSeries that feeds into a FastOhlcRenderableSeries, which renders the OHLC data points efficiently. A SweepAnimation enhances the visual presentation by animating the appearance of the series.

Features and Capabilities

This implementation includes several advanced features such as interactive chart modifiers. The chart supports intuitive user interactions through ZoomExtentsModifier, ZoomPanModifier, and MouseWheelZoomModifier, allowing for seamless zooming and panning operations. Additionally, performance optimizations are achieved with WebGL rendering, ensuring smooth animations and responsiveness even with large datasets. For detailed performance insights, refer to the Getting Started with SciChart JS documentation.

Integration and Best Practices

The example employs JavaScript integration, highlighting best practices for resource management. A cleanup function is provided by calling sciChartSurface.delete() to properly dispose of the chart resources when they are no longer needed, aligning with the guidelines in the Memory Best Practices documentation. This approach ensures that applications remain performant and free of memory leaks. The example serves as a robust reference for developers looking to integrate high-performance financial charts without additional framework dependencies.

Overall, this Ohlc Chart example using JavaScript with SciChart.js encapsulates best practices for chart initialization, axis configuration, animation, interactivity, and resource management, providing an excellent starting point for building scalable financial data visualization applications.

javascript Chart Examples & Demos

See Also: Financial Charts (9 Demos)

JavaScript Candlestick Chart | Online JavaScript Chart Examples

JavaScript Candlestick Chart

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

JavaScript Realtime Ticking Stock Chart | SciChart.js

JavaScript Realtime Ticking Stock Charts

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

NEW!
JavaScript Orderbook Heatmap | Javascript Charts | SciChart.js

JavaScript Orderbook Heatmap

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

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

JavaScript Multi-Pane Stock Charts using Subcharts

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

Tenor Curves Demo | Javascript Charts | SciChart.js Demo

Tenor Curves Demo

Demonstrating the capability of SciChart.js to create a composite 2D & 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.

JavaScript Multi-Pane Stock Chart | View JavaScript Charts

JavaScript Multi-Pane Stock Charts using Sync Multi-Chart

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

JavaScript Market Depth Chart | Javascript Charts | SciChart.js

JavaScript Market Depth Chart

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

JavaScript Chart Hoverable Buy Sell Marker Annotations

JavaScript Chart Hoverable Buy Sell Marker Annotations

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

JavaScript User Annotated Stock Chart | SciChart.js Demo

JavaScript 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.