React Chart with Vertically Stacked Axes

Vertically-Stacked Axis in SciChart.js allows several traces with independent Y-axis to be placed on the same chart, stacking the Y-Axis and enabling an ECG/EEG-style trace. Great for neurological apps, medical apps, earthquake monitoring.

Fullscreen

Edit

 Edit

Docs

drawExample.ts

index.tsx

theme.ts

Copy to clipboard
Minimise
Fullscreen
1import { appTheme } from "../../../theme";
2
3import { EWrapTo, NativeTextAnnotation, TSciChart } from "scichart";
4
5import {
6    EAxisAlignment,
7    ECoordinateMode,
8    EExecuteOn,
9    EHorizontalAnchorPoint,
10    EXyDirection,
11    FastLineRenderableSeries,
12    LeftAlignedOuterVerticallyStackedAxisLayoutStrategy,
13    MouseWheelZoomModifier,
14    NumberRange,
15    NumericAxis,
16    RubberBandXyZoomModifier,
17    SciChartSurface,
18    TextAnnotation,
19    XAxisDragModifier,
20    XyDataSeries,
21    YAxisDragModifier,
22    ZoomExtentsModifier,
23} from "scichart";
24
25export const drawExample = async (rootElement: string | HTMLDivElement) => {
26    const { sciChartSurface, wasmContext } = await SciChartSurface.create(rootElement, {
27        theme: appTheme.SciChartJsTheme,
28    });
29
30    sciChartSurface.layoutManager.leftOuterAxesLayoutStrategy =
31        new LeftAlignedOuterVerticallyStackedAxisLayoutStrategy();
32
33    sciChartSurface.xAxes.add(new NumericAxis(wasmContext, { axisTitle: "X Axis" }));
34
35    // Add title annotation
36    sciChartSurface.annotations.add(
37        new NativeTextAnnotation({
38            text: "Vertically Stacked Axis: Custom layout of axis to allow traces to overlap. Useful for ECG charts",
39            fontSize: 16,
40            textColor: appTheme.ForegroundColor,
41            x1: 0.5,
42            y1: 0,
43            opacity: 0.77,
44            horizontalAnchorPoint: EHorizontalAnchorPoint.Center,
45            xCoordinateMode: ECoordinateMode.Relative,
46            yCoordinateMode: ECoordinateMode.Relative,
47            wrapTo: EWrapTo.ViewRect,
48        })
49    );
50
51    const seriesCount: number = 10;
52    for (let i = 0; i < seriesCount; i++) {
53        const range = 10 / seriesCount;
54        const yAxis = new NumericAxis(wasmContext, {
55            id: "Y" + i,
56            visibleRange: new NumberRange(-range, range),
57            axisAlignment: EAxisAlignment.Left,
58            zoomExtentsToInitialRange: true,
59            maxAutoTicks: 5,
60            drawMinorGridLines: false,
61            axisBorder: { borderTop: 5, borderBottom: 5 },
62            axisTitle: `Y ${i}`,
63        });
64        sciChartSurface.yAxes.add(yAxis);
65
66        const lineSeries = new FastLineRenderableSeries(wasmContext, {
67            yAxisId: yAxis.id,
68            stroke: "auto",
69            strokeThickness: 2,
70        });
71        lineSeries.dataSeries = getRandomSinewave(wasmContext, 0, Math.random() * 3, Math.random() * 50, 10000, 10);
72        sciChartSurface.renderableSeries.add(lineSeries);
73    }
74
75    // Optional: Add some interactivity modifiers to enable zooming and panning
76    sciChartSurface.chartModifiers.add(
77        new YAxisDragModifier(),
78        new XAxisDragModifier(),
79        new RubberBandXyZoomModifier({
80            xyDirection: EXyDirection.XDirection,
81            executeCondition: { button: EExecuteOn.MouseRightButton },
82        }),
83        new MouseWheelZoomModifier({ xyDirection: EXyDirection.YDirection }),
84        new ZoomExtentsModifier()
85    );
86
87    return { sciChartSurface, wasmContext };
88};
89
90function getRandomSinewave(
91    wasmContext: TSciChart,
92    pad: number,
93    amplitude: number,
94    phase: number,
95    pointCount: number,
96    freq: number
97) {
98    const dataSeries = new XyDataSeries(wasmContext);
99
100    for (let i = 0; i < pad; i++) {
101        const time = (10 * i) / pointCount;
102        dataSeries.append(time, 0);
103    }
104
105    for (let i = pad, j = 0; i < pointCount; i++, j++) {
106        amplitude = Math.min(3, Math.max(0.1, amplitude * (1 + (Math.random() - 0.5) / 10)));
107        freq = Math.min(50, Math.max(0.1, freq * (1 + (Math.random() - 0.5) / 50)));
108
109        const time = (10 * i) / pointCount;
110        const wn = (2 * Math.PI) / (pointCount / freq);
111
112        const d = amplitude * Math.sin(j * wn + phase);
113        dataSeries.append(time, d);
114    }
115
116    return dataSeries;
117}
118

