React Column Chart

Creates a React Column Chart using SciChart.js, with the following features: DataLabels, Rounded corners, Gradient-palette fill, startup animations.

src/drawExample.ts
import { appTheme } from "./appTheme";
import {
    NumericAxis,
    FastColumnRenderableSeries,
    XyDataSeries,
    ZoomPanModifier,
    ZoomExtentsModifier,
    MouseWheelZoomModifier,
    SciChartSurface,
    NumberRange,
    WaveAnimation,
    GradientParams,
    Point,
    EHorizontalTextPosition,
    EVerticalTextPosition,
    PaletteFactory,
    Thickness,
} from "scichart";

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

    // Add an X, Y Axis
    sciChartSurface.xAxes.add(
        new NumericAxis(wasmContext, {
            labelPrecision: 0,
        })
    );
    sciChartSurface.yAxes.add(
        new NumericAxis(wasmContext, {
            growBy: new NumberRange(0, 0.1),
            labelPrecision: 0,
        })
    );

    const xValues = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19];
    const yValues = [1, 2, 4, 8, 11, 15, 24, 46, 81, 117, 144, 160, 137, 101, 64, 35, 25, 14, 4, 1];

    // Create an add a column series
    sciChartSurface.renderableSeries.add(
        new FastColumnRenderableSeries(wasmContext, {
            dataSeries: new XyDataSeries(wasmContext, { xValues, yValues }),
            // Fill & stroke support Hex strings and rgba()
            fill: appTheme.PaleSkyBlue + "77",
            stroke: appTheme.PaleSkyBlue,
            strokeThickness: 2,
            dataPointWidth: 0.7,
            cornerRadius: 8,
            // Optional datalabels on series. To enable set a style and position
            dataLabels: {
                horizontalTextPosition: EHorizontalTextPosition.Center,
                verticalTextPosition: EVerticalTextPosition.Above,
                style: { fontFamily: "Arial", fontSize: 16, padding: new Thickness(0, 0, 8, 0) },
                color: appTheme.ForegroundColor,
                precision: 0,
            },
            // Optional series animation executed when series shows
            animation: new WaveAnimation({ duration: 1000 }),
            // Horizontal gradient in X. For Y gradient choose fillLinearGradient property
            paletteProvider: PaletteFactory.createGradient(
                wasmContext,
                new GradientParams(new Point(0, 0), new Point(1, 1), [
                    { offset: 0, color: appTheme.VividOrange },
                    { offset: 0.67, color: appTheme.VividSkyBlue },
                    { offset: 1.0, color: appTheme.VividTeal },
                ]),
                { enableFill: true }
            ),
        })
    );

    // Optional: Add some interactivity modifiers
    sciChartSurface.chartModifiers.add(new ZoomPanModifier({ enableZoom: true }));
    sciChartSurface.chartModifiers.add(new ZoomExtentsModifier());
    sciChartSurface.chartModifiers.add(new MouseWheelZoomModifier());

    sciChartSurface.zoomExtents();

    return { sciChartSurface, wasmContext };
};

React Column Chart Example

Overview

This example demonstrates how to integrate SciChart.js with React to create a Column Chart featuring data labels, rounded corners, gradient fill, and startup animations. The chart is rendered using the <SciChartReact/> component, ensuring a seamless integration within a React application.

Technical Implementation

The chart is initialized through an asynchronous drawExample function, which creates a SciChartSurface and sets up numeric axes. A FastColumnRenderableSeries is added with an XyDataSeries for x and y values. Key features such as the gradient palette provider for advanced fill styling and a WaveAnimation for smooth startup animations are integrated directly in the series configuration. This approach is detailed further in the Column Series Type Documentation.

Features and Capabilities

Advanced styling is achieved with options like rounded corners, a gradient fill created via the palette provider, and configurable data labels that position text above the columns as described in the Adding DataLabels to a Chart Series guide. Interactive modifiers such as ZoomPanModifier, ZoomExtentsModifier, and MouseWheelZoomModifier are added to enhance user experience and enable real-time chart interactions.

Integration and Best Practices

The integration leverages the <SciChartReact/> component, ensuring best practices for embedding high-performance WebGL charts in React. The implementation follows the principles highlighted in React Charts with SciChart.js: Introducing “SciChart React” and emphasizes proper lifecycle management, initializing and cleaning up the chart efficiently. For further guidance on setting up such projects, refer to the Tutorial 01 - Setting up a project with scichart-react and config object.