Demonstrates how to create a Chart with Transparent Background using SciChart.js, High Performance JavaScript Charts
drawExample.ts
index.tsx
theme.ts
1import {
2 SciChartSurface,
3 NumericAxis,
4 MouseWheelZoomModifier,
5 ZoomExtentsModifier,
6 ZoomPanModifier,
7 SciChartJSLightTheme,
8 FastBubbleRenderableSeries,
9 XyzDataSeries,
10 EllipsePointMarker,
11 NumberRange,
12 SplineLineRenderableSeries,
13 SweepAnimation,
14 FastColumnRenderableSeries,
15 XyDataSeries,
16 WaveAnimation,
17 TextLabelProvider,
18} from "scichart";
19
20import { appTheme } from "../../../theme";
21
22export const drawExample = async (rootElement: string | HTMLDivElement) => {
23 const { sciChartSurface, wasmContext } = await SciChartSurface.create(rootElement, {
24 theme: new SciChartJSLightTheme(),
25 });
26
27 // Set the background to Transparent to show the underlying DOM through
28 sciChartSurface.background = "Transparent";
29
30 const axisOptionsCommon = {
31 axisBandsFill: "#33333311",
32 majorGridLineStyle: { color: "#FFFFFF55" },
33 minorGridLineStyle: { color: "#FFFFFF22" },
34 labelStyle: { color: "#EEE" },
35 axisTitleStyle: { color: "#EEE" },
36 };
37
38 // Add X,Y axis. Note that Axis.axisBandsFill must be modified to show the background through.
39 // This is done in the axisOptions above
40 sciChartSurface.xAxes.add(
41 new NumericAxis(wasmContext, {
42 ...axisOptionsCommon,
43 axisBorder: { borderTop: 1, color: "#ccc" },
44 growBy: new NumberRange(0.1, 0.1),
45 axisTitle: "Quarter (Year)",
46 labelProvider: new TextLabelProvider({
47 labels: ["Q1 (2020)", "Q1 (2021)", "Q1 (2022)", "Q1 (2023)"],
48 }),
49 })
50 );
51 sciChartSurface.yAxes.add(
52 new NumericAxis(wasmContext, {
53 ...axisOptionsCommon,
54 axisBorder: { borderLeft: 1, color: "#ccc" },
55 growBy: new NumberRange(0.0, 0.1),
56 axisTitle: "Sales $(Billions)",
57 })
58 );
59
60 // Add some series
61 //
62
63 // Line series with spline interpolation
64 sciChartSurface.renderableSeries.add(
65 new SplineLineRenderableSeries(wasmContext, {
66 dataSeries: new XyDataSeries(wasmContext, {
67 xValues: [0, 1, 2, 3],
68 yValues: [2, 3.5, 3.0, 5],
69 }),
70 stroke: appTheme.VividSkyBlue,
71 strokeThickness: 3,
72 animation: new SweepAnimation({ duration: 500 }),
73 })
74 );
75
76 // Bubble series
77 sciChartSurface.renderableSeries.add(
78 new FastBubbleRenderableSeries(wasmContext, {
79 dataSeries: new XyzDataSeries(wasmContext, {
80 xValues: [0, 1, 2, 3],
81 yValues: [2, 3.5, 3.0, 5],
82 zValues: [30, 90, 40, 60],
83 }),
84 pointMarker: new EllipsePointMarker(wasmContext, {
85 width: 64,
86 height: 64,
87 strokeThickness: 2,
88 stroke: appTheme.PaleSkyBlue,
89 fill: appTheme.VividSkyBlue + "33",
90 }),
91 animation: new SweepAnimation({ delay: 200, duration: 500, fadeEffect: true }),
92 })
93 );
94
95 // Column series
96 sciChartSurface.renderableSeries.add(
97 new FastColumnRenderableSeries(wasmContext, {
98 dataSeries: new XyDataSeries(wasmContext, {
99 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],
100 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],
101 }),
102 stroke: appTheme.MutedSkyBlue,
103 fill: appTheme.VividSkyBlue + "33",
104 strokeThickness: 2,
105 dataPointWidth: 0.57,
106 cornerRadius: 10,
107 animation: new WaveAnimation({ delay: 400, duration: 600, fadeEffect: true }),
108 })
109 );
110
111 // Add some interactivity modifiers
112 sciChartSurface.chartModifiers.add(
113 new ZoomPanModifier({ enableZoom: true }),
114 new MouseWheelZoomModifier(),
115 new ZoomExtentsModifier()
116 );
117
118 sciChartSurface.zoomExtents();
119
120 return { sciChartSurface, wasmContext };
121};
122This example demonstrates how to create a chart with a transparent background using SciChart.js in a React application. In this setup, sciChartSurface.background is explicitly set to "Transparent" so that an underlying CSS background image applied to the React component can show through, offering designers extensive custom styling opportunities.
The chart is initialized asynchronously using the SciChartSurface.create() method within the context of a React component. This initialization is managed by the <SciChartReact/> component, which takes an initChart function to instantiate and configure the high-performance WebAssembly-based chart. For an in-depth look at this pattern, refer to the Creating a SciChart React Component from the Ground Up guide.
The implementation includes interactive features such as zooming and panning, achieved by integrating interactive modifiers like ZoomPanModifier, MouseWheelZoomModifier, and ZoomExtentsModifier. Additionally, the example leverages animated series using SweepAnimation and WaveAnimation to enhance visual engagement. Numeric axes are configured with consistent styling for grid lines, labels, and titles to ensure a clean display. Detailed information on the animation features can be found in the Series Startup Animations documentation.
From a React integration perspective, the <SciChartReact/> component simplifies the lifecycle management of the chart, making it easy to incorporate into existing applications. The example illustrates how to combine in-line CSS styling, such as a full background image, with transparent chart backgrounds to create visually appealing and interactive charts. This approach aligns well with best practices discussed in React Charts with SciChart.js and the officially documented Chart Styling - Image, Transparent or Blurred Backgrounds guide. Additionally, the use of WebAssembly (wasmContext) ensures that performance is optimized even when complex interactions are used. For more on integrating interactive charts in React, developers may find the scichart-react GitHub repository useful.

Demonstrates how to style a React Chart entirely in code with SciChart.js themeing API

Demonstrates our Light and Dark Themes for React Charts with SciChart.js ThemeManager API

Demonstrates how to create a Custom Theme for a SciChart.js React Chart using our Theming API

Demonstrates per-point coloring in JavaScript chart types with SciChart.js PaletteProvider API

Demonstrates the different point-marker types for React Scatter charts (Square, Circle, Triangle and Custom image point-marker)

Demonstrates dashed line series in React Charts with SciChart.js

Show data labels on React Chart. Get your free demo now.

Demonstrates how to apply multiple different styles to a single series using RenderDataTransform

Demonstrates how to use a RenderDataTransform to split lines into multiple segments so they can be individually colored according to thresholds

Demonstrates chart title with different position and alignment options

The React Order of Rendering example gives you full control of the draw order of series and annotations for charts. Try SciChart's advanced customizations.