Creates a React Waterfall Chart using SciChart.js's new FastRectangleRenderableSeries with the following features: a custom Treemap-like DataLabelProvider for rectangle labels and custom Fill PaletteProvider
Also Known As: Bridge Chart and Cascade Chart.
drawExample.ts
index.tsx
theme.ts
1import {
2 NumericAxis,
3 ZoomPanModifier,
4 ZoomExtentsModifier,
5 MouseWheelZoomModifier,
6 SciChartSurface,
7 ENumericFormat,
8 FastRectangleRenderableSeries,
9 XyxyDataSeries,
10 EColumnYMode,
11 EColumnMode,
12 EDataPointWidthMode,
13 NumberRange,
14 EHorizontalTextPosition,
15 EVerticalTextPosition,
16 TextLabelProvider,
17 RectangleSeriesDataLabelProvider,
18 formatNumber,
19 IRectangleSeriesDataLabelProviderOptions,
20 EDataLabelSkipMode,
21 EMultiLineAlignment,
22 IPointMetadata,
23 IFillPaletteProvider,
24 EFillPaletteMode,
25 parseColorToUIntArgb,
26 ELabelAlignment,
27 Thickness,
28} from "scichart";
29import { appTheme } from "../../../theme";
30
31const data = [
32 { date: "Jan.", profit: 387264 },
33 { date: "Feb.", profit: 772096 },
34 { date: "Mar.", profit: 638075 },
35 { date: "Apr.", profit: -211386 },
36 { date: "May", profit: -138135 },
37 { date: "Jun.", profit: -267238 },
38 { date: "Jul.", profit: 431406 },
39 { date: "Aug.", profit: 363018 },
40 { date: "Sep.", profit: -224638 },
41 { date: "Oct.", profit: -299867 },
42 { date: "Nov.", profit: 607365 },
43 { date: "Dec.", profit: 1106986 },
44];
45
46const waterfall = function (numbers: { date: string; profit: number }[]) {
47 let last = 0,
48 accu = 0;
49 const waterfall = numbers.map((d, i) => {
50 last = accu;
51 accu += d.profit;
52 return {
53 date: d.date,
54 nextDay: i < numbers.length - 1 ? numbers[i + 1].date : "Total",
55 prior: last,
56 accu: accu,
57 profit: d.profit,
58 };
59 });
60
61 waterfall.push({
62 date: "Total",
63 nextDay: null,
64 prior: 0,
65 accu: accu,
66 profit: 0,
67 });
68
69 return waterfall;
70};
71
72const generatedData = waterfall(data);
73
74const labelProvider = new TextLabelProvider({
75 labels: [...generatedData.map((d) => d.date)],
76 maxLength: 15,
77});
78
79export const drawExample = async (rootElement: string | HTMLDivElement) => {
80 // Create a SciChartSurface
81 const { sciChartSurface, wasmContext } = await SciChartSurface.create(rootElement, {
82 theme: appTheme.SciChartJsTheme,
83 });
84
85 const growBy = new NumberRange(0.05, 0.05);
86
87 // Create an XAxis with a TextLabelProvider
88 const xAxis = new NumericAxis(wasmContext, {
89 // labelprovider maps Xaxis values (in this case index) to labels (in this case manufacturer name)
90 labelProvider,
91 labelStyle: {
92 alignment: ELabelAlignment.Center,
93 padding: new Thickness(2, 1, 2, 1),
94 fontSize: 11,
95 },
96 maxAutoTicks: 15,
97 growBy: new NumberRange(0.05, 0.05), // add some horizontal padding
98 });
99
100 sciChartSurface.xAxes.add(xAxis);
101
102 // Create a YAxis
103 sciChartSurface.yAxes.add(new NumericAxis(wasmContext, { growBy, labelFormat: ENumericFormat.Engineering }));
104
105 class CustomFillProvider implements IFillPaletteProvider {
106 public readonly fillPaletteMode = EFillPaletteMode.SOLID;
107
108 public onAttached(): void {}
109 public onDetached(): void {}
110
111 public overrideFillArgb(
112 _xValue: number,
113 _yValue: number,
114 _index: number,
115 _opacity?: number,
116 metadata?: IPointMetadata
117 ): number {
118 const profit = (metadata as unknown as { profit: number })?.profit;
119
120 if (profit > 0) {
121 return parseColorToUIntArgb(appTheme.VividTeal, 255);
122 }
123
124 if (profit < 0) {
125 return parseColorToUIntArgb(appTheme.VividPink, 255);
126 }
127
128 return parseColorToUIntArgb(appTheme.VividBlue, 128);
129 }
130 }
131
132 class TreemapDataLabelProvider extends RectangleSeriesDataLabelProvider {
133 constructor(options?: IRectangleSeriesDataLabelProviderOptions) {
134 super(options);
135 }
136
137 // Override "getText" method to provide dynamic text based on rectangle size
138 getText(state: any): string {
139 const metadata = state.getMetaData() as any;
140
141 return (
142 `${formatNumber(metadata.accu, ENumericFormat.Engineering, 2)}$` +
143 (metadata.profit === 0
144 ? ""
145 : `\n${metadata.profit > 0 ? "+" : ""}${formatNumber(
146 metadata.profit,
147 ENumericFormat.Engineering,
148 this.precision
149 )}$`)
150 );
151 }
152 }
153
154 // Prepare data and create rectangle series
155
156 const rectangleSeries = new FastRectangleRenderableSeries(wasmContext, {
157 dataSeries: new XyxyDataSeries(wasmContext, {
158 xValues: generatedData.map((d, i) => i),
159 yValues: generatedData.map((d) => d.prior),
160 x1Values: generatedData.map((d, i) => i),
161 y1Values: generatedData.map((d) => d.accu),
162 metadata: generatedData as any[],
163 }),
164 columnXMode: EColumnMode.Mid,
165 columnYMode: EColumnYMode.TopBottom,
166 dataPointWidthMode: EDataPointWidthMode.Range,
167 stroke: "black",
168 strokeThickness: 1,
169 opacity: 0.5,
170 fill: appTheme.DarkIndigo,
171 dataLabelProvider: new TreemapDataLabelProvider({
172 skipMode: EDataLabelSkipMode.ShowAll,
173 color: "white",
174 style: {
175 fontSize: 11,
176 multiLineAlignment: EMultiLineAlignment.Center,
177 lineSpacing: 5,
178 },
179 horizontalTextPosition: EHorizontalTextPosition.Center,
180 verticalTextPosition: EVerticalTextPosition.Center,
181 metaDataSelector: (md: unknown) => {
182 return (md as { profit: string }).profit;
183 },
184 }),
185 paletteProvider: new CustomFillProvider(),
186 });
187 sciChartSurface.renderableSeries.add(rectangleSeries);
188
189 // Add interactivity modifiers
190 sciChartSurface.chartModifiers.add(
191 new ZoomPanModifier({ enableZoom: true }),
192 new ZoomExtentsModifier(),
193 new MouseWheelZoomModifier()
194 );
195
196 return { sciChartSurface, wasmContext };
197};
198This React Charts example creates a Waterfall Chart using SciChart.js, demonstrating how to integrate the powerful charting library within a React application via the SciChart React component.
The chart logic is encapsulated in drawExample.ts, which initializes the SciChartSurface asynchronously. The React component simply passes this function to <SciChartReact initChart={drawExample}>. The implementation uses FastRectangleRenderableSeries with EColumnMode.Mid for centered columns and custom data labels.
The chart features dynamic coloring through a custom IFillPaletteProvider, multi-line data labels showing both cumulative and delta values, and responsive design through the ChartWrapper CSS class. Interactive modifiers enable zooming and panning.
The example shows proper React integration by separating chart logic from presentation. The async initialization pattern ensures optimal performance, while the contained component structure makes it easy to reuse. For more on React best practices, see Creating a SciChart React Component.

