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 LEAD: any = '#FFAB00';
private ROSTER: any = [
{
name: 'Engineering',
data: [
{ name: 'Ana Ruiz', role: 'Engineering Lead', fillColor: this.LEAD },
{ name: 'Ben Cho', role: 'Staff Engineer' },
{ name: 'Priya Nair', role: 'Senior Engineer' },
{ name: 'Marco Silva', role: 'Senior Engineer' },
{ name: 'Yuki Tanaka', role: 'Engineer' },
{ name: 'Sam Okoye', role: 'Engineer' },
{ name: 'Lena Fischer', role: 'Engineer' },
{ name: 'Diego Torres', role: 'Engineer' },
{ name: 'Hana Kim', role: 'Junior Engineer' },
{ name: 'Omar Haddad', role: 'Junior Engineer' },
],
},
{
name: 'Design',
data: [
{ name: 'Noa Levi', role: 'Design Lead', fillColor: this.LEAD },
{ name: 'Tom Beck', role: 'Senior Designer' },
{ name: 'Ivy Chen', role: 'Product Designer' },
{ name: 'Kofi Mensah', role: 'Product Designer' },
{ name: 'Sara Nowak', role: 'Designer' },
{ name: 'Leo Rossi', role: 'Designer' },
],
},
{
name: 'Sales',
data: [
{ name: 'Mara Vidal', role: 'Sales Lead', fillColor: this.LEAD },
{ name: 'Jon Park', role: 'Account Executive' },
{ name: 'Ella Brandt', role: 'Account Executive' },
{ name: 'Raj Mehta', role: 'Account Executive' },
{ name: 'Fay Duval', role: 'SDR' },
{ name: 'Cole Ward', role: 'SDR' },
{ name: 'Nia Abara', role: 'SDR' },
{ name: 'Theo Blanc', role: 'SDR' },
],
},
];
private rosterTooltip = (o: any): any => {
if (!o.datum) return o.seriesName
return (
'<div style="font-weight:700">' +
o.datum.name +
'</div>' +
'<div style="opacity:0.7">' +
o.datum.role +
'</div>'
)
};
public chartOptions: Partial<ChartOptions> = {
series: this.ROSTER,
chart: {
type: 'unit',
height: 440,
animations: {
enabled: true,
speed: 700,
},
},
colors: ['#008FFB', '#00B8D9', '#36B37E'],
legend: {
show: false,
},
plotOptions: {
unit: {
layout: 'grouped',
spacing: 1.2,
clusterLabels: {
show: true,
// Team name + headcount, e.g. "Engineering (10)".
formatter: (name, opts) => {
return name + ' (' + opts.value + ')'
},
},
tooltip: {
// rosterTooltip lives in the shared head script.
formatter: this.rosterTooltip,
},
},
},
};
ngAfterViewInit() {
(window as any).ApexCharts.setLicense('APEX-eyJpc3N1ZURhdGUiOiIyMDI2LTA0LTE2IiwiZXhwaXJ5RGF0ZSI6IjIwNTItMDQtMTciLCJwbGFuIjoiZW50ZXJwcmlzZSIsImRvbWFpbnMiOlsiYXBleGNoYXJ0cy5jb20iLCIxMjcuMC4wLjEiXX0=');
}
ngOnDestroy() {
// no cleanup needed
}
}