React Impulse Chart

Use this demonstration to learn how to create a React Impulse Chart using SciChart.js, our own High Performance JavaScript Chart Library.

src/drawExample.ts
import { appTheme } from "./appTheme";
import {
    NumericAxis,
    XyDataSeries,
    SciChartSurface,
    FastImpulseRenderableSeries,
    ZoomPanModifier,
    ZoomExtentsModifier,
    MouseWheelZoomModifier,
    EllipsePointMarker,
    NumberRange,
    WaveAnimation,
} from "scichart";

export const drawExample = async (rootElement: string | HTMLDivElement) => {
    const { sciChartSurface, wasmContext } = await SciChartSurface.create(rootElement, {
        theme: appTheme.SciChartJsTheme,
    });
    sciChartSurface.xAxes.add(new NumericAxis(wasmContext, { axisTitle: "X Axis" }));
    sciChartSurface.yAxes.add(new NumericAxis(wasmContext, { axisTitle: "Y Axis", growBy: new NumberRange(0.1, 0.1) }));

    const xValues = [];
    const yValues = [];
    for (let i = 0; i < 70; i++) {
        xValues.push(i);
        yValues.push(Math.sin(i * 0.2) * -Math.log(i / 100));
    }

    const impulseSeries = new FastImpulseRenderableSeries(wasmContext, {
        fill: appTheme.VividPink,
        strokeThickness: 2,
        pointMarker: new EllipsePointMarker(wasmContext, { width: 1, height: 1 }),
        dataSeries: new XyDataSeries(wasmContext, { xValues, yValues }),
        animation: new WaveAnimation({ duration: 500, delay: 200, fadeEffect: true }),
    });
    sciChartSurface.renderableSeries.add(impulseSeries);

    sciChartSurface.chartModifiers.add(new ZoomPanModifier({ enableZoom: true }));
    sciChartSurface.chartModifiers.add(new ZoomExtentsModifier());
    sciChartSurface.chartModifiers.add(new MouseWheelZoomModifier());

    return { sciChartSurface };
};

React Impulse Chart

Overview

This example demonstrates how to create a high-performance Impulse Chart using SciChart.js in a React environment. It initializes a chart within a React component by leveraging the <SciChartReact/> component, setting up NumericAxis, a customized impulse series, interactive modifiers, and animated effects to deliver a responsive charting experience.

Technical Implementation

The chart is asynchronously initialized through a dedicated function that creates the SciChartSurface with a WebGL-powered WASM context. In this setup, a FastImpulseRenderableSeries is configured with custom data and a minimal point marker, and animation (specifically a wave effect) is applied to enhance visual engagement. Developers interested in the available animation options can refer to the Animations API Documentation.

Features and Capabilities

The example incorporates advanced chart modifiers such as ZoomPanModifier, ZoomExtentsModifier, and MouseWheelZoomModifier, providing interactive zooming and panning capabilities. The use of a customizable theme (via an external appTheme configuration) ensures that styling remains consistent and easy to manage. These features, combined with the optimized rendering of the impulse series on WebGL, illustrate how SciChart.js supports real-time updates and dynamic customizations. For further insights into these interactive modifiers, please see the ZoomPanModifier Documentation.

Integration and Best Practices

This implementation follows best practices for integrating SciChart.js with React by using the <SciChartReact/> component, which simplifies the asynchronous creation and disposal of chart instances. By embedding the initialization function directly within the component lifecycle, the example avoids common pitfalls related to resource management in React. Developers looking to deepen their understanding of React integration with SciChart.js are encouraged to review the React Charts with SciChart.js: Introducing "SciChart React" article, as well as the guide on Creating a SciChart React Component from the Ground Up.