Discover how to create a high performance React Line Chart with SciChart - the leading JavaScript library. Get your free demo now.

Discover how to create a React Spline Line Chart with SciChart. Demo includes algorithm for smoother lines. Get your free trial now.

Discover how to create a React Digital Line Chart with SciChart - your feature-rich JavaScript Chart Library. Get your free demo now.

Easily create a React Band Chart or High-Low Fill with SciChart - high performance JavaScript Chart Library. Get your free trial now.

SciChart's React Spline Band Chart makes it easy to draw thresholds or fills between two lines on a chart. Get your free demo today.

Learn how to create a React Digital Band Chart or High-Low Fill Chart with SciChart's easy-to-follow demos. Get your free trial today.

Create a high performance React Bubble Chart with Sci-Chart. Demo shows how to draw point-markers at X,Y locations. Get your free demo now.

Discover how to create a React Candlestick Chart or Stock Chart using SciChart.js. For high Performance JavaScript Charts, get your free demo now.

React Column Chart demo by SciChart supports gradient fill and paletteproviders for more custom coloring options. Get your free demo now.

Population Pyramid of Europe and Africa

Create React Error Bars Chart using high performance SciChart.js. Display uncertainty or statistical confidence of a data-point. Get free demo now.

Easily create React Impulse Chart or Stem Chart using SciChart.js - our own high performance JavaScript Chart Library. Get your free trial now.

