Angular Heatmap Chart

If you want to learn about heatmaps. this demo shows you how to create a Angular Heatmap Chart using SciChart.js, our 5-star rated JavaScript Chart Component.

# Heatmap Size: 0 x 0
FPS: 00

Fullscreen

Edit

 Edit

Docs

drawExample.ts

angular.ts

theme.ts

Copy to clipboard
Minimise
Fullscreen
1import {
2    HeatmapColorMap,
3    HeatmapLegend,
4    MouseWheelZoomModifier,
5    NumericAxis,
6    SciChartSurface,
7    UniformHeatmapDataSeries,
8    UniformHeatmapRenderableSeries,
9    zeroArray2D,
10    ZoomExtentsModifier,
11    ZoomPanModifier,
12} from "scichart";
13import { appTheme } from "../../../theme";
14
15const MAX_SERIES = 100;
16const WIDTH = 300;
17const HEIGHT = 200;
18
19// Draws a Heatmap chart in real-time
20export const drawExample = async (rootElement: string | HTMLDivElement) => {
21    // Create a SciChartSurface
22    const { sciChartSurface, wasmContext } = await SciChartSurface.create(rootElement, {
23        theme: appTheme.SciChartJsTheme,
24    });
25
26    // Add XAxis and YAxis
27    sciChartSurface.xAxes.add(new NumericAxis(wasmContext, { isVisible: false }));
28    sciChartSurface.yAxes.add(new NumericAxis(wasmContext, { isVisible: false }));
29
30    // Create a Heatmap Data-series. Pass heatValues as a number[][] to the UniformHeatmapDataSeries
31    const initialZValues: number[][] = generateExampleData(WIDTH, HEIGHT, 200, 20, MAX_SERIES);
32    const heatmapDataSeries = new UniformHeatmapDataSeries(wasmContext, {
33        xStart: 0,
34        xStep: 1,
35        yStart: 0,
36        yStep: 1,
37        zValues: initialZValues,
38    });
39
40    // Create a Heatmap RenderableSeries with the color map. ColorMap.minimum/maximum defines the values in
41    // HeatmapDataSeries which correspond to gradient stops at 0..1
42    const heatmapSeries = new UniformHeatmapRenderableSeries(wasmContext, {
43        dataSeries: heatmapDataSeries,
44        useLinearTextureFiltering: false,
45        colorMap: new HeatmapColorMap({
46            minimum: 0,
47            maximum: 200,
48            gradientStops: [
49                { offset: 1, color: appTheme.VividPink },
50                { offset: 0.9, color: appTheme.VividOrange },
51                { offset: 0.7, color: appTheme.MutedRed },
52                { offset: 0.5, color: appTheme.VividGreen },
53                { offset: 0.3, color: appTheme.VividSkyBlue },
54                { offset: 0.2, color: appTheme.Indigo },
55                { offset: 0, color: appTheme.DarkIndigo },
56            ],
57        }),
58    });
59
60    // Add heatmap to the chart
61    sciChartSurface.renderableSeries.add(heatmapSeries);
62
63    // Add interaction
64    sciChartSurface.chartModifiers.add(new ZoomPanModifier({ enableZoom: true }));
65    sciChartSurface.chartModifiers.add(new ZoomExtentsModifier());
66    sciChartSurface.chartModifiers.add(new MouseWheelZoomModifier());
67
68    // Functions for running the example in real-time
69    let timerId: NodeJS.Timeout;
70    let updateIndex: number = 0;
71
72    const updateChart = () => {
73        // Cycle through pre-generated data on timer tick
74        const newZValues = generateExampleData(WIDTH, HEIGHT, 200, updateIndex++, MAX_SERIES);
75        // Update the heatmap z-values
76        heatmapDataSeries.setZValues(newZValues);
77        if (updateIndex >= MAX_SERIES) {
78            updateIndex = 0;
79        }
80        timerId = setTimeout(updateChart, 16);
81    };
82
83    const startUpdate = () => {
84        if (!timerId) {
85            updateChart();
86        }
87    };
88
89    const stopUpdate = () => {
90        clearTimeout(timerId);
91        timerId = undefined;
92    };
93
94    const subscribeToRenderStats = (callback: (stats: { xSize: number; ySize: number; fps: number }) => void) => {
95        // Handle drawing/updating FPS
96        let lastRendered = Date.now();
97        sciChartSurface.rendered.subscribe(() => {
98            const currentTime = Date.now();
99            const timeDiffSeconds = (currentTime - lastRendered) / 1000;
100            lastRendered = currentTime;
101            const fps = 1 / timeDiffSeconds;
102            callback({
103                xSize: heatmapDataSeries.arrayWidth,
104                ySize: heatmapDataSeries.arrayHeight,
105                fps,
106            });
107        });
108    };
109
110    return { sciChartSurface, subscribeToRenderStats, controls: { startUpdate, stopUpdate } };
111};
112
113// Draws a Heatmap legend over the <div id={divHeatmapLegend}></div>
114export const drawHeatmapLegend = async (rootElement: string | HTMLDivElement) => {
115    const { heatmapLegend, wasmContext } = await HeatmapLegend.create(rootElement, {
116        theme: {
117            ...appTheme.SciChartJsTheme,
118            sciChartBackground: appTheme.DarkIndigo + "BB",
119            loadingAnimationBackground: appTheme.DarkIndigo + "BB",
120        },
121        yAxisOptions: {
122            isInnerAxis: true,
123            labelStyle: {
124                fontSize: 12,
125                color: appTheme.ForegroundColor,
126            },
127            axisBorder: {
128                borderRight: 1,
129                color: appTheme.ForegroundColor + "77",
130            },
131            majorTickLineStyle: {
132                color: appTheme.ForegroundColor,
133                tickSize: 6,
134                strokeThickness: 1,
135            },
136            minorTickLineStyle: {
137                color: appTheme.ForegroundColor,
138                tickSize: 3,
139                strokeThickness: 1,
140            },
141        },
142        colorMap: {
143            minimum: 0,
144            maximum: 200,
145            gradientStops: [
146                { offset: 1, color: appTheme.VividPink },
147                { offset: 0.9, color: appTheme.VividOrange },
148                { offset: 0.7, color: appTheme.MutedRed },
149                { offset: 0.5, color: appTheme.VividGreen },
150                { offset: 0.3, color: appTheme.VividSkyBlue },
151                { offset: 0.2, color: appTheme.Indigo },
152                { offset: 0, color: appTheme.DarkIndigo },
153            ],
154        },
155    });
156
157    return { sciChartSurface: heatmapLegend.innerSciChartSurface.sciChartSurface };
158};
159
160// This function generates data for the heatmap series example
161// because data-generation is not trivial, we generate once before the example starts
162// so you can see the speed & power of SciChart.js
163function generateExampleData(
164    width: number,
165    height: number,
166    cpMax: number,
167    index: number,
168    maxIndex: number
169): number[][] {
170    // Returns a 2-dimensional javascript array [height (y)] [width (x)] size
171    const zValues = zeroArray2D([height, width]);
172
173    // math.round but to X digits
174    function roundTo(number: number, digits: number) {
175        return number;
176        // return parseFloat(number.toFixed(digits));
177    }
178
179    const angle = roundTo(Math.PI * 2 * index, 3) / maxIndex;
180
181    // When appending data to a 2D Array for the heatmap, the order of appending (X,Y) does not matter
182    // but when accessing the zValues[][] array, we set data [y] then [x]
183    for (let y = 0; y < height; y++) {
184        for (let x = 0; x < width; x++) {
185            const v =
186                (1 + roundTo(Math.sin(x * 0.04 + angle), 3)) * 50 +
187                (1 + roundTo(Math.sin(y * 0.1 + angle), 3)) * 50 * (1 + roundTo(Math.sin(angle * 2), 3));
188            const cx = width / 2;
189            const cy = height / 2;
190            const r = Math.sqrt((x - cx) * (x - cx) + (y - cy) * (y - cy));
191            const exp = Math.max(0, 1 - r * 0.008);
192            const zValue = v * exp + Math.random() * 10;
193            zValues[y][x] = zValue > cpMax ? cpMax : zValue;
194        }
195    }
196    return zValues;
197}
198

