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 VIEWS: any = {
droplet: { layout: 'custom', positions: 'droplet' },
tree: { layout: 'custom', positions: 'tree' },
leaf: { layout: 'custom', positions: 'leaf' },
sun: { layout: 'custom', positions: 'sun' },
flame: { layout: 'custom', positions: 'flame' },
fish: { layout: 'custom', positions: 'fish' },
house: { layout: 'custom', positions: 'house' },
battery: { layout: 'custom', positions: 'battery' },
rocket: { layout: 'custom', positions: 'rocket' },
bulb: { layout: 'custom', positions: 'bulb' },
flask: { layout: 'custom', positions: 'flask' },
car: { layout: 'custom', positions: 'car' },
plane: { layout: 'custom', positions: 'plane' },
human: { layout: 'custom', positions: 'human' },
group: { layout: 'custom', positions: 'group' },
target: { layout: 'custom', positions: 'target' },
trophy: { layout: 'custom', positions: 'trophy' },
moneybag: { layout: 'custom', positions: 'moneybag' },
funnel: { layout: 'custom', positions: 'funnel' },
shield: { layout: 'custom', positions: 'shield' },
gear: { layout: 'custom', positions: 'gear' },
robot: { layout: 'custom', positions: 'robot' },
heart: { layout: 'custom', positions: 'heart' },
pyramid: { layout: 'custom', positions: 'pyramid' },
star: { layout: 'custom', positions: 'star' },
arrow: { layout: 'custom', positions: 'arrow' },
crown: { layout: 'custom', positions: 'crown' },
cross: { layout: 'custom', positions: 'cross' },
bolt: { layout: 'custom', positions: 'bolt' },
globe: { layout: 'custom', positions: 'globe' },
pin: { layout: 'custom', positions: 'pin' },
mountain: { layout: 'custom', positions: 'mountain' },
check: { layout: 'custom', positions: 'check' },
wifi: { layout: 'custom', positions: 'wifi' },
pulse: { layout: 'custom', positions: 'pulse' },
xmark: { layout: 'custom', positions: 'xmark' },
percent: { layout: 'custom', positions: 'percent' },
question: { layout: 'custom', positions: 'question' },
spiral: { layout: 'custom', positions: 'spiral' },
packed: { layout: 'packed', positions: undefined },
columns: { layout: 'columns', positions: undefined },
};
private setActive = (id: any): any => {
document
.querySelectorAll('.actions button[data-view]')
.forEach(function (btn) {
btn.classList.toggle('active', btn.getAttribute('data-view') === id)
})
};
private wireGallery = (chart: any): any => {
var current = 'heart'
this.setActive(current)
document
.querySelectorAll('.actions button[data-view]')
.forEach(function (btn) {
btn.addEventListener('click', function () {
var id = btn.getAttribute('data-view')
if (id === current) return
current = id
this.setActive(current)
chart.updateOptions({ plotOptions: { unit: this.VIEWS[id] } })
})
})
};
public chartOptions: Partial<ChartOptions> = {
series: [576, 168, 42, 34],
chart: {
id: 'shapeGallery',
type: 'unit',
height: 460,
animations: {
enabled: true,
speed: 900,
},
},
labels: ['Engineering', 'Sales', 'Marketing', 'Operations'],
colors: ['#008FFB', '#00B8D9', '#FFAB00', '#FF4560'],
plotOptions: {
unit: {
layout: 'custom',
positions: 'heart',
// Keyed by global order, so the crowd migrates across a relayout instead
// of each category fading in and out on the spot.
transition: 'flow',
clusterLabels: {
show: false,
},
},
},
legend: {
position: 'bottom',
},
};
ngAfterViewInit() {
(window as any).ApexCharts.setLicense('APEX-eyJleHBpcnlEYXRlIjoiMjEyNi0wNy0wNCIsImlzc3VlRGF0ZSI6IjIwMjYtMDctMjgiLCJwbGFuIjoicHJlbWl1bSIsImRvbWFpbnMiOlsiYXBleGNoYXJ0cy5jb20iLCIxMjcuMC4wLjEiLCJsb2NhbGhvc3QiXSwic2lnIjoieVBmb1VCc0Z3TU9ZdUEyaEZkR0I2Y1FtZ0JITUtXcVdJSjB2NVRESXRZbFR3eDJMUmh6R2x0RUc3VXJ4X0s3b25ZMWRZb2Z2VGItN01ydFYyNDVyOWcifQ==');
this.wireGallery(this.chart)
function wireGallery(chart) {
var current = 'heart'
this.setActive(current)
document
.querySelectorAll('.actions button[data-view]')
.forEach(function (btn) {
btn.addEventListener('click', () => {
var id = btn.getAttribute('data-view')
if (id === current) return
current = id
this.setActive(current)
this.chart.updateOptions({ plotOptions: { unit: this.VIEWS[id] } })
})
})
}
}
ngOnDestroy() {
// no cleanup needed
}
}