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 pictoState: any = { layout: 'heart', mark: 'person' };
private pictoOptions = (): any => {
return {
plotOptions: {
unit: {
positions: this.pictoState.layout,
shape: this.pictoState.mark ? 'pictogram' : 'circle',
pictogram: { mark: this.pictoState.mark || undefined },
},
},
}
};
private pictoPaint = (): any => {
document.querySelectorAll('#layout-nav button').forEach(function (b) {
b.classList.toggle(
'on',
b.getAttribute('data-layout') === this.pictoState.layout,
)
})
document.querySelectorAll('#mark-nav button').forEach(function (b) {
b.classList.toggle('on', b.getAttribute('data-mark') === this.pictoState.mark)
})
};
private pictoWire = (chart: any): any => {
document.querySelectorAll('#layout-nav button').forEach(function (b) {
b.addEventListener('click', function () {
this.pictoState.layout = b.getAttribute('data-layout')
chart.updateOptions(this.pictoOptions(), false, true)
this.pictoPaint()
})
})
document.querySelectorAll('#mark-nav button').forEach(function (b) {
b.addEventListener('click', function () {
this.pictoState.mark = b.getAttribute('data-mark')
chart.updateOptions(this.pictoOptions(), false, true)
this.pictoPaint()
})
})
this.pictoPaint()
};
public chartOptions: Partial<ChartOptions> = {
series: [820, 410, 170],
chart: {
type: 'unit',
id: 'pictoCrowd',
height: 460,
animations: {
enabled: true,
speed: 900,
},
},
labels: ['Weekday shifts', 'Weekend shifts', 'On call'],
colors: ['#1D4E89', '#00A6A0', '#FF8A3D'],
plotOptions: {
unit: {
layout: 'custom',
positions: 'heart',
// A glyph, not a dot. `mark` names one of the pictograms; the chart fits
// it to the box the dot would have occupied, so switching between them
// never re-flows the layout.
shape: 'pictogram',
pictogram: {
mark: 'person',
},
// The same specific volunteer keeps their glyph and colour when the layout
// changes, so a shape swap reads as the crowd walking rather than as a
// slideshow.
transition: 'flow',
unitValue: 10,
clusterLabels: {
show: false,
},
},
},
legend: {
position: 'bottom',
},
};
ngAfterViewInit() {
(window as any).ApexCharts.setLicense('APEX-eyJleHBpcnlEYXRlIjoiMjEyNi0wNy0wNCIsImlzc3VlRGF0ZSI6IjIwMjYtMDctMjgiLCJwbGFuIjoicHJlbWl1bSIsImRvbWFpbnMiOlsiYXBleGNoYXJ0cy5jb20iLCIxMjcuMC4wLjEiLCJsb2NhbGhvc3QiXSwic2lnIjoieVBmb1VCc0Z3TU9ZdUEyaEZkR0I2Y1FtZ0JITUtXcVdJSjB2NVRESXRZbFR3eDJMUmh6R2x0RUc3VXJ4X0s3b25ZMWRZb2Z2VGItN01ydFYyNDVyOWcifQ==');
this.pictoWire(this.chart)
function pictoWire(chart) {
document.querySelectorAll('#layout-nav button').forEach(function (b) {
b.addEventListener('click', () => {
this.pictoState.layout = b.getAttribute('data-layout')
this.chart.updateOptions(this.pictoOptions(), false, true)
this.pictoPaint()
})
})
document.querySelectorAll('#mark-nav button').forEach(function (b) {
b.addEventListener('click', () => {
this.pictoState.mark = b.getAttribute('data-mark')
this.chart.updateOptions(this.pictoOptions(), false, true)
this.pictoPaint()
})
})
this.pictoPaint()
}
}
ngOnDestroy() {
// no cleanup needed
}
}