This demo uses imperative chart updates. The generated code is a faithful Angular translation: open it in CodeSandbox to run and tweak.
import { Component, AfterViewInit, OnDestroy, ViewChild } from '@angular/core';
import {
ChartComponent,
ApexAxisChartSeries,
ApexNonAxisChartSeries,
ApexChart,
ApexXAxis,
ApexYAxis,
ApexTitleSubtitle,
ApexDataLabels,
ApexStroke,
ApexFill,
ApexLegend,
ApexTooltip,
ApexMarkers,
ApexPlotOptions,
ApexResponsive,
ApexGrid,
ApexAnnotations,
ApexStates,
ApexTheme,
NgApexchartsModule,
} from 'ng-apexcharts';
export type ChartOptions = {
series?: ApexAxisChartSeries | ApexNonAxisChartSeries;
chart?: ApexChart;
xaxis?: ApexXAxis;
yaxis?: ApexYAxis | ApexYAxis[];
title?: ApexTitleSubtitle;
subtitle?: ApexTitleSubtitle;
dataLabels?: ApexDataLabels;
stroke?: ApexStroke;
fill?: ApexFill;
legend?: ApexLegend;
tooltip?: ApexTooltip;
markers?: ApexMarkers;
plotOptions?: ApexPlotOptions;
responsive?: ApexResponsive[];
grid?: ApexGrid;
annotations?: ApexAnnotations;
states?: ApexStates;
theme?: ApexTheme;
colors?: string[];
labels?: any;
};
@Component({
selector: 'app-chart',
standalone: true,
imports: [NgApexchartsModule],
templateUrl: './chart.component.html',
})
export class AppChart implements AfterViewInit, OnDestroy {
@ViewChild('chart') chart!: ChartComponent;
private mulberry32 = (seed: any): any => {
return function () {
seed |= 0
seed = (seed + 0x6d2b79f5) | 0
var t = Math.imul(seed ^ (seed >>> 15), 1 | seed)
t = (t + Math.imul(t ^ (t >>> 7), 61 | t)) ^ t
return ((t ^ (t >>> 14)) >>> 0) / 4294967296
}
};
private DAYS: any = ['Sun', 'Sat', 'Fri', 'Thu', 'Wed', 'Tue', 'Mon'];
private HOURS: any = ['6a', '8a', '10a', '12p', '2p', '4p', '6p', '8p'];
private LOCATIONS: any = [
{
name: 'Central Station',
seed: 7,
volume: 1.0,
peaks: [1, 6],
weekend: 0.45,
},
{ name: 'Harbor Point', seed: 19, volume: 0.82, peaks: [1, 6], weekend: 0.6 },
{
name: 'University Campus',
seed: 31,
volume: 0.66,
peaks: [3, 4],
weekend: 0.3,
},
{
name: 'Riverside Mall',
seed: 43,
volume: 0.58,
peaks: [4, 5],
weekend: 1.15,
},
{
name: 'Airport North',
seed: 59,
volume: 0.74,
peaks: [0, 7],
weekend: 0.95,
},
{
name: 'Lakeside Park',
seed: 71,
volume: 0.31,
peaks: [5, 6],
weekend: 1.4,
},
];
private hourlyRow = (rand: any, loc: any, dayIndex: any): any => {
// DAYS runs Sun..Mon top to bottom, so weekend factor keys off the ends.
var isWeekend = dayIndex === 0 || dayIndex === 1
var dayFactor = isWeekend ? loc.weekend : 0.85 + rand() * 0.3
return this.HOURS.map(function (hour, hi) {
var near = Math.min(
Math.abs(hi - loc.peaks[0]),
Math.abs(hi - loc.peaks[1]),
)
var shape = Math.max(0.12, 1 - near * 0.28)
var v = 130 * loc.volume * dayFactor * shape * (0.85 + rand() * 0.3)
return { x: hour, y: Math.round(v) }
})
};
private activitySeries: any = [];
public chartOptions: Partial<ChartOptions> = {
series: this.activitySeries,
chart: {
id: 'activityTrellis',
type: 'heatmap',
height: 620,
animations: {
enabled: false,
},
},
trellis: {
by: 'location',
columns: 3,
minPanelWidth: 300,
gap: 14,
},
colors: ['#0E7490'],
plotOptions: {
heatmap: {
radius: 2,
enableShades: true,
shadeIntensity: 0.55,
colorScale: {
gradientLegend: {
formatter: (val) => {
return Math.round(Number(val)) + ' check-ins'
},
},
},
},
},
dataLabels: {
enabled: false,
},
stroke: {
width: 1,
colors: ['#fff'],
},
xaxis: {
type: 'category',
},
tooltip: {
compact: true,
y: {
formatter: (val) => {
return val + ' check-ins'
},
},
},
};
ngAfterViewInit() {
(window as any).ApexCharts.setLicense('APEX-eyJleHBpcnlEYXRlIjoiMjEyNi0wNy0wNCIsImlzc3VlRGF0ZSI6IjIwMjYtMDctMjgiLCJwbGFuIjoicHJlbWl1bSIsImRvbWFpbnMiOlsiYXBleGNoYXJ0cy5jb20iLCIxMjcuMC4wLjEiLCJsb2NhbGhvc3QiXSwic2lnIjoieVBmb1VCc0Z3TU9ZdUEyaEZkR0I2Y1FtZ0JITUtXcVdJSjB2NVRESXRZbFR3eDJMUmh6R2x0RUc3VXJ4X0s3b25ZMWRZb2Z2VGItN01ydFYyNDVyOWcifQ==');
this.LOCATIONS.forEach(function (loc) {
var rand = this.mulberry32(loc.seed)
this.DAYS.forEach(function (day, di) {
this.activitySeries.push({
name: day,
location: loc.name,
data: this.hourlyRow(rand, loc, di),
})
})
})
}
ngOnDestroy() {
// no cleanup needed
}
}