Demonstrates a realtime JavaScript 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.
import {
XyDataSeries,
NumericAxis,
FastLineRenderableSeries,
SciChartSurface,
EAutoRange,
HorizontalLineAnnotation,
NumberRange,
EAxisAlignment,
} from "scichart";
import { appTheme, createChartTheme } from "./appTheme";
export const drawExample = async (rootElement: string | HTMLDivElement) => {
const { sciChartSurface, wasmContext } = await SciChartSurface.create(rootElement, {
theme: createChartTheme({
majorGridLineBrush: "#FFFFFF22",
}),
});
// Create X Axis
const staticXAxis = new NumericAxis(wasmContext, {
labelPrecision: 0,
autoRange: EAutoRange.Always,
axisAlignment: EAxisAlignment.Top,
axisTitle: "Static Axis",
isStaticAxis: true, // when true, gridlines and axis labels keep their initial position on visible range change
// drawMajorBands: false, // avoids flickering - when values change fast and isStaticAxis is true
});
const xAxis = new NumericAxis(wasmContext, {
labelPrecision: 0,
autoRange: EAutoRange.Always,
axisAlignment: EAxisAlignment.Bottom,
axisTitle: "Normal Axis",
id: "Normal",
isStaticAxis: false, // when true, gridlines and axis labels keep their initial position on visible range change
// drawMajorBands: false, // avoids flickering - when values change fast and isStaticAxis is true
});
staticXAxis.visibleRangeChanged.subscribe((data) => (xAxis.visibleRange = data.visibleRange));
sciChartSurface.xAxes.add(staticXAxis, xAxis);
// Create Y Axis
const yAxis = new NumericAxis(wasmContext, {
visibleRange: new NumberRange(-2, 2),
});
sciChartSurface.yAxes.add(yAxis);
// build data series
const xValues = [];
const yValues = [];
const fifoCapacity = 1000;
let i = 0;
const makeY = (x: number) => Math.sin(x * 0.05) - 0.1 * Math.sin(x * 0.1) - Math.cos(x * 0.005);
for (; i < fifoCapacity; i++) {
xValues.push(i);
yValues.push(makeY(i));
}
// Add a line series with initial data
const dataSeries = new XyDataSeries(wasmContext, {
xValues,
yValues,
fifoCapacity,
});
sciChartSurface.renderableSeries.add(
new FastLineRenderableSeries(wasmContext, {
dataSeries,
stroke: appTheme.VividOrange,
strokeThickness: 4,
})
);
const updateCallback = () => {
const xUpdate = [];
const yUpdate = [];
for (let j = 0; j < 2; i++, j++) {
xUpdate.push(i);
yUpdate.push(makeY(i));
}
dataSeries.appendRange(xUpdate, yUpdate);
};
setInterval(updateCallback, 10);
// line annotation at x = 0
sciChartSurface.annotations.add(
new HorizontalLineAnnotation({
stroke: "#FFFFFF44",
strokeThickness: 1,
y1: 0,
})
);
function toggleStaticAxis() {
if (staticXAxis.isPrimaryAxis) {
xAxis.isPrimaryAxis = true;
} else {
staticXAxis.isPrimaryAxis = true;
}
}
return { sciChartSurface, wasmContext, controls: { toggleStaticAxis } };
};
This example demonstrates a real-time chart built with JavaScript using SciChart.js. The chart features two X axes: a *static axis_ where gridlines and tick positions remain fixed, and a normal axis that updates dynamically as new data streams in. By setting the property axis.isStaticAxis to true, the static axis ensures that while the labels change with incoming data, the label positions and gridline positions stay constant. More details on static axis behavior can be found in the SciChart.js Static Axis Documentation.
The chart is initialized using the high-performance SciChartSurface.create() method passing in a custom theme. Two NumericAxis instances are created for the X axis: one configured with isStaticAxis = true and the other as a normal axis. The static axis subscribes to the visibleRangeChanged event to synchronize its visible range with the normal axis, a technique related to axis synchronization. Real-time data is generated and appended to an XyDataSeries via a setInterval callback using the dataSeries.appendRange method, ensuring smooth, continuous updates. Additionally, a horizontal line annotation is added to highlight Y=0, showcasing the ability to integrate annotations seamlessly. Toggle buttons for 'Normal Axis' and 'Static Axis' call the toggleStaticAxis() function in drawExample.ts, setting which axis has isPrimaryAxis flag set to true, which defines which axis draws the gridlines.
Key features of this implementation include real-time update capabilities, dual X axis configuration with one axis maintaining static gridlines, and the integration of annotations. The synchronization between the static and normal axes ensures consistent visual behavior and improves readability during rapid updates. This multi-axis management approach aligns with practices detailed in the Tutorial 08 - Adding Multiple Axis documentation.
Developers using JavaScript can integrate SciChart.js using this example as a baseline for high-performance, real-time charting applications. The approach emphasizes efficient data handling with FIFO data series (XyDataSeries.fifoCapacity) and leverages the performance benefits offered through WebAssembly integration.










