Our Contours Chart example demonstrates how to create a JavaScript Contour-map Chart using our powerful JavaScript Chart Library.
import {
HeatmapColorMap,
HeatmapLegend,
MouseWheelZoomModifier,
NumericAxis,
SciChartSurface,
UniformContoursRenderableSeries,
UniformHeatmapDataSeries,
UniformHeatmapRenderableSeries,
zeroArray2D,
ZoomExtentsModifier,
ZoomPanModifier,
} from "scichart";
import { appTheme, createChartTheme } from "./appTheme";
export const drawExample = async (rootElement: string | HTMLDivElement) => {
// Create a SciChartSurface
const { sciChartSurface, wasmContext } = await SciChartSurface.create(rootElement, {
theme: appTheme.SciChartJsTheme,
});
// Create an X & Y Axis
sciChartSurface.xAxes.add(new NumericAxis(wasmContext, { isVisible: false }));
sciChartSurface.yAxes.add(new NumericAxis(wasmContext, { isVisible: false }));
const heatmapWidth = 300;
const heatmapHeight = 200;
const colorPaletteMin = 0;
const colorPaletteMax = 200;
// Create a Heatmap Data-series. Pass heatValues as a number[][] to the UniformHeatmapDataSeries
const initialZValues = generateExampleData(3, heatmapWidth, heatmapHeight, colorPaletteMax);
const heatmapDataSeries = new UniformHeatmapDataSeries(wasmContext, {
zValues: initialZValues,
xStart: 0,
xStep: 1,
yStart: 0,
yStep: 1,
});
// Add the contours series and add to the chart
sciChartSurface.renderableSeries.add(
new UniformContoursRenderableSeries(wasmContext, {
dataSeries: heatmapDataSeries,
zMin: 20,
zMax: colorPaletteMax,
zStep: 20,
zOffset: 1,
strokeThickness: 1,
stroke: appTheme.ForegroundColor,
})
);
// Create a background heatmap series with the same data and add to the chart
sciChartSurface.renderableSeries.add(
new UniformHeatmapRenderableSeries(wasmContext, {
dataSeries: heatmapDataSeries,
useLinearTextureFiltering: false,
opacity: appTheme.isDark ? 0.5 : 0.85,
colorMap: new HeatmapColorMap({
minimum: colorPaletteMin,
maximum: colorPaletteMax,
gradientStops: [
{ offset: 1, color: appTheme.VividPink },
{ offset: 0.9, color: appTheme.VividOrange },
{ offset: 0.7, color: appTheme.MutedRed },
{ offset: 0.5, color: appTheme.VividGreen },
{ offset: 0.3, color: appTheme.VividSkyBlue },
{ offset: 0.2, color: appTheme.Indigo },
{ offset: 0, color: appTheme.DarkIndigo },
],
}),
})
);
// Add interaction
sciChartSurface.chartModifiers.add(new ZoomPanModifier({ enableZoom: true }));
sciChartSurface.chartModifiers.add(new ZoomExtentsModifier());
sciChartSurface.chartModifiers.add(new MouseWheelZoomModifier());
return { sciChartSurface };
};
export const drawHeatmapLegend = async (rootElement: string | HTMLDivElement) => {
const { heatmapLegend, wasmContext } = await HeatmapLegend.create(rootElement, {
theme: createChartTheme({
sciChartBackground: appTheme.DarkIndigo + "BB",
loadingAnimationBackground: appTheme.DarkIndigo + "BB",
}),
yAxisOptions: {
isInnerAxis: true,
labelStyle: {
fontSize: 12,
color: appTheme.ForegroundColor,
},
axisBorder: {
borderRight: 1,
color: appTheme.ForegroundColor + "77",
},
majorTickLineStyle: {
color: appTheme.ForegroundColor,
tickSize: 6,
strokeThickness: 1,
},
minorTickLineStyle: {
color: appTheme.ForegroundColor,
tickSize: 3,
strokeThickness: 1,
},
},
colorMap: {
minimum: 0,
maximum: 200,
gradientStops: [
{ offset: 1, color: appTheme.VividPink },
{ offset: 0.9, color: appTheme.VividOrange },
{ offset: 0.7, color: appTheme.MutedRed },
{ offset: 0.5, color: appTheme.VividGreen },
{ offset: 0.3, color: appTheme.VividSkyBlue },
{ offset: 0.2, color: appTheme.Indigo },
{ offset: 0, color: appTheme.DarkIndigo },
],
},
});
return { sciChartSurface: heatmapLegend.innerSciChartSurface.sciChartSurface };
};
// This function generates data for the heatmap with contours series example
function generateExampleData(index: number, heatmapWidth: number, heatmapHeight: number, colorPaletteMax: number) {
const zValues = zeroArray2D([heatmapHeight, heatmapWidth]);
const angle = (Math.PI * 2 * index) / 30;
let smallValue = 0;
for (let x = 0; x < heatmapWidth; x++) {
for (let y = 0; y < heatmapHeight; y++) {
const v =
(1 + Math.sin(x * 0.04 + angle)) * 50 +
(1 + Math.sin(y * 0.1 + angle)) * 50 * (1 + Math.sin(angle * 2));
const cx = heatmapWidth / 2;
const cy = heatmapHeight / 2;
const r = Math.sqrt((x - cx) * (x - cx) + (y - cy) * (y - cy));
const exp = Math.max(0, 1 - r * 0.008);
const zValue = v * exp;
zValues[y][x] = zValue > colorPaletteMax ? colorPaletteMax : zValue;
zValues[y][x] += smallValue;
}
smallValue += 0.001;
}
return zValues;
}
This example demonstrates how to create an interactive heatmap chart with contours using SciChart.js in JavaScript. It renders a vivid heatmap background combined with overlaid contour lines, providing a powerful visualization tool for data analysis.
The chart is initialized asynchronously using async/await, ensuring a smooth startup process. For more information on asynchronous initialization in JavaScript, refer to Async and Await in JavaScript and How to use async and await with JavaScript. The implementation sets up hidden numeric X and Y axes and creates a data series using a custom generator. Two main renderable series are used: the UniformHeatmapRenderableSeries for the heatmap and the UniformContoursRenderableSeries for the contours. Detailed information about the contours series can be found in the Contours Series documentation.
The example supports advanced interactive features. Chart navigation is enhanced with modifiers such as ZoomPanModifier, ZoomExtentsModifier, and MouseWheelZoomModifier; further details are available in the Tutorial 03 - Adding Zooming, Panning Behavior. Additionally, a dynamic color mapping is applied via the HeatmapColorMap with multiple gradient stops, and the layered rendering of heatmap and contour series creates a comprehensive visualization platform.
The implementation follows best practices by separating data generation from rendering logic, which promotes maintainability and scalability. The use of WebGL rendering in SciChart.js guarantees high performance, as described in the Advanced JavaScript Chart and Graph Library page. This example, built purely with JavaScript, serves as a solid foundation for developers looking to create high-performance, interactive charts without relying on additional frameworks.








