Create React Text Chart with high performance SciChart.js.

Discover how to create React Fan Chart with SciChart. Zoom in to see the detail you can go to using our JavaScript Charts. Get your free demo today.

Easily create a high performance React Heatmap Chart with SciChart. Get your free trial of our 5-star rated JavaScript Chart Component today.

Create React Non Uniform Chart using high performance SciChart.js. Display Heatmap with variable cell sizes. Get free demo now.

Design a highly dynamic React Heatmap Chart With Contours with SciChart's feature-rich JavaScript Chart Library. Get your free demo today.

Design a highly dynamic React Map Chart with Heatmap overlay with SciChart's feature-rich JavaScript Chart Library. Get your free demo today.

Create React Mountain Chart with SciChart.js. Zero line can be zero or a specific value. Fill color can be solid or gradient as well. Get a free demo now.

React Spline Mountain Chart design made easy. Use SciChart.js' JavaScript Charts for high performance, feature-rich designs. Get free demo now.

Create React Digital Mountain Chart with a stepped-line visual effect. Get your free trial of SciChart's 5-star rated JavaScript Chart Component now.

React Realtime Mountain Chart made easy. Add animated, real-time updates with SciChart.js - high performance JavaScript Charts. Get free trial now.

Create React Scatter Chart with high performance SciChart.js. Easily render pre-defined point types. Supports custom shapes. Get your free trial now.

Discover how to create a React Stacked Column Chart using our feature-rich JavaScript Chart Library, SciChart.js. Get your free demo today!

Design React Stacked Group Column Chart side-by-side using our 5-star rated JavaScript Chart Framework, SciChart.js. Get your free demo now.

Design a high performance React Stacked Mountain Chart with SciChart.js - your one-stop JavaScript chart library. Get free demo now to get started.

Design a high performance React Stacked Mountain Chart with SciChart.js - your one-stop JavaScript chart library. Get free demo now to get started.

Easily create and customise a high performance React Pie Chart with 5-star rated SciChart.js. Get your free trial now to access the whole library.

Create React Donut Chart with 5-star rated SciChart.js chart library. Supports legends, text labels, animated updates and more. Get free trial now.

View the React Linear Gauge Chart example to combine rectangles & annotations. Create a linear gauge dashboard with animated indicators and custom scales.

Demonstrates how to color areas of the chart surface using background Annotations using SciChart.js Annotations API

Create a React Histogram Chart with custom texture fills and patterns. Try the SciChartReact wrapper component for seamless React integration today.

Build a React Gantt Chart with SciChart. View the demo for horizontal bars, rounded corners and data labels to show project timelines and task completion.

Create a React Choropleth map, a type of thematic map where areas are shaded or patterned in proportion to the value of a variable being represented.

Create a React Multi-Layer Map Example, using FastTriangleRenderableSeries with GeoJSON data-points using a constrained delaunay triangulation algorithm.

View the React Vector Field Plot example from SciChart, including dynamic vector generation, gradient-colored segments, and interactive zoom/pan. Try demo.

Try the React Box Plot Chart example for React-friendly chart lifecycle management, dynamic sub-surface positioning, and custom styling. Try the demo now.

Create React Triangle Meshes with the Triangle Series from SciChart. This demo supports strip mode, list mode and the drawing of polygons. View the example.

Create a React Treemap Chart to define rectangle positions based on total value. Use SciChart FastRectangleRenderableSeries and d3-hierarchy.js layouts.

React Force Directed Graph demo by SciChart.js. Visualize network graphs with physics simulation, interactive node dragging, and hover tooltips.