Demonstrates how to create a Angular Chart with central axes using SciChart.js, High Performance JavaScript Charts
import { appTheme } from "./appTheme";
import {
CentralAxesLayoutManager,
EAxisAlignment,
ECoordinateMode,
EHorizontalAnchorPoint,
EInnerAxisPlacementCoordinateMode,
ELineDrawMode,
FastLineRenderableSeries,
ICentralAxesLayoutManagerOptions,
MouseWheelZoomModifier,
NumericAxis,
NumberRange,
SciChartSurface,
TextAnnotation,
TSciChart,
XyDataSeries,
ZoomExtentsModifier,
ZoomPanModifier,
FadeAnimation,
} from "scichart";
export const drawExample = async (rootElement: string | HTMLDivElement) => {
const { sciChartSurface, wasmContext } = await SciChartSurface.create(rootElement, {
theme: appTheme.SciChartJsTheme,
});
// Optional parameters to control exact placement of the axis
// These are defaults: which fix the axes in the center of the chart
// Relative coordinate mode and 0.5 means 'place half way'
// const options: ICentralAxesLayoutManagerOptions = {
// horizontalAxisPositionCoordinateMode: EInnerAxisPlacementCoordinateMode.Relative,
// verticalAxisPositionCoordinateMode: EInnerAxisPlacementCoordinateMode.Relative,
// horizontalAxisPosition: 0.5,
// verticalAxisPosition: 0.5
// };
// These options keep the axes crossing at (0,0), so the axes pan with the chart
const options: ICentralAxesLayoutManagerOptions = {
horizontalAxisPositionCoordinateMode: EInnerAxisPlacementCoordinateMode.DataValue,
verticalAxisPositionCoordinateMode: EInnerAxisPlacementCoordinateMode.DataValue,
horizontalAxisPosition: 0,
verticalAxisPosition: 0,
};
// Control the placement of the axis by specifying CentralAxesLayoutManager
// and isInnerAxis property
sciChartSurface.layoutManager = new CentralAxesLayoutManager(options);
// Configure x,y axis with central layout - oscilloscope style
sciChartSurface.xAxes.add(
new NumericAxis(wasmContext, {
visibleRange: new NumberRange(-5, 5),
isInnerAxis: true, // required for central axis
axisAlignment: EAxisAlignment.Top,
labelStyle: {
color: appTheme.TextColor,
},
axisBorder: {
borderTop: 1,
color: appTheme.VividSkyBlue,
},
})
);
sciChartSurface.yAxes.add(
new NumericAxis(wasmContext, {
visibleRange: new NumberRange(-5, 5),
isInnerAxis: true, // required for central axis
axisAlignment: EAxisAlignment.Left,
labelStyle: {
color: appTheme.TextColor,
},
axisBorder: {
borderLeft: 1,
color: appTheme.VividSkyBlue,
},
})
);
// Add a line series
sciChartSurface.renderableSeries.add(
new FastLineRenderableSeries(wasmContext, {
drawNaNAs: ELineDrawMode.PolyLine,
dataSeries: getButterflyCurve(wasmContext, 20000),
isDigitalLine: false,
stroke: appTheme.VividTeal,
animation: new FadeAnimation({ duration: 500 }),
})
);
// Add title annotation
sciChartSurface.annotations.add(
new TextAnnotation({
text: "SciChart.js allows axis layout customisation including Central axis",
fontSize: 16,
textColor: appTheme.ForegroundColor,
x1: 0,
xCoordShift: 10,
y1: 0,
yCoordShift: 10,
opacity: 0.77,
horizontalAnchorPoint: EHorizontalAnchorPoint.Left,
xCoordinateMode: ECoordinateMode.Relative,
yCoordinateMode: ECoordinateMode.Relative,
})
);
// Add some interaction modifiers
sciChartSurface.chartModifiers.add(
new ZoomPanModifier({ enableZoom: true }),
new MouseWheelZoomModifier(),
new ZoomExtentsModifier()
);
return { sciChartSurface, wasmContext };
};
function getButterflyCurve(wasmContext: TSciChart, count: number = 2000) {
const temp = 0.01;
const dataSeries = new XyDataSeries(wasmContext);
for (let i = 0; i < count; i++) {
const t = i * temp;
const multiplier = Math.pow(Math.E, Math.cos(t)) - 2 * Math.cos(4 * t) - Math.pow(Math.sin(t / 12), 5);
const x = Math.sin(t) * multiplier;
const y = Math.cos(t) * multiplier;
dataSeries.append(x, y);
}
return dataSeries;
}
This Angular example demonstrates how to create a high-performance chart with central axes using SciChart.js. The chart positions both axes in the center by using a custom central axis layout and inner axis configuration. It leverages the scichart-angular package, which simplifies integration with Angular projects using the ScichartAngularComponent.
The implementation initializes a SciChartSurface using the Angular standalone component, which passes the chart setup function through the [initChart] property. The chart employs the CentralAxesLayoutManager with options set to position the axes based on data values, ensuring that the axes cross at (0,0). Both the x and y axes are defined as inner axes by setting the axis.isInnerAxis property, as detailed in the Central Axis Layout documentation. A FastLineRenderableSeries is used to render a dynamically generated butterfly curve, with a fade animation enhancing performance. Additional interactivity is provided through the ZoomPanModifier, MouseWheelZoomModifier, and ZoomExtentsModifier, which offer smooth zooming and panning as described in the Tutorial 03 - Adding Zooming, Panning Behavior.
This example highlights advanced chart capabilities such as real-time updates, dynamic data rendering, and a unique oscilloscope style layout. The efficient rendering of complex data series, such as the butterfly curve, is optimized by the use of FastLineRenderableSeries and FadeAnimation, supporting high performance even with large data sets. For insights into performance optimization, developers can refer to the techniques discussed in Performance Optimisation of JavaScript Applications & Charts.
Following Angular best practices, the example uses a standalone component to encapsulate chart initialization, which promotes modularity and ease of management within larger Angular applications. Developers are encouraged to consult the Getting Started with SciChart JS guide for further details on Angular application integration techniques. This example provides a robust reference for implementing complex axis layouts, interactive modifiers, and performance optimizations in Angular environments.










