Demonstrates how to create a JavaScript Chart with central axes using SciChart.js, High Performance JavaScript Charts
drawExample.ts
index.html
vanilla.ts
theme.ts
1import { appTheme } from "../../../theme";
2import {
3 CentralAxesLayoutManager,
4 EAnimationType,
5 EAxisAlignment,
6 ECoordinateMode,
7 EHorizontalAnchorPoint,
8 EInnerAxisPlacementCoordinateMode,
9 ELineDrawMode,
10 FastLineRenderableSeries,
11 ICentralAxesLayoutManagerOptions,
12 MouseWheelZoomModifier,
13 NumericAxis,
14 NumberRange,
15 PinchZoomModifier,
16 SciChartSurface,
17 TextAnnotation,
18 TSciChart,
19 XyDataSeries,
20 ZoomExtentsModifier,
21 ZoomPanModifier,
22} from "scichart";
23
24export const drawExample = async (rootElement: string | HTMLDivElement) => {
25 const { sciChartSurface, wasmContext } = await SciChartSurface.create(rootElement, {
26 theme: appTheme.SciChartJsTheme,
27 });
28
29 // Optional parameters to control exact placement of the axis
30 // These are defaults: which fix the axes in the center of the chart
31 // Relative coordinate mode and 0.5 means 'place half way'
32 // const options: ICentralAxesLayoutManagerOptions = {
33 // horizontalAxisPositionCoordinateMode: EInnerAxisPlacementCoordinateMode.Relative,
34 // verticalAxisPositionCoordinateMode: EInnerAxisPlacementCoordinateMode.Relative,
35 // horizontalAxisPosition: 0.5,
36 // verticalAxisPosition: 0.5
37 // };
38
39 // These options keep the axes crossing at (0,0), so the axes pan with the chart
40 const options: ICentralAxesLayoutManagerOptions = {
41 horizontalAxisPositionCoordinateMode: EInnerAxisPlacementCoordinateMode.DataValue,
42 verticalAxisPositionCoordinateMode: EInnerAxisPlacementCoordinateMode.DataValue,
43 horizontalAxisPosition: 0,
44 verticalAxisPosition: 0,
45 };
46
47 // Control the placement of the axis by specifying CentralAxesLayoutManager
48 // and isInnerAxis property
49 sciChartSurface.layoutManager = new CentralAxesLayoutManager(options);
50
51 // Configure x,y axis with central layout - oscilloscope style
52 sciChartSurface.xAxes.add(
53 new NumericAxis(wasmContext, {
54 visibleRange: new NumberRange(-5, 5),
55 isInnerAxis: true, // required for central axis
56 axisAlignment: EAxisAlignment.Top,
57 labelStyle: {
58 color: appTheme.PaleSkyBlue,
59 },
60 axisBorder: {
61 borderTop: 1,
62 color: appTheme.VividSkyBlue,
63 },
64 })
65 );
66
67 sciChartSurface.yAxes.add(
68 new NumericAxis(wasmContext, {
69 visibleRange: new NumberRange(-5, 5),
70 isInnerAxis: true, // required for central axis
71 axisAlignment: EAxisAlignment.Left,
72 labelStyle: {
73 color: appTheme.PaleSkyBlue,
74 },
75 axisBorder: {
76 borderLeft: 1,
77 color: appTheme.VividSkyBlue,
78 },
79 })
80 );
81
82 // Add a line series
83 sciChartSurface.renderableSeries.add(
84 new FastLineRenderableSeries(wasmContext, {
85 drawNaNAs: ELineDrawMode.PolyLine,
86 dataSeries: getButterflyCurve(wasmContext, 20000),
87 isDigitalLine: false,
88 stroke: appTheme.VividTeal,
89 animation: { type: EAnimationType.Fade, options: { duration: 500 } },
90 })
91 );
92
93 // Add title annotation
94 sciChartSurface.annotations.add(
95 new TextAnnotation({
96 text: "SciChart.js allows axis layout customisation including Central axis",
97 fontSize: 16,
98 textColor: appTheme.ForegroundColor,
99 x1: 0,
100 xCoordShift: 10,
101 y1: 0,
102 yCoordShift: 10,
103 opacity: 0.77,
104 horizontalAnchorPoint: EHorizontalAnchorPoint.Left,
105 xCoordinateMode: ECoordinateMode.Relative,
106 yCoordinateMode: ECoordinateMode.Relative,
107 })
108 );
109
110 // Add some interaction modifiers
111 sciChartSurface.chartModifiers.add(
112 new ZoomPanModifier({ enableZoom: true }),
113 new MouseWheelZoomModifier(),
114 new ZoomExtentsModifier()
115 );
116
117 return { sciChartSurface, wasmContext };
118};
119
120function getButterflyCurve(wasmContext: TSciChart, count: number = 2000) {
121 const temp = 0.01;
122 const dataSeries = new XyDataSeries(wasmContext);
123 for (let i = 0; i < count; i++) {
124 const t = i * temp;
125
126 const multiplier = Math.pow(Math.E, Math.cos(t)) - 2 * Math.cos(4 * t) - Math.pow(Math.sin(t / 12), 5);
127
128 const x = Math.sin(t) * multiplier;
129 const y = Math.cos(t) * multiplier;
130 dataSeries.append(x, y);
131 }
132 return dataSeries;
133}
134This example demonstrates how to create a high-performance chart with central axes using SciChart.js in a JavaScript framework. The chart positions the x and y axes to cross at the data value (0,0), producing an oscilloscope-like layout. It leverages the advanced customization available in SciChart.js for axis placement, as detailed in the Central Axis Layout documentation.
The implementation begins by initializing a SciChartSurface with an integrated WebAssembly context, following guidelines from the Tutorial 01 - Including SciChart.js in an HTML Page using CDN documentation. Both the x and y axes are configured as inner axes by enabling the axis.isInnerAxis property and aligned to the center by setting the sciChartSurface.layoutManager property equal to a CentralAxesLayoutManager instance with data value based positioning. A dynamically generated butterfly curve is rendered using the FastLineRenderableSeries and utilizes a fade animation as provided by the Animations API for performance and visual enhancement. Interaction is further enriched with modifiers such as ZoomPanModifier, MouseWheelZoomModifier, and ZoomExtentsModifier, which support smooth zooming and panning.
This example showcases advanced chart capabilities such as real-time data rendering for complex curves and dynamic interactivity. The efficient use of WebAssembly ensures high performance even when visualizing large data sets. Additionally, the chart demonstrates clear separation of concerns by isolating initialization, axis configuration, data rendering, and user interaction, which allows for robust customization based on the application’s needs.
Integrating SciChart.js into a JavaScript application is streamlined by employing a modular approach where the chart initialization function is directly invoked with a designated root element. Resource cleanup is handled by returning a destructor function that calls the delete() method on the SciChartSurface, in line with best practices suggested in the Memory Best Practices documentation. Developers looking to extend or optimize their chart applications can also refer to the Getting Started with SciChart JS guide for additional insights on integration and performance optimization.

Demonstrates Multiple X & Y Axis on a JavaScript Chart using SciChart.js. SciChart supports unlimited left, right, top, bottom X, Y axis with configurable alignment and individual zooming, panning

Demonstrates Secondary Y Axis on a JavaScript Chart using SciChart.js. SciChart supports unlimited, multiple left, right, top, bottom X, Y axis with configurable alignment and individual zooming, panning

Demonstrates alignment of Axis to create a vertical chart with SciChart.js - JavaScript Charts.

Demonstrates isStaticAxis on a JavaScript Chart using SciChart.js.

Demonstrates Vertically Stacked Axes on a JavaScript Chart using SciChart.js, allowing data to overlap

Demonstrates Logarithmic Axis on a JavaScript Chart using SciChart.js. SciChart supports logarithmic axis with scientific or engineering notation and positive and negative values


Demonstrates BaseValue Axes on a JavaScript Chart using SciChart.js to create non-linear and custom-scaled axes such as log-like scales

Demonstrates the option of the transparent Axes customization on a JavaScript Chart using SciChart.js.

Demonstrates how to use arbitrary text for axis labels, rather than formatted data values, using the new TextLabelProvider

Demonstrates outer, inner, central and stacked axes, and use of axis alignment to create vertical charts