This SciChart demo demonstrates how to create a React Non Uniform Heatmap Chart using SciChart.js our High Performance JavaScript Chart component.
drawExample.ts
index.tsx
theme.ts
1import { appTheme } from "../../../theme";
2import {
3 HeatmapColorMap,
4 MouseWheelZoomModifier,
5 NumericAxis,
6 NonUniformHeatmapDataSeries,
7 NonUniformHeatmapRenderableSeries,
8 NumberRange,
9 PinchZoomModifier,
10 SciChartSurface,
11 ZoomExtentsModifier,
12 ZoomPanModifier,
13} from "scichart";
14
15export const drawExample = async (rootElement: string | HTMLDivElement) => {
16 // Create a SciChartSurface with Theme
17 const { sciChartSurface, wasmContext } = await SciChartSurface.create(rootElement, {
18 theme: appTheme.SciChartJsTheme,
19 });
20
21 // Create an X, Y Axis
22 sciChartSurface.xAxes.add(new NumericAxis(wasmContext, { growBy: new NumberRange(0.1, 0.1) }));
23 sciChartSurface.yAxes.add(new NumericAxis(wasmContext, { growBy: new NumberRange(0.1, 0.1) }));
24
25 // Create some data for the heatmap as a 2d array
26 const heatmapWidth = 7;
27 const heatmapHeight = 4;
28 const zValues = Array.from(Array(heatmapHeight));
29 zValues.forEach((row, index, collection) => {
30 collection[index] = Array.from(Array(heatmapWidth));
31 });
32 let maxValue = Number.MIN_VALUE;
33 for (let x = 0; x < heatmapWidth; x++) {
34 for (let y = 0; y < heatmapHeight; y++) {
35 zValues[y][x] = 3.5 * ((heatmapHeight - y) * (heatmapWidth - x));
36 maxValue = Math.max(maxValue, zValues[y][x]);
37 }
38 }
39
40 // arrays with cell offsets
41 const xRangeOffsetsSource = [0, 10, 20, 26, 36, 60, 72, 84];
42 const yRangeOffsetsSource = [100, 250, 390, 410, 600];
43
44 // mapping functions that will calculate cell offsets based on heatmap width and height (zValues dimension sizes)
45 const xCellOffsets = (i: number) => xRangeOffsetsSource[i];
46 const yCellOffsets = (i: number) => yRangeOffsetsSource[i];
47
48 // Create the NonUniform Heatmap Series
49 const heatmapSeries = new NonUniformHeatmapRenderableSeries(wasmContext, {
50 // DataSeries defines data. This contains zValues 2D array plus the x and y cell offsets
51 dataSeries: new NonUniformHeatmapDataSeries(wasmContext, { zValues, xCellOffsets, yCellOffsets }),
52 // Color map defines how heatmap cells map to colours between minimum & maximum
53 colorMap: new HeatmapColorMap({
54 minimum: 0,
55 maximum: 100,
56 gradientStops: [
57 { offset: 0, color: appTheme.DarkIndigo },
58 { offset: 0.2, color: appTheme.Indigo },
59 { offset: 0.3, color: appTheme.VividSkyBlue },
60 { offset: 0.5, color: appTheme.VividGreen },
61 { offset: 0.7, color: appTheme.MutedRed },
62 { offset: 0.9, color: appTheme.VividOrange },
63 { offset: 1, color: appTheme.VividPink },
64 ],
65 }),
66 // optional settings
67 opacity: 0.77,
68 // values outside of the colorMap.min/max will be filled with the colours at edge of the colormap
69 fillValuesOutOfRange: true,
70 // add datalabels to the cells of the heatmap
71 dataLabels: {
72 style: {
73 fontFamily: "Arial",
74 fontSize: 16,
75 },
76 color: appTheme.ForegroundColor,
77 },
78 });
79
80 sciChartSurface.renderableSeries.add(heatmapSeries);
81
82 // add some interactivity
83 sciChartSurface.chartModifiers.add(
84 new ZoomPanModifier({ enableZoom: true }),
85 new ZoomExtentsModifier(),
86 new MouseWheelZoomModifier()
87 );
88
89 return { sciChartSurface };
90};
91This example demonstrates a React implementation of a Non Uniform Heatmap Chart using SciChart.js. It visualizes data with variable cell sizes and positions using a non-uniform grid, showcasing high-performance WebGL rendering and advanced chart customizations.
The chart is initialized via the <SciChartReact/> component by passing an initialization function that creates a SciChartSurface. Within the function, NumericAxis are defined and a non-uniform heatmap data series is constructed using the NonUniformHeatmapDataSeries class. Custom mapping functions are used to define varying x and y cell offsets, and a HeatmapColorMap is applied with gradient stops based on a predefined theme. Interactive modifiers, such as ZoomPanModifier and MouseWheelZoomModifier, are added to enhance user interactions. For detailed guidance on non-uniform heatmap customization, see the Non-Uniform Heatmap Chart Documentation.
The example features precise control over cell offset mapping via custom xCellOffsets and yCellOffsets functions, allowing for variable cell sizes in the heatmap. It includes data labels on each cell and configurable opacity settings to enhance visual appeal. Advanced color map customization is demonstrated, enabling developers to finely tune the gradient and threshold values. Additional details on color map customization can be found in the Heatmap ColorMaps and Legends documentation.
This implementation leverages the <SciChartReact/> component for seamless React integration, following best practices for React integration and ensuring a smooth developer experience. Performance optimization is achieved by utilizing the WebAssembly context (wasmContext) for efficient rendering, as highlighted in the Memory Best Practices guide. Furthermore, interactive chart modifiers are implemented to support robust zooming and panning functionality, with additional insights available in the Adding Zooming, Panning Behavior tutorial.

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.

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.

Build a React Waterfall Chart with dynamic coloring, multi-line data labels and responsive design, using the SciChartReact component for seamless integration.

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.