Demonstrates loading 500 series, each with 500 points (250k points total) instantly. Click the Reload button at the bottom of the demo to see the chart draw again.
import {
SciChartSurface,
NumericAxis,
NumberRange,
EAutoRange,
TextAnnotation,
EHorizontalAnchorPoint,
EVerticalAnchorPoint,
ECoordinateMode,
EAnnotationLayer,
XyDataSeries,
FastLineRenderableSeries,
ZoomExtentsModifier,
ZoomPanModifier,
MouseWheelZoomModifier,
EAxisAlignment,
Thickness
} from "scichart";
import { appTheme } from "./appTheme";
export type TTimeSpan = {
title: string;
durationMs: number;
};
const SERIES = 500;
const POINTS = 500;
export const drawExample = async (
rootElement: string | HTMLDivElement,
updateTimeSpans: (newTimeSpans: TTimeSpan[]) => void,
useVerticalChart = false
) => {
// Create the SciChartSurface
const { wasmContext, sciChartSurface } = await SciChartSurface.create(rootElement, {
// theme: appTheme.SciChartJsTheme,
padding: new Thickness(0)
});
// Create an X,Y Axis
sciChartSurface.xAxes.add(
new NumericAxis(wasmContext, {
isVisible: false,
axisAlignment: useVerticalChart ? EAxisAlignment.Left : EAxisAlignment.Bottom,
flippedCoordinates: useVerticalChart,
visibleRange: new NumberRange(0, POINTS),
autoRange: EAutoRange.Never,
axisTitle: "X Axis",
})
);
sciChartSurface.yAxes.add(
new NumericAxis(wasmContext, {
isVisible: false,
axisAlignment: useVerticalChart ? EAxisAlignment.Bottom : EAxisAlignment.Left,
visibleRange: new NumberRange(-250, 250),
autoRange: EAutoRange.Never,
axisTitle: "Y Axis",
})
);
if (!useVerticalChart) {
const watermarkAnnotation = (text: string, offset: number = 0) => {
return new TextAnnotation({
text,
fontSize: 42,
fontWeight: "Bold",
textColor: appTheme.ForegroundColor,
x1: 0.5,
y1: 0.5,
yCoordShift: offset,
opacity: 0.43,
horizontalAnchorPoint: EHorizontalAnchorPoint.Center,
verticalAnchorPoint: EVerticalAnchorPoint.Center,
xCoordinateMode: ECoordinateMode.Relative,
yCoordinateMode: ECoordinateMode.Relative,
annotationLayer: EAnnotationLayer.AboveChart,
});
};
// add a title annotation
sciChartSurface.annotations.add(watermarkAnnotation("SciChart.js Performance Demo", -52));
sciChartSurface.annotations.add(watermarkAnnotation(`${SERIES} Series x ${POINTS} Points per series`, 0));
sciChartSurface.annotations.add(watermarkAnnotation(`(${(SERIES * POINTS) / 1000}k DataPoints)`, 52));
}
// // add a title annotation
// // Add title annotation
// sciChartSurface.annotations.add(new TextAnnotation({
// text: "SciChart.js Performance Demo: Draw 500 Series x 500 Points (250k Points total)",
// fontSize: 16,
// textColor: appTheme.ForegroundColor,
// x1: 1,
// y1: 0,
// xCoordShift: -20,
// opacity: 0.77,
// horizontalAnchorPoint: EHorizontalAnchorPoint.Right,
// xCoordinateMode: ECoordinateMode.Relative,
// yCoordinateMode: ECoordinateMode.Relative,
// }));
// We pre-create N empty FastLineRenderableSeries for the performance test. Going to fill these with data below
const dataSeriesArray: XyDataSeries[] = new Array<XyDataSeries>(SERIES);
const rendSeriesArray: FastLineRenderableSeries[] = new Array<FastLineRenderableSeries>(SERIES);
for (let i = 0; i < SERIES; i++) {
const dataSeries: XyDataSeries = new XyDataSeries(wasmContext);
const rendSeries: FastLineRenderableSeries = new FastLineRenderableSeries(wasmContext, {
dataSeries,
strokeThickness: 2,
stroke: "auto",
});
dataSeriesArray[i] = dataSeries;
rendSeriesArray[i] = rendSeries;
sciChartSurface.renderableSeries.add(rendSeries);
}
// Add some interactivity modifiers
sciChartSurface.chartModifiers.add(
new ZoomExtentsModifier(),
new ZoomPanModifier({ enableZoom: true }),
new MouseWheelZoomModifier()
);
// Buttons for chart
const loadPoints = () => {
const newTimeSpans: TTimeSpan[] = [];
// Start counting Points generation time
const generateTimestamp = Date.now();
const xValuesArray: number[][] = new Array<number[]>(SERIES);
const yValuesArray: number[][] = new Array<number[]>(SERIES);
for (let i = 0; i < SERIES; i++) {
// Allocate data arrays
xValuesArray[i] = new Array<number>(POINTS);
yValuesArray[i] = new Array<number>(POINTS);
// Clear data, if any
dataSeriesArray[i].clear();
// Generate points
let prevYValue = 0;
for (let j = 0; j < POINTS; j++) {
const curYValue = Math.random() * 10 - 5;
xValuesArray[i][j] = j;
yValuesArray[i][j] = prevYValue + curYValue;
prevYValue += curYValue;
}
}
// Add the first time span: Generating 500 series x 500 points
newTimeSpans.push({
title: "Generate Data Points",
durationMs: Date.now() - generateTimestamp,
});
// Start counting batch append time
const appendTimestamp = Date.now();
for (let i = 0; i < SERIES; i++) {
dataSeriesArray[i].appendRange(xValuesArray[i], yValuesArray[i]);
}
// Add the second time span: Generation of data point
newTimeSpans.push({
title: "Append Data Points",
durationMs: Date.now() - appendTimestamp,
});
// Subscribe to sciChartSurface.rendered event,
// and calculate time duration between the append and
// the first frame after it
const firstFrameTimestamp = Date.now();
let frameIndex: number = 0;
const handler = () => {
if (frameIndex === 0) {
// Add the third time span: Render the first frame
newTimeSpans.push({
title: "Render the frame",
durationMs: Date.now() - firstFrameTimestamp,
});
} else {
// Unsubscribe from sciChartSurface.rendered
updateTimeSpans(newTimeSpans);
sciChartSurface.rendered.unsubscribe(handler);
// Zoom extents at the end of performance measurement
// sciChartSurface.zoomExtents();
}
setTimeout(sciChartSurface.invalidateElement, 0);
// Increment frame index
frameIndex++;
};
sciChartSurface.rendered.subscribe(handler);
};
let timerId: NodeJS.Timeout;
const startUpdate = () => {
timerId = setInterval(loadPoints, 200);
};
const stopUpdate = () => {
clearInterval(timerId);
};
const reloadOnce = () => {
loadPoints();
};
return { wasmContext, sciChartSurface, controls: { startUpdate, stopUpdate, reloadOnce } };
};
The Load 500 Series by 500 Points Performance Demo illustrates how to integrate SciChart.js with Angular to render a high-performance chart containing 500 series, each with 500 data points (a total of 250k points). This example demonstrates the power of Angular’s standalone component architecture combined with SciChart.js rendering capabilities for real-time data visualization.
The implementation leverages ScichartAngularComponent, integrating the scichart-angular package to encapsulate and initialize the charting functionality. The chart initialization is performed asynchronously by calling SciChartSurface.create(), and Angular lifecycle hooks ensure proper initialization and cleanup of the chart instance. Event binding is used to subscribe to render events for capturing performance metrics such as data generation, data appending, and the rendering of the first frame. For more on Angular’s methods for handling component lifecycles, please refer to the Component Lifecycle documentation.
This demo supports real-time data updates by reloading chart data at regular intervals (every 200 milliseconds). The implementation efficiently pre-creates 500 renderable series and appends data in batches, ensuring minimal rendering delay. Additionally, interactive features like zooming, panning, and mouse wheel zoom are integrated, providing a dynamic and responsive user experience. Native controls styled with shared CSS classes provide the user interface.
Adhering to Angular integration best practices, the example uses dependency injection and Angular’s change detection strategies to manage state updates and performance metrics effectively. The use of asynchronous initialization and event handlers ensures that the chart updates are both efficient and observable. Developers are encouraged to review the Angular Performance Optimization techniques and the Getting Started with SciChart JS guide for further insights into large-scale chart rendering and real-time updates in Angular applications.











