React Heatmap Chart With Contours

Our Contours Chart example demonstrates how to create a React Contour-map Chart using our powerful JavaScript Chart Library.

Fullscreen

Edit

 Edit

Docs

drawExample.ts

index.tsx

ChartGroupLoader.tsx

theme.ts

Copy to clipboard
Minimise
Fullscreen
1import {
2    HeatmapColorMap,
3    HeatmapLegend,
4    MouseWheelZoomModifier,
5    NumericAxis,
6    SciChartSurface,
7    UniformContoursRenderableSeries,
8    UniformHeatmapDataSeries,
9    UniformHeatmapRenderableSeries,
10    zeroArray2D,
11    ZoomExtentsModifier,
12    ZoomPanModifier,
13} from "scichart";
14import { appTheme } from "../../../theme";
15
16export const drawExample = async (rootElement: string | HTMLDivElement) => {
17    // Create a SciChartSurface
18    const { sciChartSurface, wasmContext } = await SciChartSurface.create(rootElement, {
19        theme: appTheme.SciChartJsTheme,
20    });
21
22    // Create an X & Y Axis
23    sciChartSurface.xAxes.add(new NumericAxis(wasmContext, { isVisible: false }));
24    sciChartSurface.yAxes.add(new NumericAxis(wasmContext, { isVisible: false }));
25
26    const heatmapWidth = 300;
27    const heatmapHeight = 200;
28
29    const colorPaletteMin = 0;
30    const colorPaletteMax = 200;
31
32    // Create a Heatmap Data-series. Pass heatValues as a number[][] to the UniformHeatmapDataSeries
33    const initialZValues = generateExampleData(3, heatmapWidth, heatmapHeight, colorPaletteMax);
34    const heatmapDataSeries = new UniformHeatmapDataSeries(wasmContext, {
35        zValues: initialZValues,
36        xStart: 0,
37        xStep: 1,
38        yStart: 0,
39        yStep: 1,
40    });
41
42    // Add the contours series and add to the chart
43    sciChartSurface.renderableSeries.add(
44        new UniformContoursRenderableSeries(wasmContext, {
45            dataSeries: heatmapDataSeries,
46            zMin: 20,
47            zMax: colorPaletteMax,
48            zStep: 20,
49            strokeThickness: 1,
50            stroke: appTheme.PaleSkyBlue,
51        })
52    );
53
54    // Create a background heatmap series with the same data and add to the chart
55    sciChartSurface.renderableSeries.add(
56        new UniformHeatmapRenderableSeries(wasmContext, {
57            dataSeries: heatmapDataSeries,
58            useLinearTextureFiltering: false,
59            opacity: 0.5,
60            colorMap: new HeatmapColorMap({
61                minimum: colorPaletteMin,
62                maximum: colorPaletteMax,
63                gradientStops: [
64                    { offset: 1, color: appTheme.VividPink },
65                    { offset: 0.9, color: appTheme.VividOrange },
66                    { offset: 0.7, color: appTheme.MutedRed },
67                    { offset: 0.5, color: appTheme.VividGreen },
68                    { offset: 0.3, color: appTheme.VividSkyBlue },
69                    { offset: 0.2, color: appTheme.Indigo },
70                    { offset: 0, color: appTheme.DarkIndigo },
71                ],
72            }),
73        })
74    );
75
76    // Add interaction
77    sciChartSurface.chartModifiers.add(new ZoomPanModifier({ enableZoom: true }));
78    sciChartSurface.chartModifiers.add(new ZoomExtentsModifier());
79    sciChartSurface.chartModifiers.add(new MouseWheelZoomModifier());
80
81    return { sciChartSurface };
82};
83
84export const drawHeatmapLegend = async (rootElement: string | HTMLDivElement) => {
85    const { heatmapLegend, wasmContext } = await HeatmapLegend.create(rootElement, {
86        theme: {
87            ...appTheme.SciChartJsTheme,
88            sciChartBackground: appTheme.DarkIndigo + "BB",
89            loadingAnimationBackground: appTheme.DarkIndigo + "BB",
90        },
91        yAxisOptions: {
92            isInnerAxis: true,
93            labelStyle: {
94                fontSize: 12,
95                color: appTheme.ForegroundColor,
96            },
97            axisBorder: {
98                borderRight: 1,
99                color: appTheme.ForegroundColor + "77",
100            },
101            majorTickLineStyle: {
102                color: appTheme.ForegroundColor,
103                tickSize: 6,
104                strokeThickness: 1,
105            },
106            minorTickLineStyle: {
107                color: appTheme.ForegroundColor,
108                tickSize: 3,
109                strokeThickness: 1,
110            },
111        },
112        colorMap: {
113            minimum: 0,
114            maximum: 200,
115            gradientStops: [
116                { offset: 1, color: appTheme.VividPink },
117                { offset: 0.9, color: appTheme.VividOrange },
118                { offset: 0.7, color: appTheme.MutedRed },
119                { offset: 0.5, color: appTheme.VividGreen },
120                { offset: 0.3, color: appTheme.VividSkyBlue },
121                { offset: 0.2, color: appTheme.Indigo },
122                { offset: 0, color: appTheme.DarkIndigo },
123            ],
124        },
125    });
126
127    return { sciChartSurface: heatmapLegend.innerSciChartSurface.sciChartSurface };
128};
129
130// This function generates data for the heatmap with contours series example
131function generateExampleData(index: number, heatmapWidth: number, heatmapHeight: number, colorPaletteMax: number) {
132    const zValues = zeroArray2D([heatmapHeight, heatmapWidth]);
133
134    const angle = (Math.PI * 2 * index) / 30;
135    let smallValue = 0;
136    for (let x = 0; x < heatmapWidth; x++) {
137        for (let y = 0; y < heatmapHeight; y++) {
138            const v =
139                (1 + Math.sin(x * 0.04 + angle)) * 50 +
140                (1 + Math.sin(y * 0.1 + angle)) * 50 * (1 + Math.sin(angle * 2));
141            const cx = heatmapWidth / 2;
142            const cy = heatmapHeight / 2;
143            const r = Math.sqrt((x - cx) * (x - cx) + (y - cy) * (y - cy));
144            const exp = Math.max(0, 1 - r * 0.008);
145            const zValue = v * exp;
146            zValues[y][x] = zValue > colorPaletteMax ? colorPaletteMax : zValue;
147            zValues[y][x] += smallValue;
148        }
149
150        smallValue += 0.001;
151    }
152
153    return zValues;
154}
155