Angular Heatmap Chart Example

Overview

This example demonstrates how to integrate SciChart.js with Angular using Standalone Components and the scichart-angular package. It showcases a high-performance heatmap visualization that updates in real-time while providing interactive controls to start and stop the updates.

Technical Implementation

The implementation leverages a custom Angular Standalone Component that embeds the ScichartAngularComponent. The chart is created via the asynchronous function drawExample which initializes the SciChartSurface, attaches numeric axes (hidden for a cleaner look), and sets up a uniform heatmap data series. Real-time updates are managed using JavaScript’s setTimeout, while performance is monitored by subscribing to render events to extract data such as FPS and heatmap dimensions. This approach adheres to the integration patterns described in the scichart-angular documentation and the Getting Started with SciChart JS guide.

Features and Capabilities

The example includes advanced features such as dynamic color mapping using a detailed gradient setup, a dedicated heatmap legend provided by the drawHeatmapLegend function, and interactive chart modifiers including zoom and pan functionalities. The real-time data update mechanism allows the chart to refresh continuously with performance statistics being updated live. This ensures that developers can monitor and optimize rendering performance using insights provided by Performance Tips & Tricks.

Integration and Best Practices

Angular-specific integration is handled using property binding and event subscriptions, ensuring smooth communication between the Angular component and the SciChartSurface instance. The example follows best practices for Angular lifecycle management, as detailed in the Component Lifecycle - Angular documentation. Additionally, Angular event handling and dynamic styling are used to control chart behavior and update the UI in response to user interactions, making the integration robust and maintainable.

