Learn how to make a JavaScript 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 with a JavaScript approach. The implementation uses native JavaScript to initialize a WebGL-powered chart and illustrates how to create multiple stacked mountain series representing different data groups such as Apples, Pears, Bananas, and Oranges. 100% Stacked Mountain chart may be achieved by pressing the '100% Mode' toggle switch.
The chart is created by instantiating a SciChartSurface with a custom theme and adding numeric X and Y axes via NumericAxis. Each data series is defined with an XyDataSeries and rendered using the StackedMountainRenderableSeries. These series are grouped into a StackedMountainCollection which supports smooth visual transitions through a WaveAnimation. 100% Stacked Mountain charts may be achieved by setting the isOneHundredPercent property on StackedMountainCollection. Interactive features such as zooming and panning are provided by modifiers including ZoomExtentsModifier, ZoomPanModifier, and MouseWheelZoomModifier as described in the Tutorial on Adding Zooming and Panning Behavior.
The example highlights real-time update capabilities and advanced customization options. It demonstrates how multiple series can be visually integrated through grouping and animations, providing a rich user experience. The use of a smooth animation for data transitions and interactive chart modifiers ensures that users can explore the chart data dynamically while benefiting from WebGL based performance as discussed in Performance Tips & Tricks.
While this example focuses on a JavaScript implementation, the code structure emphasizes best practices such as modular design and clear separation of chart initialization logic from DOM elements. Developers are encouraged to refer to the Getting Started with SciChart JS guide for foundational setup and the Chart Styling - Creating a Custom Theme documentation to further customize the appearance of their charts. Advanced interactive features and performance optimizations are seamlessly integrated, making this implementation an excellent reference for building complex visualizations with SciChart.js using plain JavaScript.








































