This SciChart demo demonstrates how to create a React Non Uniform Heatmap Chart using SciChart.js our High Performance JavaScript Chart component.
import { appTheme } from "./appTheme";
import {
HeatmapColorMap,
MouseWheelZoomModifier,
NumericAxis,
NonUniformHeatmapDataSeries,
NonUniformHeatmapRenderableSeries,
NumberRange,
SciChartSurface,
ZoomExtentsModifier,
ZoomPanModifier,
} from "scichart";
export const drawExample = async (rootElement: string | HTMLDivElement) => {
// Create a SciChartSurface with Theme
const { sciChartSurface, wasmContext } = await SciChartSurface.create(rootElement, {
theme: appTheme.SciChartJsTheme,
});
// Create an X, Y Axis
sciChartSurface.xAxes.add(new NumericAxis(wasmContext, { growBy: new NumberRange(0.1, 0.1) }));
sciChartSurface.yAxes.add(new NumericAxis(wasmContext, { growBy: new NumberRange(0.1, 0.1) }));
// Create some data for the heatmap as a 2d array
const heatmapWidth = 7;
const heatmapHeight = 4;
const zValues = Array.from(Array(heatmapHeight));
zValues.forEach((row, index, collection) => {
collection[index] = Array.from(Array(heatmapWidth));
});
let maxValue = Number.MIN_VALUE;
for (let x = 0; x < heatmapWidth; x++) {
for (let y = 0; y < heatmapHeight; y++) {
zValues[y][x] = 3.5 * ((heatmapHeight - y) * (heatmapWidth - x));
maxValue = Math.max(maxValue, zValues[y][x]);
}
}
// arrays with cell offsets
const xRangeOffsetsSource = [0, 10, 20, 26, 36, 60, 72, 84];
const yRangeOffsetsSource = [100, 250, 390, 410, 600];
// mapping functions that will calculate cell offsets based on heatmap width and height (zValues dimension sizes)
const xCellOffsets = (i: number) => xRangeOffsetsSource[i];
const yCellOffsets = (i: number) => yRangeOffsetsSource[i];
// Create the NonUniform Heatmap Series
const heatmapSeries = new NonUniformHeatmapRenderableSeries(wasmContext, {
// DataSeries defines data. This contains zValues 2D array plus the x and y cell offsets
dataSeries: new NonUniformHeatmapDataSeries(wasmContext, { zValues, xCellOffsets, yCellOffsets }),
// Color map defines how heatmap cells map to colours between minimum & maximum
colorMap: new HeatmapColorMap({
minimum: 0,
maximum: 100,
gradientStops: [
{ offset: 0, color: appTheme.DarkIndigo },
{ offset: 0.2, color: appTheme.Indigo },
{ offset: 0.3, color: appTheme.VividSkyBlue },
{ offset: 0.5, color: appTheme.VividGreen },
{ offset: 0.7, color: appTheme.MutedRed },
{ offset: 0.9, color: appTheme.VividOrange },
{ offset: 1, color: appTheme.VividPink },
],
}),
// optional settings
opacity: 0.77,
// values outside of the colorMap.min/max will be filled with the colours at edge of the colormap
fillValuesOutOfRange: true,
// add datalabels to the cells of the heatmap
dataLabels: {
style: {
fontFamily: "Arial",
fontSize: 16,
},
color: appTheme.ForegroundColor,
},
});
sciChartSurface.renderableSeries.add(heatmapSeries);
// add some interactivity
sciChartSurface.chartModifiers.add(
new ZoomPanModifier({ enableZoom: true }),
new ZoomExtentsModifier(),
new MouseWheelZoomModifier()
);
return { sciChartSurface };
};
This 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.








