Developers looking to extend or customize this implementation can refer to the provided documentation links for deeper technical context and further optimization techniques.

angular Chart Examples & Demos

See Also: JavaScript Chart Types (39 Demos)

Angular Line Chart | Angular Charts | SciChart.js Demo

Angular Line Chart

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

Angular Spline Line Chart | Angular Charts | SciChart.js Demo

Angular Spline Line Chart

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

Angular Digital Line Chart | Angular Charts | SciChart.js

Angular Digital Line Chart

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

Angular Band Chart | Angular Charts | SciChart.js Demo

Angular Band Chart

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

Angular Spline Band Chart | Angular Charts | SciChart.js Demo

Angular Spline Band Chart

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

Angular Digital Band Chart | Angular Charts | SciChart.js

Angular Digital Band Chart

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

Angular Bubble Chart | Online JavaScript Chart Examples

Angular Bubble Chart

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

Angular Candlestick Chart | Online JavaScript Chart Examples

Angular Candlestick Chart

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

Angular Column Chart | Angular Charts | SciChart.js Demo

Angular Column Chart

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

Angular Population Pyramid | Angular Charts | SciChart.js

Angular Population Pyramid

Population Pyramid of Europe and Africa

Angular Error Bars Char | Angular Charts | SciChart.js Demo

Angular Error Bars Chart

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

Angular Impulse Chart | Angular Charts | SciChart.js Demo

Angular Impulse Chart

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

Angular Text Chart | Angular Charts | SciChart.js Demo

Angular Text Chart

Create Angular Text Chart with high performance SciChart.js.

Angular Fan Chart | Angular Charts | SciChart.js Demo

Angular Fan Chart

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

Angular Non Uniform Heatmap Chart | SciChart.js Demo

Angular Non Uniform Heatmap Chart

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

Angular Heatmap Chart With Contours | SciChart.js Demo

Angular Heatmap Chart With Contours Example

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

NEW!
Angular Map Chart with Heatmap overlay | SciChart.js Demo

Angular Map Chart with Heatmap overlay

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

Angular Mountain Chart | Angular Charts | SciChart.js Demo

Angular Mountain Chart

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

Angular Spline Mountain Chart | Angular Charts | SciChart.js

Angular Spline Mountain Chart

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

Angular Digital Mountain Chart | Angular Charts | SciChart.js

Angular Digital Mountain Chart

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

Angular Realtime Mountain Chart | View Online At SciChart

Angular Realtime Mountain Chart

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

Angular Scatter Chart | Angular Charts | SciChart.js Demo

Angular Scatter Chart

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

Angular Stacked Column Chart | Online JavaScript Charts

Angular Stacked Column Chart

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

Angular Stacked Group Column Chart | View Examples Now

Angular Stacked Column Side by Side

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

Angular Stacked Mountain Chart | Angular Charts | SciChart.js

Angular Stacked Mountain Chart

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

Angular Smooth Stacked Mountain Chart | SciChart.js Demo

Angular Smooth Stacked Mountain Chart

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

Angular Pie Chart | Angular Charts | SciChart.js Demo

Angular Pie Chart

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

Angular Donut Chart | Angular Charts | SciChart.js Demo

Angular Donut Chart

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

Angular Linear Gauges | Angular Charts | SciChart.js Demo

Angular Linear Gauges Example

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

Angular Quadrant Chart using Background Annotations

Angular Quadrant Chart using Background Annotations

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

Angular Histogram Chart | Angular Charts | SciChart.js Demo

Angular Histogram Chart

Create an Angular Histogram Chart with custom texture fills and patterns. Try the SciChartAngular wrapper component for seamless Angular integration today.

Angular Gantt Chart | Angular Charts | SciChart.js Demo

Angular Gantt Chart Example

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

Angular Choropleth Map | Angular Charts | SciChart.js Demo

Angular Choropleth Map Example

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

Angular Multi-Layer Map | Angular Charts | SciChart.js Demo

Angular Multi-Layer Map Example

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

Angular Vector Field Plot | Angular Charts | SciChart.js Demo

Angular Vector Field Plot

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

Angular Waterfall Chart | Bridge Chart | SciChart.js Demo

Angular Waterfall Chart | Bridge Chart

Build an Angular Waterfall Chart with dynamic coloring, multi-line data labels & responsive design, using ScichartAngular component for seamless integration

Angular Box Plot Chart | Angular Charts | SciChart.js Demo

Angular Box Plot Chart

Try the Angular Box Plot Chart example for Angular-friendly chart lifecycle management, dynamic sub-surface positioning, and custom styling. Try the demo now.

Angular Triangle Series | Triangle Mesh Chart | SciChart

Angular Triangle Series | Triangle Mesh Chart

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

Angular Treemap Chart | Angular Charts | SciChart.js Demo

Angular Treemap Chart

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

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