JavaScript Waterfall Chart | Bridge Chart

Creates a JavaScript 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.

Fullscreen

Edit

 Edit

Docs

drawExample.ts

index.html

vanilla.ts

theme.ts

Copy to clipboard
Minimise
Fullscreen
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};
198

Waterfall Chart - JavaScript

Overview

This example demonstrates how to create a Waterfall Chart using SciChart.js in vanilla JavaScript. The chart visualizes cumulative profit data with colored rectangles indicating positive (teal) and negative (pink) values, using the FastRectangleRenderableSeries for high-performance rendering.

Technical Implementation

The chart uses an XyxyDataSeries to define rectangle positions (prior/accu values) and a custom IFillPaletteProvider to dynamically color rectangles based on profit values. The TextLabelProvider maps indices to month labels, while a custom RectangleSeriesDataLabelProvider displays formatted cumulative values.

Features and Capabilities

Key features include dynamic coloring based on data values, formatted engineering notation labels, and interactive zoom/pan with ZoomPanModifier. The implementation showcases how to transform raw data into waterfall format using a custom data processing function.

Integration and Best Practices

The example follows best practices for WASM initialization with SciChartSurface.create() and includes proper cleanup. For performance, it uses a single renderable series with palette providers instead of multiple series.

javascript Chart Examples & Demos

See Also: JavaScript Chart Types (40 Demos)

JavaScript Line Chart | Javascript Charts | SciChart.js Demo

JavaScript Line Chart

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

JavaScript Spline Line Chart | Javascript Charts | SciChart.js

JavaScript Spline Line Chart

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

JavaScript Digital Line Chart | Javascript Charts | SciChart.js

JavaScript Digital Line Chart

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

JavaScript Band Chart | Javascript Charts | SciChart.js Demo

JavaScript Band Chart

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

JavaScript Spline Band Chart | Javascript Charts | SciChart.js

JavaScript Spline Band Chart

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

JavaScript Digital Band Chart | Javascript Charts | SciChart.js

JavaScript Digital Band Chart

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

JavaScript Bubble Chart | Online JavaScript Chart Examples

JavaScript Bubble Chart

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

JavaScript Candlestick Chart | Online JavaScript Chart Examples

JavaScript Candlestick Chart

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

JavaScript Column Chart | Javascript Charts | SciChart.js Demo

JavaScript Column Chart

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

JavaScript Population Pyramid | Javascript Charts | SciChart.js

JavaScript Population Pyramid

Population Pyramid of Europe and Africa

JavaScript Error Bars Char | Javascript Charts | SciChart.js

JavaScript Error Bars Chart

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

JavaScript Impulse Chart | Javascript Charts | SciChart.js Demo

JavaScript Impulse Chart

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

JavaScript Text Chart | Javascript Charts | SciChart.js Demo

JavaScript Text Chart

Create JavaScript Text Chart with high performance SciChart.js.

JavaScript Fan Chart | Javascript Charts | SciChart.js Demo

JavaScript Fan Chart

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

JavaScript Heatmap Chart | Javascript Charts | SciChart.js Demo

JavaScript Heatmap Chart

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

JavaScript Non Uniform Heatmap Chart | SciChart.js Demo

JavaScript Non Uniform Heatmap Chart

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

JavaScript Heatmap Chart With Contours | SciChart.js Demo

JavaScript Heatmap Chart With Contours Example

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

JavaScript Map Chart with Heatmap overlay | SciChart.js

JavaScript Map Chart with Heatmap overlay

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

JavaScript Mountain Chart | Javascript Charts | SciChart.js Demo

JavaScript Mountain Chart

Create JavaScript 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.

JavaScript Spline Mountain Chart | Javascript Charts | SciChart.js

JavaScript Spline Mountain Chart

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

JavaScript Digital Mountain Chart | SciChart.js Demo

JavaScript Digital Mountain Chart

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

JavaScript Realtime Mountain Chart | View Online At SciChart

JavaScript Realtime Mountain Chart

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

JavaScript Scatter Chart | Javascript Charts | SciChart.js Demo

JavaScript Scatter Chart

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

JavaScript Stacked Column Chart | Online JavaScript Charts

JavaScript Stacked Column Chart

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

JavaScript Stacked Group Column Chart | View Examples Now

JavaScript Stacked Column Side by Side

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

JavaScript Stacked Mountain Chart | SciChart.js Demo

JavaScript Stacked Mountain Chart

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

JavaScript Smooth Stacked Mountain Chart | SciChart.js

JavaScript Smooth Stacked Mountain Chart

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

JavaScript Pie Chart | Javascript Charts | SciChart.js Demo

JavaScript Pie Chart

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

JavaScript Donut Chart | Javascript Charts | SciChart.js Demo

JavaScript Donut Chart

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

JavaScript Linear Gauges | Javascript Charts | SciChart.js Demo

JavaScript Linear Gauges Example

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

JavaScript Quadrant Chart using Background Annotations

JavaScript Quadrant Chart using Background Annotations

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

JavaScript Histogram Chart | Javascript Charts | SciChart.js

JavaScript Histogram Chart

Create a JavaScript Histogram Chart with custom texture fills and patterns. Try the SciChart.js library for seamless integration today.

JavaScript Gantt Chart | Javascript Charts | SciChart.js Demo

JavaScript Gantt Chart Example

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

JavaScript Choropleth Map | Javascript Charts | SciChart.js Demo

JavaScript Choropleth Map Example

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

JavaScript Multi-Layer Map | Javascript Charts | SciChart.js

JavaScript Multi-Layer Map Example

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

JavaScript Vector Field Plot | Javascript Charts | SciChart.js

JavaScript Vector Field Plot

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

JavaScript Box Plot Chart | Javascript Charts | SciChart.js Demo

JavaScript Box Plot Chart

Try the JavaScript Box-Plot Chart examples with developer-friendly chart lifecycle management, dynamic sub-surface positioning, and custom styling.

JavaScript Triangle Series | Triangle Mesh Chart | SciChart

JavaScript Triangle Series | Triangle Mesh Chart

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

JavaScript Treemap Chart | Javascript Charts | SciChart.js Demo

JavaScript Treemap Chart

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

NEW!
JavaScript Force Directed Graph | Javascript Charts | SciChart.js

JavaScript Force Directed Graph

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

SciChart Ltd, 16 Beaufort Court, Admirals Way, Docklands, London, E14 9XL.