Drag Angular Chart Axis to Scale or Pan

Demonstrates how to scale or pan the Axis on a Angular Chart using SciChart.js, High Performance JavaScript Charts

Fullscreen

Edit

 Edit

Docs

drawExample.ts

angular.ts

Copy to clipboard
Minimise
Fullscreen
1import {
2    EAxisAlignment,
3    EColor,
4    ELabelAlignment,
5    ENumericFormat,
6    FastLineRenderableSeries,
7    NumericAxis,
8    SciChartSurface,
9    XyDataSeries,
10    ZoomExtentsModifier,
11    EDragMode,
12    YAxisDragModifier,
13    XAxisDragModifier,
14    SciChartJsNavyTheme,
15} from "scichart";
16
17export const drawExample = async (rootElement: string | HTMLDivElement) => {
18    const { sciChartSurface, wasmContext } = await SciChartSurface.create(rootElement, {
19        theme: new SciChartJsNavyTheme(),
20    });
21
22    const ID_X_AXIS_2 = "xAxis2";
23    const ID_Y_AXIS_2 = "yAxis2";
24
25    const setXAxis1 = () => {
26        const xAxis = new NumericAxis(wasmContext);
27        xAxis.axisAlignment = EAxisAlignment.Top;
28        xAxis.axisTitle = "Drag the X-Axis to Pan";
29        xAxis.labelProvider.numericFormat = ENumericFormat.Decimal;
30        xAxis.labelProvider.precision = 0;
31        sciChartSurface.xAxes.add(xAxis);
32    };
33
34    const setXAxis2 = () => {
35        const xAxis = new NumericAxis(wasmContext, {
36            id: ID_X_AXIS_2,
37        });
38        xAxis.axisAlignment = EAxisAlignment.Bottom;
39        xAxis.axisTitle = "Drag the X-Axis to Pan";
40        xAxis.labelProvider.numericFormat = ENumericFormat.Decimal;
41        xAxis.labelProvider.precision = 0;
42        sciChartSurface.xAxes.add(xAxis);
43    };
44
45    const setYAxis1 = () => {
46        const yAxis = new NumericAxis(wasmContext);
47        yAxis.axisAlignment = EAxisAlignment.Left;
48        yAxis.axisTitle = "Drag the Y-Axis to Scale";
49        yAxis.labelProvider.numericFormat = ENumericFormat.Decimal;
50        yAxis.labelProvider.precision = 0;
51        sciChartSurface.yAxes.add(yAxis);
52    };
53
54    const setYAxis2 = () => {
55        const yAxis = new NumericAxis(wasmContext, {
56            id: ID_Y_AXIS_2,
57        });
58        yAxis.axisAlignment = EAxisAlignment.Right;
59        yAxis.axisTitle = "Drag the Y-Axis to Scale";
60        yAxis.labelProvider.numericFormat = ENumericFormat.Decimal;
61        yAxis.labelProvider.precision = 0;
62        yAxis.labelStyle = { alignment: ELabelAlignment.Right };
63        sciChartSurface.yAxes.add(yAxis);
64    };
65
66    const setSeries1 = () => {
67        const lineSeries = new FastLineRenderableSeries(wasmContext, { stroke: EColor.Red });
68        lineSeries.strokeThickness = 3;
69        sciChartSurface.renderableSeries.add(lineSeries);
70        const lineData = new XyDataSeries(wasmContext);
71
72        // Define line data
73        const iStep = 20;
74        const fAmpltude = 100.0;
75        const fFrequency = 1.0;
76        for (let i = 0; i < 500 + iStep; i += iStep) {
77            lineData.append(i, Math.sin((fFrequency * i * Math.PI) / 180.0) * fAmpltude);
78        }
79
80        lineSeries.dataSeries = lineData;
81    };
82
83    const setSeries2 = () => {
84        const lineSeries = new FastLineRenderableSeries(wasmContext, { stroke: EColor.Purple });
85        lineSeries.xAxisId = ID_X_AXIS_2;
86        lineSeries.yAxisId = ID_Y_AXIS_2;
87        lineSeries.strokeThickness = 3;
88        sciChartSurface.renderableSeries.add(lineSeries);
89        const lineData = new XyDataSeries(wasmContext);
90
91        // Define line data
92        const iStep = 10;
93        const fAmpltude = 200.0;
94        const fFrequency = 1.5;
95        for (let i = 0; i < 1.5 * 500 + iStep; i += iStep) {
96            lineData.append(i, Math.sin((fFrequency * (i - 100) * Math.PI) / 180.0) * fAmpltude);
97        }
98
99        lineSeries.dataSeries = lineData;
100    };
101
102    setXAxis1();
103    setXAxis2();
104    setYAxis1();
105    setYAxis2();
106
107    setSeries1();
108    setSeries2();
109
110    // Add modifiers to enable YAxis and XAxis drag with dragMode as scale or pan
111    sciChartSurface.chartModifiers.add(
112        new XAxisDragModifier({ dragMode: EDragMode.Panning }),
113        new YAxisDragModifier({ dragMode: EDragMode.Scaling })
114    );
115
116    // Add a modifier to zoom to fit on double-click
117    sciChartSurface.chartModifiers.add(new ZoomExtentsModifier());
118
119    sciChartSurface.zoomExtents();
120
121    return { sciChartSurface };
122};
123

