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 Angular

Overview

This example demonstrates a dynamic chart layout that converts a single chart into a grid layout and back. It leverages a custom chart modifier, the GridLayoutModifier, to animate transitions and reconfigure sub-charts for rich and interactive visualizations using SciChart.js in an Angular context.

Technical Implementation

The implementation uses the GridLayoutModifier to split the parent chart into multiple sub-charts based on the number of data series. Calculations determine the appropriate number of rows and columns, and each sub-chart is configured dynamically using a JSON representation of the chart (via sciChartSurface.toJSON(true)). This approach facilitates integration into Angular services for state management and dependency injection. Smooth animated transitions are implemented using GenericAnimation, while customization of the modifier follows the guidelines outlined in the Custom Chart Modifier API.

Features and Capabilities

The example provides real-time dynamic layout switching between a single chart and a grid layout where each data series is displayed in its own animated sub-chart. The animations interpolate properties such as position, opacity, and borders to create a fluid user experience. Performance is optimized by disabling unnecessary grid lines and reusing data series across sub-charts, aligning with techniques described in the Performance Tips & Tricks documentation.

Integration and Best Practices

For Angular applications, encapsulating chart initialization and state management within Angular components and services is essential. This approach leverages Angular's dependency injection system to share the SciChart surface state efficiently. Additionally, design patterns demonstrated in the Worked Example: Re-usable Chart Groups with SubCharts documentation can be adapted to Angular to ensure responsive chart configurations and optimal rendering performance. For further insights into implementing animated transitions in an Angular context, developers are encouraged to review the techniques in the Angular Style Animation demo.

angular Chart Examples & Demos

See Also: Performance Demos & Showcases (12 Demos)

Realtime Angular Chart Performance Demo | SciChart.js

Realtime Angular Chart Performance Demo

This demo showcases the incredible realtime performance of our Angular 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 Angular 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 | Angular Charts | SciChart.js Demo

Realtime Ghosted Traces

This demo showcases the realtime performance of our Angular 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 Angular audio spectrum analyzer example from SciChart. This real-time audio visualizer demo uses a Fourier Transform.

Oil & Gas Explorer Angular Dashboard | SciChart.js Demo

Oil & Gas Explorer Angular 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 | Angular Charts | SciChart.js Demo

Server Traffic Dashboard

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

Rich Interactions Showcase | Angular Charts | SciChart.js

Rich Interactions Showcase

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

Dragabble Event Markers | Angular Charts | SciChart.js Demo

Dragabble Event Markers

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

Angular Population Pyramid | Angular Charts | SciChart.js

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