Chart Background Image with Transparency

Demonstrates how to create a Chart with Transparent Background using SciChart.js, High Performance JavaScript Charts

src/drawExample.ts
import {
    SciChartSurface,
    NumericAxis,
    MouseWheelZoomModifier,
    ZoomExtentsModifier,
    ZoomPanModifier,
    SciChartJSLightTheme,
    FastBubbleRenderableSeries,
    XyzDataSeries,
    EllipsePointMarker,
    NumberRange,
    SplineLineRenderableSeries,
    SweepAnimation,
    FastColumnRenderableSeries,
    XyDataSeries,
    WaveAnimation,
    TextLabelProvider,
} from "scichart";

import { appTheme } from "./appTheme";

export const drawExample = async (rootElement: string | HTMLDivElement) => {
    const { sciChartSurface, wasmContext } = await SciChartSurface.create(rootElement, {
        theme: new SciChartJSLightTheme(),
    });

    // Set the background to Transparent to show the underlying DOM through
    sciChartSurface.background = "Transparent";

    const axisOptionsCommon = {
        axisBandsFill: "#33333311",
        majorGridLineStyle: { color: "#FFFFFF55" },
        minorGridLineStyle: { color: "#FFFFFF22" },
        labelStyle: { color: "#EEE" },
        axisTitleStyle: { color: "#EEE" },
    };

    // Add X,Y axis. Note that Axis.axisBandsFill must be modified to show the background through.
    // This is done in the axisOptions above
    sciChartSurface.xAxes.add(
        new NumericAxis(wasmContext, {
            ...axisOptionsCommon,
            axisBorder: { borderTop: 1, color: "#ccc" },
            growBy: new NumberRange(0.1, 0.1),
            axisTitle: "Quarter (Year)",
            labelProvider: new TextLabelProvider({
                labels: ["Q1 (2020)", "Q1 (2021)", "Q1 (2022)", "Q1 (2023)"],
            }),
        })
    );
    sciChartSurface.yAxes.add(
        new NumericAxis(wasmContext, {
            ...axisOptionsCommon,
            axisBorder: { borderLeft: 1, color: "#ccc" },
            growBy: new NumberRange(0.0, 0.1),
            axisTitle: "Sales $(Billions)",
        })
    );

    // Add some series
    //

    // Line series with spline interpolation
    sciChartSurface.renderableSeries.add(
        new SplineLineRenderableSeries(wasmContext, {
            dataSeries: new XyDataSeries(wasmContext, {
                xValues: [0, 1, 2, 3],
                yValues: [2, 3.5, 3.0, 5],
            }),
            stroke: appTheme.VividSkyBlue,
            strokeThickness: 3,
            animation: new SweepAnimation({ duration: 500 }),
        })
    );

    // Bubble series
    sciChartSurface.renderableSeries.add(
        new FastBubbleRenderableSeries(wasmContext, {
            dataSeries: new XyzDataSeries(wasmContext, {
                xValues: [0, 1, 2, 3],
                yValues: [2, 3.5, 3.0, 5],
                zValues: [30, 90, 40, 60],
            }),
            pointMarker: new EllipsePointMarker(wasmContext, {
                width: 64,
                height: 64,
                strokeThickness: 2,
                stroke: appTheme.PaleSkyBlue,
                fill: appTheme.VividSkyBlue + "33",
            }),
            animation: new SweepAnimation({ delay: 200, duration: 500, fadeEffect: true }),
        })
    );

    // Column series
    sciChartSurface.renderableSeries.add(
        new FastColumnRenderableSeries(wasmContext, {
            dataSeries: new XyDataSeries(wasmContext, {
                xValues: [0, 0.2, 0.4, 0.6, 0.8, 1, 1.2, 1.4, 1.6, 1.8, 2, 2.2, 2.4, 2.6, 2.8, 3],
                yValues: [0.8, 1, 1, 1.1, 1.2, 5.2, 2.8, 2.7, 2.6, 2.6, 2.5, 2.5, 2.5, 2.6, 3.2, 4],
            }),
            stroke: appTheme.MutedSkyBlue,
            fill: appTheme.VividSkyBlue + "33",
            strokeThickness: 2,
            dataPointWidth: 0.57,
            cornerRadius: 10,
            animation: new WaveAnimation({ delay: 400, duration: 600, fadeEffect: true }),
        })
    );

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

    sciChartSurface.zoomExtents();

    return { sciChartSurface, wasmContext };
};

Charts with Transparent Backgrounds Example using JavaScript

Overview

This example demonstrates how to create a SciChart.js chart with a fully transparent background. By setting the chart's background to "Transparent", the underlying DOM—such as a CSS background image—can be seen, enabling rich visual integrations for custom-themed web applications.

Technical Implementation

Implemented in JavaScript, the chart is initialized asynchronously using the SciChartSurface.create() method. Performance is optimized through the use of WebAssembly (wasmContext), ensuring fast rendering and high responsiveness. The numeric axes are configured with custom grid lines, band fills, and label styles as detailed in the Axis Styling: Title, Labels, Gridlines and Axis Band Style documentation. The transparent background is applied by setting sciChartSurface.background to "Transparent", a technique explained in the Transparent Background documentation.

Features and Capabilities

The chart incorporates several renderable series including a spline line, bubble, and column series. Each series utilizes dynamic animations—such as SweepAnimation and WaveAnimation — to create engaging visual effects, a concept described in the Series Startup Animations documentation. Additionally, interactive modifiers like ZoomPanModifier, MouseWheelZoomModifier, and ZoomExtentsModifier are added to enable smooth real-time navigation and user interaction.

Integration and Best Practices

This example follows best practices for high-performance charting by leveraging the WebAssembly context for rendering efficiency. Data series are configured using clear JSON-style setups, making it straightforward to modify and extend the chart's functionality as needed. Developers can refer to the Working with Data documentation for more details on customizing series and interactivity. Overall, this transparent background example serves as a solid reference for integrating SciChart.js into JavaScript projects requiring advanced styling and seamless background integration.