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;
public chartOptions: Partial<ChartOptions> = {
series: [
{
name: 'Jan',
data: generateData(18, { min: 0, max: 90 }),
},
{
name: 'Feb',
data: generateData(18, { min: 10, max: 90 }),
},
{
name: 'Mar',
data: generateData(18, { min: 20, max: 100 }),
},
{
name: 'Apr',
data: generateData(18, { min: 10, max: 100 }),
},
{
name: 'May',
data: generateData(18, { min: 0, max: 50 }),
},
{
name: 'Jun',
data: generateData(18, { min: 0, max: 90 }),
},
{
name: 'Jul',
data: generateData(18, { min: 0, max: 90 }),
},
{
name: 'Aug',
data: generateData(18, { min: 0, max: 90 }),
},
{
name: 'Sep',
data: generateData(18, { min: 0, max: 90 }),
},
{
name: 'Oct',
data: generateData(18, { min: 0, max: 90 }),
},
{
name: 'Nov',
data: generateData(18, { min: 0, max: 90 }),
},
{
name: 'Dec',
data: generateData(18, { min: 0, max: 90 }),
},
],
chart: {
height: 380,
type: 'heatmap',
},
plotOptions: {
heatmap: {
shadeIntensity: 0.5,
radius: 2,
useFillColorAsStroke: false,
colorScale: {
// Continuous gradient legend replaces the default categorical legend.
// The arrow tracks the hovered cell's value along the spectrum and
// automatically reorients based on legend.position.
gradientLegend: {
enabled: true,
width: '75%',
thickness: 14,
showHoverValue: true,
},
},
},
},
colors: ['#008FFB'],
dataLabels: {
enabled: false,
},
stroke: {
width: 1,
},
legend: {
position: 'right',
},
title: {
text: 'Monthly Rainfall (mm) — continuous gradient legend',
},
};
ngAfterViewInit() {
(window as any).ApexCharts.setLicense('APEX-eyJpc3N1ZURhdGUiOiIyMDI2LTA0LTE2IiwiZXhwaXJ5RGF0ZSI6IjIwNTItMDQtMTciLCJwbGFuIjoiZW50ZXJwcmlzZSIsImRvbWFpbnMiOlsiYXBleGNoYXJ0cy5jb20iLCIxMjcuMC4wLjEiXX0=');
}
ngOnDestroy() {
// no cleanup needed
}
}