See Also: JavaScript Chart Types (28 Demos)

React Line Chart | JavaScript Chart Examples | SciChart | SciChart.js Demo

React Line Chart

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

React Spline Line Chart | JavaScript Chart Library | SciChart.js Demo

React Spline Line Chart

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

React Digital Line Chart | JavaScript Charts | View Now | SciChart.js Demo

React Digital Line Chart

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

React Band Chart | JavaScript Charts | View Examples | SciChart.js Demo

React Band Chart

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

React Spline Band Chart | JavaScript Charts | SciChart | SciChart.js Demo

React Spline Band Chart

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.

React Digital Band Chart | JavaScript Chart Library | SciChart.js Demo

React Digital Band Chart

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.

React Bubble Chart | Online JavaScript Chart Examples | SciChart.js Demo

React Bubble Chart

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.

React Candlestick Chart | Chart Examples | SciChart.js | SciChart.js Demo

React Candlestick Chart

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 | JavaScript Charts | SciChart.js | SciChart.js Demo

React Column Chart

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

React Population Pyramid | SciChart.js Demo

React Population Pyramid

Population Pyramid of Europe and Africa

React Error Bars Chart |  Online Examples | SciChart.js | SciChart.js Demo

React Error Bars Chart

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

React Impulse Chart | JavaScript Charts | View Online | SciChart.js Demo

React Impulse Chart

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

React Text Chart | SciChart.js Demo

React Text Chart

Create React Text Chart with high performance SciChart.js.

React Fan Chart | JavaScript Chart Library | View Now | SciChart.js Demo

React Fan Chart

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.

React Heatmap Chart | JavaScript Chart Library Examples | SciChart.js Demo

React Heatmap Chart

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

React Non Uniform Heatmap Chart | JavaScript Chart Library Examples | SciChart.js Demo

React Non Uniform Heatmap Chart

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

React Mountain Chart | View Examples Now | SciChart.js | SciChart.js Demo

React Mountain Chart

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 | JavaScript Chart Library | SciChart.js Demo

React Spline Mountain Chart

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

React Digital Mountain Chart | JavaScript Chart Example | SciChart.js Demo

React Digital Mountain Chart

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 | View Online At SciChart | SciChart.js Demo

React Realtime Mountain Chart

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

React Scatter Chart | JavaScript Charts | SciChart.js | SciChart.js Demo

React Scatter Chart

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

React Stacked Column Chart | Online JavaScript Charts | SciChart.js Demo

React Stacked Column Chart

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

React Stacked Group Column Chart | View Examples Now | SciChart.js Demo

React Stacked Column Side by Side

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

React Stacked Mountain Chart | JavaScript Chart Library | SciChart.js Demo

React Stacked Mountain Chart

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

React Smooth Stacked Mountain Chart | JavaScript Chart Library | SciChart.js Demo

React Smooth Stacked Mountain Chart

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

React Pie Chart | JavaScript Chart Examples | SciChart | SciChart.js Demo

React Pie Chart

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.

React Donut Chart | JavaScript Charts | SciChart.js | SciChart.js Demo

React Donut Chart

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

React Quadrant Chart using Background Annotations | SciChart.js Demo

React Quadrant Chart using Background Annotations

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

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