Drag Angular Chart Axis to Scale or Pan

Overview

This example demonstrates how to integrate SciChart.js within an Angular application using the ScichartAngularComponent to create an interactive chart where users can pan and scale axes by simply dragging them. The example highlights the use of multiple numeric axes and renderable series to achieve high performance, real-time charting in Angular.

Technical Implementation

The chart is initialized through a standalone Angular component that imports the scichart-angular package. A custom function, defined in the drawExample module, creates a SciChartSurface and configures two X-axes and two Y-axes with unique alignments and numeric formatting. For interactive panning and scaling, the example adds an XAxisDragModifier (configured for panning) and a YAxisDragModifier (configured for scaling). The inclusion of the ZoomExtentsModifier provides zoom-to-fit capabilities through double-click interactions.

Features and Capabilities

This implementation supports real-time axis interactions and dynamic data updates through two distinct line series, each with its own axis configuration. The chart showcases advanced features like dual axis scaling and panning, alongside custom numeric formatting and theming via the SciChartJsNavyTheme. These features ensure a smooth and responsive user experience, even with detailed and large datasets.

Integration and Best Practices

By leveraging a standalone Angular component and a custom chart initialization function, this example adheres to best practices for integrating SciChart.js into Angular. Developers seeking to embed high-performance charts in their Angular projects can refer to the Getting Started with SciChart JS guide and the Tutorial 01 - Setting up a npm Project with SciChart.js for more detailed setup instructions. Additional resources on Axis customization further assist in tailoring the chart experience to specific requirements.

angular Chart Examples & Demos

See Also: Zoom and Pan a Chart (9 Demos)

Angular Chart with Multiple X Axes | SciChart.js Demo

Angular Chart with Multiple X Axes

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

Angular Chart with Secondary Y Axes | SciChart.js Demo

Angular Chart with Secondary Y Axes

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

Zoom and Pan a Realtime Angular Chart | SciChart.js Demo

Zoom and Pan a Realtime Angular Chart

Demonstrates how to zoom and pan a realtime Angular Chart while it is updating, with SciChart.js ZoomState API

Zoom and Pan with Angular Chart multiple Modifiers | SciChart

Zoom and Pan with Angular Chart multiple Modifiers

Demonstrates how to use multiple Zoom and Pan Modifiers on a Angular Chart with SciChart.js

Zoom and Pan with Overview Chart | Angular Charts | SciChart.js

Zoom and Pan with Overview Chart

Demonstrates how to zoom and pan with an Overview Chart

Virtualized Angular Charts: Load Data on Zoom/Pan | SciChart

Virtualized Angular Charts: Load Data on Zoom/Pan

shows how to load data on zoom/pan and how to create an overview chart for this case.

Angular Polar Modifiers | Polar Interactivity Modifiers

Angular Polar Modifiers | Polar Interactivity Modifiers Demo

Explore SciChart's Polar Interactivity Modifiers including zooming, panning, and cursor tracking. Try the demo to trial the Polar Chart Behavior Modifiers.

NEW!
High Precision Date Axis | Angular Charts | SciChart.js Demo

High Precision Date Axis

Demonstrates 64-bit precision Date Axis in SciChart.js handling Nanoseconds to Billions of Years

NEW!
Angular Overview for SubCharts with Range Selection

Angular Overview for SubCharts with Range Selection

Demonstrates how to build synchronized multi-panel charts with an overview range selector using SciChart.js in Angular

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