Angular Chart with Static X Axis

Demonstrates a realtime Angular static axis chart - where the ticks and gridlines are fixed, but the labels change. With SciChart.js High Performance JavaScript Charts you can achieve this simply by setting isStaticAxis property to true on the X axis.

Primary Axis:

Fullscreen

Edit

 Edit

Docs

drawExample.ts

index.tsx

theme.ts

Copy to clipboard
Minimise
Fullscreen
1import {
2    XyDataSeries,
3    NumericAxis,
4    FastLineRenderableSeries,
5    SciChartSurface,
6    EAutoRange,
7    HorizontalLineAnnotation,
8    NumberRange,
9    EAxisAlignment,
10} from "scichart";
11import { appTheme } from "../../../theme";
12
13export const drawExample = async (rootElement: string | HTMLDivElement) => {
14    const { sciChartSurface, wasmContext } = await SciChartSurface.create(rootElement, {
15        theme: {
16            ...appTheme.SciChartJsTheme,
17            majorGridLineBrush: "#FFFFFF22", // make gridlines more noticeable
18        },
19    });
20
21    // Create X Axis
22    const staticXAxis = new NumericAxis(wasmContext, {
23        labelPrecision: 0,
24        autoRange: EAutoRange.Always,
25        axisAlignment: EAxisAlignment.Top,
26        axisTitle: "Static Axis",
27        isStaticAxis: true, // when true, gridlines and axis labels keep their initial position on visible range change
28        // drawMajorBands: false, // avoids flickering - when values change fast and isStaticAxis is true
29    });
30
31    const xAxis = new NumericAxis(wasmContext, {
32        labelPrecision: 0,
33        autoRange: EAutoRange.Always,
34        axisAlignment: EAxisAlignment.Bottom,
35        axisTitle: "Normal Axis",
36        id: "Normal",
37        isStaticAxis: false, // when true, gridlines and axis labels keep their initial position on visible range change
38        // drawMajorBands: false, // avoids flickering - when values change fast and isStaticAxis is true
39    });
40    staticXAxis.visibleRangeChanged.subscribe((data) => (xAxis.visibleRange = data.visibleRange));
41
42    sciChartSurface.xAxes.add(staticXAxis, xAxis);
43
44    // Create Y Axis
45    const yAxis = new NumericAxis(wasmContext, {
46        visibleRange: new NumberRange(-2, 2),
47    });
48    sciChartSurface.yAxes.add(yAxis);
49
50    // build data series
51    const xValues = [];
52    const yValues = [];
53    const fifoCapacity = 1000;
54    let i = 0;
55    const makeY = (x: number) => Math.sin(x * 0.05) - 0.1 * Math.sin(x * 0.1) - Math.cos(x * 0.005);
56    for (; i < fifoCapacity; i++) {
57        xValues.push(i);
58        yValues.push(makeY(i));
59    }
60
61    // Add a line series with initial data
62    const dataSeries = new XyDataSeries(wasmContext, {
63        xValues,
64        yValues,
65        fifoCapacity,
66    });
67
68    sciChartSurface.renderableSeries.add(
69        new FastLineRenderableSeries(wasmContext, {
70            dataSeries,
71            stroke: appTheme.VividOrange,
72            strokeThickness: 4,
73        })
74    );
75
76    const updateCallback = () => {
77        const xUpdate = [];
78        const yUpdate = [];
79
80        for (let j = 0; j < 2; i++, j++) {
81            xUpdate.push(i);
82            yUpdate.push(makeY(i));
83        }
84        dataSeries.appendRange(xUpdate, yUpdate);
85    };
86
87    setInterval(updateCallback, 10);
88
89    // line annotation at x = 0
90    sciChartSurface.annotations.add(
91        new HorizontalLineAnnotation({
92            stroke: "#FFFFFF44",
93            strokeThickness: 1,
94            y1: 0,
95        })
96    );
97
98    function toggleStaticAxis() {
99        if (staticXAxis.isPrimaryAxis) {
100            xAxis.isPrimaryAxis = true;
101        } else {
102            staticXAxis.isPrimaryAxis = true;
103        }
104    }
105
106    return { sciChartSurface, wasmContext, controls: { toggleStaticAxis } };
107};
108

Angular Chart with Static X Axis

Overview

This example demonstrates a real-time chart in an Angular application using SciChart.js. It focuses on configuring a static X axis where the gridlines and ticks remain fixed while the labels update dynamically as new data is streamed. The example provides an interactive toggle to switch between a static and a normal axis configuration.

Technical Implementation

The chart is initialized by creating a SciChartSurface and setting up two NumericAxis. One axis is designated as static by enabling the isStaticAxis property, ensuring that its gridlines and ticks retain their original positions regardless of the data updates. The synchronization between the axes is achieved by subscribing to the visibleRangeChanged event, a technique detailed in the Axis Ranging - How to Listen to VisibleRange Changes - SciChart. Real-time data updates are managed by appending new data points to the data series at regular intervals, following the practices described in the Adding Realtime Updates | JavaScript Chart Documentation - SciChart guide.

Features and Capabilities

Key features of this implementation include real-time data streaming, advanced axis synchronization, and support for annotations. The static axis minimizes visual flickering during high-frequency updates while maintaining consistent gridlines. Additional customizations, such as the inclusion of a horizontal line annotation, enhance the clarity and usability of the chart. These functionalities highlight the chart’s capability to handle complex, dynamic data efficiently.

Integration and Best Practices

For Angular developers, integrating SciChart.js can be streamlined using ScichartAngularComponent from the scichart-angular package, which simplifies the embedding of high-performance charts into Angular applications. The example follows best practices for updating and synchronizing axes, ensuring that performance remains optimal even with realtime data streams.

angular Chart Examples & Demos

See Also: Chart Axis APIs (11 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

Angular Vertical Charts | Angular Charts | SciChart.js Demo

Angular Vertical Charts

Demonstrates alignment of Axis to create a vertical chart with SciChart.js - JavaScript Charts.

Angular Chart with Central Axes | Angular Charts | SciChart.js

Angular Chart with Central Axes

Demonstrates Central Axes on a Angular Chart using SciChart.js. SciChart supports unlimited left, right, top, bottom X, Y axis with configurable layout

Angular Chart with Vertically Stacked Axes | SciChart.js

Angular Chart with Vertically Stacked Axes

Demonstrates Vertically Stacked Axes on a Angular Chart using SciChart.js, allowing data to overlap

Angular Chart with Logarithmic Axis Example | SciChart.js

Angular Chart with Logarithmic Axis Example

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

NEW!
Angular Chart with DiscontinuousDateAxis  Comparison

DiscontinuousDateAxis Comparison with Angular

NEW!
Angular Chart with BaseValue Axes | SciChart.js Demo

Angular Chart with BaseValue Axes

Demonstrates BaseValue Axes on an Angular Chart using SciChart.js to create non-linear and custom-scaled axes

Draw Angular Chart Behind Axis | Angular Charts | SciChart.js

Draw Angular Chart Behind Axis

Demonstrates the option of the transparent Axes customization on a Angular Chart using SciChart.js.

Axis Types | Angular Charts | SciChart.js Demo

Axis Types

Demonstrates how to use arbitrary text for axis labels, rather than formatted data values, using the new TextLabelProvider

Angular Chart Axis Layout Options | SciChart.js Demo

Angular Chart Axis Layout Options

Demonstrates outer, inner, central and stacked axes, and use of axis alignment to create vertical charts

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