React Chart with Vertically Stacked Axes

Overview

This example demonstrates how to create a React-based chart using SciChart.js to display multiple data traces with independent Y-axes that are vertically stacked. The chart is particularly suited for applications such as ECG/EEG visualizations, where overlapping traces are required.

Technical Implementation

The implementation is built using React and integrates SciChart.js through the <SciChartReact/> component. The chart initialization is handled by passing a function (drawExample) to the initChart property of the <SciChartReact/> component. This function sets up a custom layout strategy using the LeftAlignedOuterVerticallyStackedAxisLayoutStrategy to align multiple Y-axes vertically, ensuring the traces can overlap appropriately. Interactive modifiers such as pan, zoom, and drag are added to enable advanced chart interactivity. The source leverages SciChart.js documentation on vertically stacked axes for guidance on configuring these layout strategies.

Features and Capabilities

The example highlights several advanced features:

  • Multiple Y-Axes: Each data series is associated with its own Y-axis, configured with a custom visible range and axis borders to emphasize clear separation, yet visually overlapping for ECG/EEG style charts.
  • High-Performance Rendering: FastLineRenderableSeries is used to efficiently render large numbers of data points, which is critical for performance-sensitive applications. For additional performance optimization details, refer to the Performance Tips & Tricks in SciChart.js.
  • Interactive Chart Modifiers: The chart employs several interactive modifiers including mouse wheel zoom, drag modifiers on both X and Y axes, and rubber band zoom. These modifiers provide a smooth and responsive user experience as explained in the Tutorial on Adding Zooming, Panning Behavior.
  • Annotations: A text annotation is added to provide context for the stacked layout, demonstrating how annotations can be used to incorporate additional information directly onto the chart.

Integration and Best Practices

The example illustrates best practices for integrating SciChart.js into a React application using the <SciChartReact/> component. Developers new to SciChart in React can learn how to initialize charts asynchronously using the initChart prop. This approach is further detailed in React Charts with SciChart.js: Introducing “SciChart React”. Furthermore, the custom layout strategies and interactive modifiers showcase how to tailor the chart behavior to specific application needs. By following these practices, developers can build highly interactive and performant charts in React.

Overall, this example serves as a comprehensive guide to implementing vertically stacked axes in a React environment using SciChart.js, emphasizing custom layouts, performance optimization, and advanced chart interactivity.

react Chart Examples & Demos

See Also: Scientific & Medical Charts (10 Demos)

React Vital Signs ECG/EKG Medical Demo | SciChart.js Demo

React Vital Signs ECG/EKG Medical Demo

In this example we are simulating four channels of data showing that SciChart.js can be used to draw real-time ECG/EKG charts and graphs to monitor heart reate, body temperature, blood pressure, pulse rate, SPO2 blood oxygen, volumetric flow and more.

React Chart with Logarithmic Axis Example | SciChart.js

React Chart with Logarithmic Axis Example

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

LiDAR 3D Point Cloud of Geospatial Data | SciChart.js

LiDAR 3D Point Cloud of Geospatial Data

Demonstrating the capability of SciChart.js to create JavaScript 3D Point Cloud charts and visualize LiDAR data from the UK Defra Survey.

Realtime Audio Spectrum Analyzer Chart | SciChart.js Demo

Realtime Audio Spectrum Analyzer Chart Example

See the frequency of recordings with the React audio spectrum analyzer example from SciChart. This real-time audio visualizer demo uses a Fourier Transform.

Realtime Audio Analyzer Bars Demo | SciChart.js Demo

Realtime Audio Analyzer Bars Demo

Demonstrating the capability of SciChart.js to create a JavaScript Audio Analyzer Bars and visualize the Fourier-Transform of an audio waveform in realtime.

Interactive Waterfall Chart | React Charts | SciChart.js

Interactive Waterfall Spectral Chart

Demonstrates how to create a Waterfall chart in SciChart.js, showing chromotragraphy data with interactive selection of points.

Interactive Phasor Diagram chart | React Charts | SciChart.js

Phasor Diagram Chart Example

See the React Phasor Diagram example to combine a Cartesian surface with a Polar subsurface. Get seamless React integration with SciChart. View demo now.

NEW!
React Correlation Plot | React Charts | SciChart.js Demo

React Correlation Plot

Create React Correlation Plot with high performance SciChart.js. Easily render pre-defined point types. Supports custom shapes. Get your free trial now.

NEW!
React Semiconductors Dashboard | JavaScript Charts | SciChart.js

Semiconductors Dashboard

React **Semiconductors Dashboard** using SciChart.js, by leveraging the **FastRectangleRenderableSeries**, and its `customTextureOptions` property to have a custom tiling texture fill.

NEW!
React Wafer Analysis Chart | JavaScript Charts | SciChart.js

Wafer Analysis Chart

React **Wafer Analysis Chart** using SciChart.js, by leveraging the **FastRectangleRenderableSeries**, and crossfilter to enable live filtering.

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