Dynamic Layout Showcase

Demonstrates a custom modifier which can convert from single chart to grid layout and back using SciChart.js, High Performance JavaScript Charts

Fullscreen

Edit

 Edit

Docs

drawExample.ts

index.tsx

RandomWalkGenerator.ts

theme.ts

GridLayoutModifier.ts

Copy to clipboard
Minimise
Fullscreen
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};
66

Dynamic Chart Layout in React

Overview

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

Technical Implementation

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

Features and Capabilities

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.

Integration and Best Practices

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

react Chart Examples & Demos

See Also: Performance Demos & Showcases (12 Demos)

Realtime React Chart Performance Demo | SciChart.js Demo

Realtime React Chart Performance Demo

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

Load 500 Series x 500 Points Performance Demo | SciChart

Load 500 Series x 500 Points Performance Demo

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

Load 1 Million Points Performance Demo | SciChart.js Demo

Load 1 Million Points Performance Demo

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

Realtime Ghosted Traces | React Charts | SciChart.js Demo

Realtime Ghosted Traces

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

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.

Oil & Gas Explorer React Dashboard | SciChart.js Demo

Oil & Gas Explorer React Dashboard

Demonstrates how to create Oil and Gas Dashboard

Client/Server Websocket Data Streaming | SciChart.js Demo

Client/Server Websocket Data Streaming

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

Server Traffic Dashboard | React Charts | SciChart.js Demo

Server Traffic Dashboard

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

Rich Interactions Showcase | React Charts | SciChart.js

Rich Interactions Showcase

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

Dragabble Event Markers | React Charts | SciChart.js Demo

Dragabble Event Markers

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

React Population Pyramid | React Charts | SciChart.js Demo

React Population Pyramid

Population Pyramid of Europe and Africa

NEW!
High Performance SVG Cursor & Rollover | SciChart.js Demo

High Performance SVG Cursor & Rollover

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

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