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 PERSON_ICON: any = 'data:image/svg+xml,' +
encodeURIComponent(
'<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="#5B8DEF">' +
'<circle cx="12" cy="7" r="4"/>' +
'<path d="M4 21c0-4.4 3.6-8 8-8s8 3.6 8 8z"/>' +
'</svg>',
);
public chartOptions: Partial<ChartOptions> = {
series: [520000, 1180000, 300000],
chart: {
type: 'unit',
height: 440,
animations: {
enabled: true,
speed: 900,
},
},
labels: ['Under 18', '18 to 64', '65 and over'],
colors: ['#5B8DEF', '#00B8A9', '#F6A609'],
series: [520000, 1180000, 300000],
legend: {
position: 'bottom',
},
plotOptions: {
unit: {
layout: 'grouped',
shape: 'image',
unitValue: 25000,
spacing: 1.2,
image: {
src: this.PERSON_ICON,
width: 16,
height: 16,
// Recolour each icon to its category colour so the crowd matches the
// legend (the source icon is a single-colour silhouette).
tint: true,
},
clusterLabels: {
show: true,
},
},
},
};
ngAfterViewInit() {
(window as any).ApexCharts.setLicense('APEX-eyJpc3N1ZURhdGUiOiIyMDI2LTA0LTE2IiwiZXhwaXJ5RGF0ZSI6IjIwNTItMDQtMTciLCJwbGFuIjoiZW50ZXJwcmlzZSIsImRvbWFpbnMiOlsiYXBleGNoYXJ0cy5jb20iLCIxMjcuMC4wLjEiXX0=');
}
ngOnDestroy() {
// no cleanup needed
}
}