JavaScript Digital Mountain Chart

For Digital Mountain Charts, you can use this demonstration to see how to create a JavaScript Digital Mountain Chart using SciChart.js, and its powerful JavaScript Chart Library.

src/drawExample.ts
import {
    FastMountainRenderableSeries,
    GradientParams,
    MouseWheelZoomModifier,
    NumberRange,
    NumericAxis,
    Point,
    RubberBandXyZoomModifier,
    SciChartSurface,
    WaveAnimation,
    XyDataSeries,
    ZoomExtentsModifier,
} from "scichart";
import { appTheme } from "./appTheme";
import { RandomWalkGenerator } from "./RandomWalkGenerator";

export const drawExample = async (rootElement: string | HTMLDivElement) => {
    // Create a SciChartSurface
    const { wasmContext, sciChartSurface } = await SciChartSurface.create(rootElement, {
        theme: appTheme.SciChartJsTheme,
    });

    // Create an XAxis and YAxis
    sciChartSurface.xAxes.add(new NumericAxis(wasmContext, { axisTitle: "X Axis" }));
    sciChartSurface.yAxes.add(
        new NumericAxis(wasmContext, {
            growBy: new NumberRange(0.05, 0.05),
            axisTitle: "Y Axis",
        })
    );

    const POINTS = 200;

    // Create arrays of x, y values
    const xValues = Array.from(Array(POINTS).keys());
    const yValues = new RandomWalkGenerator().Seed(0).getRandomWalkSeries(POINTS).yValues;

    // Create a Mountain Series and add to the chart
    const mountainSeries = new FastMountainRenderableSeries(wasmContext, {
        dataSeries: new XyDataSeries(wasmContext, { xValues, yValues }),
        stroke: appTheme.VividOrange,
        strokeThickness: 3,
        zeroLineY: 0.0,
        fill: appTheme.VividOrange, // when a solid color is required, use fill
        // when a gradient is required, use fillLinearGradient
        fillLinearGradient: new GradientParams(new Point(0, 0), new Point(0, 1), [
            { color: appTheme.MutedOrange, offset: 0 },
            { color: "Transparent", offset: 1 },
        ]),
        isDigitalLine: true,
        animation: new WaveAnimation({ duration: 1000, fadeEffect: true, zeroLine: 0 }),
    });
    sciChartSurface.renderableSeries.add(mountainSeries);

    // Optional: Add some interactivity to the chart
    sciChartSurface.chartModifiers.add(new ZoomExtentsModifier());
    sciChartSurface.chartModifiers.add(new RubberBandXyZoomModifier());
    sciChartSurface.chartModifiers.add(new MouseWheelZoomModifier());

    sciChartSurface.zoomExtents();
    return { wasmContext, sciChartSurface };
};

Digital Mountain Chart in JavaScript

Overview

This example demonstrates how to create a high-performance digital mountain chart using SciChart.js with JavaScript. It renders a stepped-line (digital) mountain series with gradient fills and smooth wave animations, providing an engaging data visualization experience in a WebGL-powered environment.

Technical Implementation

The chart is initialized by creating a SciChartSurface using the native JavaScript API, as explained in the Tutorial 01 - Including SciChart.js in an HTML Page using CDN guide. Numeric axes are configured with the NumericAxis class and fine-tuned with the NumberRange growBy property (NumericAxis API Documentation) to ensure proper spacing. A digital mountain series is built using FastMountainRenderableSeries with the isDigitalLine property set to true, and its visual appeal is enhanced via a gradient fill defined by GradientParams (GradientParams API Documentation). The series also incorporates a WaveAnimation effect to create dynamic startup animations. Interactive modifiers such as ZoomExtentsModifier, RubberBandXyZoomModifier, and MouseWheelZoomModifier are added to enable intuitive zooming and panning, following guidelines from the Tutorial 03 - Adding Zooming, Panning Behavior documentation.

Features and Capabilities

Key features include real-time data simulation via a random walk generator, digital stepped-line rendering for clear data visualization, and a custom gradient fill that transitions seamlessly to transparency. These enhancements, combined with smooth wave animations, deliver an engaging and high-fidelity charting experience.

Integration and Best Practices

This JavaScript example emphasizes direct instantiation and granular control over chart components without any abstraction layers such as builder APIs. It implements a robust resource management strategy by returning a destructor function to clean up the SciChartSurface, which aligns with best practices for performance optimization as described in the Performance Tips & Tricks guide. This approach facilitates maintainability and efficient resource management in WebGL-based applications.