Demonstrates a custom modifier which can convert from single chart to grid layout and back using SciChart.js, High Performance JavaScript Charts
drawExample.ts
index.tsx
RandomWalkGenerator.ts
theme.ts
GridLayoutModifier.ts
1import {
2 SciChartSurface,
3 NumericAxis,
4 EAxisAlignment,
5 NumberRange,
6 FastLineRenderableSeries,
7 XyDataSeries,
8 AUTO_COLOR,
9 SweepAnimation,
10 ZoomExtentsModifier,
11 MouseWheelZoomModifier,
12 ZoomPanModifier,
13 RolloverModifier,
14} from "scichart";
15import { RandomWalkGenerator } from "../../../ExampleData/RandomWalkGenerator";
16import { GridLayoutModifier } from "./GridLayoutModifier";
17
18export const drawExample = async (rootElement: string | HTMLDivElement) => {
19 // Create a SciChartSurface
20 const { wasmContext, sciChartSurface } = await SciChartSurface.create(rootElement);
21
22 // Create an XAxis and YAxis
23 sciChartSurface.xAxes.add(new NumericAxis(wasmContext));
24 sciChartSurface.yAxes.add(
25 new NumericAxis(wasmContext, {
26 axisAlignment: EAxisAlignment.Left,
27 growBy: new NumberRange(0.05, 0.05),
28 })
29 );
30
31 const POINTS = 1000;
32 for (let i = 0; i < 10; i++) {
33 // Create arrays of x, y values (just arrays of numbers)
34 const { xValues, yValues } = new RandomWalkGenerator().getRandomWalkSeries(POINTS);
35
36 // Create a Series and add to the chart
37 sciChartSurface.renderableSeries.add(
38 new FastLineRenderableSeries(wasmContext, {
39 dataSeries: new XyDataSeries(wasmContext, { xValues, yValues, dataSeriesName: `Series ${i + 1}` }),
40 stroke: AUTO_COLOR,
41 strokeThickness: 3,
42 animation: new SweepAnimation({ duration: 500, fadeEffect: true }),
43 })
44 );
45 }
46
47 // Optional: Add some interactivity to the chart
48 sciChartSurface.chartModifiers.add(
49 new ZoomExtentsModifier({ modifierGroup: "chart" }),
50 new MouseWheelZoomModifier({ modifierGroup: "chart" }),
51 new ZoomPanModifier({ modifierGroup: "chart" }),
52 new RolloverModifier({ modifierGroup: "chart" })
53 );
54
55 const glm = new GridLayoutModifier();
56 sciChartSurface.chartModifiers.add(glm);
57
58 sciChartSurface.zoomExtents();
59
60 const setIsGridLayoutMode = (value: boolean) => {
61 glm.isGrid = value;
62 };
63
64 return { wasmContext, sciChartSurface, setIsGridLayoutMode };
65};
66This example demonstrates a dynamic layout switcher built with SciChart.js and React. The implementation features a custom chart modifier that converts a single chart into a grid layout and back, providing an interactive charting experience with smooth animated transitions using the SubCharts API to create the grid layout with nested charts.
The example integrates the <SciChartReact/> component from the scichart-react package with React's context API using the useContext hook for state management. A custom modifier, implemented as GridLayoutModifier in TypeScript, is responsible for converting the parent chart into a series of sub-charts arranged in a grid. Animated layout transitions are managed with the GenericAnimation class, ensuring that sub-charts adjust their positions and styles smoothly. For further details on React integration with SciChart, refer to React Charts with SciChart.js: Introducing "SciChart React".
Key features include dynamic switching between a single chart view and a grid layout that displays individual charts per data series. Each sub-chart is animated during the transition, enhancing the interactivity and user experience. The smooth animations are supported by advanced chart animation capabilities demonstrated in the React Generic Animation demo, while the custom modifier follows guidelines from the Custom Chart Modifier API.
The example integrates Material-UI's ToggleButtonGroup to provide an interactive chart toolbar, showcasing how to combine modern UI components with <SciChartReact/> for dynamic layout updates. React's context API plays a crucial role in sharing the SciChartSurface state between components, a technique well explained in Mastering React's useContext Hook: Simplifying State Management. Additionally, by enabling dynamic grid and single chart layouts, the implementation reflects modern performance optimization practices in rendering multiple animated sub-charts as illustrated in the Dynamic Layout Showcase | SciChart.js Demo. Please also refer to the SubCharts API

This demo showcases the incredible realtime performance of our React charts by updating the series with millions of data-points!

This demo showcases the incredible performance of our React Chart by loading 500 series with 500 points (250k points) instantly!

This demo showcases the incredible performance of our JavaScript Chart by loading a million points instantly.

This demo showcases the realtime performance of our React Chart by animating several series with thousands of data-points at 60 FPS

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

Demonstrates how to create Oil and Gas Dashboard

This demo showcases the incredible realtime performance of our JavaScript charts by updating the series with millions of data-points!

This dashboard demo showcases the incredible realtime performance of our React charts by updating the series with millions of data-points!

This demo showcases the incredible realtime performance of our React charts by updating the series with millions of data-points!

Demonstrates how to repurpose a Candlestick Series into dragabble, labled, event markers

Population Pyramid of Europe and Africa

Demonstrates how to use the SVG render layer in SciChart.js to maintain smooth cursor interaction on heavy charts with millions of points.