Learn how to make a Angular Stacked Mountain Chart using with SciChart's powerful JavaScript Charts and it's range of features.
import {
ELegendOrientation,
ELegendPlacement,
LegendModifier,
MouseWheelZoomModifier,
NumericAxis,
SciChartSurface,
StackedMountainCollection,
StackedMountainRenderableSeries,
WaveAnimation,
XyDataSeries,
ZoomExtentsModifier,
ZoomPanModifier,
} from "scichart";
import { appTheme } from "./appTheme";
import { xValues, y1Values, y2Values, y3Values, y4Values } from "./stackedMountainChartData";
export const drawExample = async (rootElement: string | HTMLDivElement) => {
// Create a SciChartSurface
const { wasmContext, sciChartSurface } = await SciChartSurface.create(rootElement, {
theme: appTheme.SciChartJsTheme,
});
// Create an xAxis, yAxis
sciChartSurface.xAxes.add(new NumericAxis(wasmContext, { labelPrecision: 0 }));
sciChartSurface.yAxes.add(new NumericAxis(wasmContext, { labelPrecision: 0 }));
// A collection stacks its series in insertion order.
const stackedMountainCollection = new StackedMountainCollection(wasmContext);
for (const { yValues, dataSeriesName, fill } of [
{ yValues: y1Values, dataSeriesName: "Apples", fill: appTheme.VividPurple },
{ yValues: y2Values, dataSeriesName: "Pears", fill: appTheme.VividPink },
{ yValues: y3Values, dataSeriesName: "Bananas", fill: appTheme.VividSkyBlue },
{ yValues: y4Values, dataSeriesName: "Oranges", fill: appTheme.VividOrange },
]) {
stackedMountainCollection.add(
new StackedMountainRenderableSeries(wasmContext, {
dataSeries: new XyDataSeries(wasmContext, { xValues, yValues, dataSeriesName }),
fill: fill + "AA",
stroke: appTheme.PaleSkyBlue,
strokeThickness: 2,
})
);
}
stackedMountainCollection.animation = new WaveAnimation({ duration: 600, fadeEffect: true });
// Add the StackedMountainCollection to the chart
sciChartSurface.renderableSeries.add(stackedMountainCollection);
// Add some interactivity modifiers
sciChartSurface.chartModifiers.add(
new ZoomExtentsModifier(),
new ZoomPanModifier({ enableZoom: true }),
new MouseWheelZoomModifier()
);
// Add a legend to the chart to show the series
sciChartSurface.chartModifiers.add(
new LegendModifier({
placement: ELegendPlacement.TopLeft,
orientation: ELegendOrientation.Vertical,
showLegend: true,
showCheckboxes: false,
showSeriesMarkers: true,
})
);
sciChartSurface.zoomExtents();
return { wasmContext, sciChartSurface, stackedMountainCollection };
};
This example demonstrates how to build a high performance Stacked Mountain Chart using SciChart.js within an Angular environment. The implementation leverages an Angular standalone component, specifically the ScichartAngularComponent, to initialize and render a WebGL-powered chart. Developers can refer to the scichart-angular package and Getting Started with SciChart JS for more details on integrating SciChart.js in Angular.
The chart is initialized via property binding in Angular, where the [initChart] attribute on the ScichartAngularComponent passes a reference to a custom draw function. Within this function, a SciChartSurface is created along with numeric X and Y axes. Four distinct stacked mountain series – representing data categories such as Apples, Pears, Bananas, and Oranges – are generated using the StackedMountainRenderableSeries and then grouped into a StackedMountainCollection. A smooth WaveAnimation provides animated transitions, and interactivity is enhanced through modifiers like ZoomExtentsModifier, ZoomPanModifier, and MouseWheelZoomModifier, as detailed in the Tutorial 03 - Adding Zooming, Panning Behavior guide. The use of Angular property binding is further clarified in the Property binding - Angular documentation.
This Angular implementation showcases advanced customization capabilities with features such as real-time updates, interactive zooming and panning, and animated transitions. The chart’s design takes full advantage of WebGL for optimal performance, ensuring smooth and responsive rendering even with dynamically updated data. The inclusion of a legend modifier provides clear series identification, while custom theming integrates seamlessly via an external theme configuration.
By utilizing Angular standalone components and property binding for chart initialization, this example illustrates a clean and modular integration approach. Developers are encouraged to explore the Getting Started with SciChart JS guide for foundational setup practices and refer to the Tutorial 01 - Setting up a npm Project with SciChart.js for tips on project configuration. Best practices for Angular interactive component design, state management, and WebGL performance optimization can help in building scalable and efficient web applications.








































