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 mulberry32 = (seed: any): any => {
return function () {
seed |= 0
seed = (seed + 0x6d2b79f5) | 0
var t = Math.imul(seed ^ (seed >>> 15), 1 | seed)
t = (t + Math.imul(t ^ (t >>> 7), 61 | t)) ^ t
return ((t ^ (t >>> 14)) >>> 0) / 4294967296
}
};
private TASKS: any = [
'Ad hoc',
'Reports',
'Dashboards',
'Alerts',
'Modeling',
'Sharing',
'Exports',
];
private TEAMS: any = [
{ name: 'Atlas', color: '#2563EB', profile: [64, 52, 44, 22, 18, 14, 8] },
{ name: 'Beacon', color: '#0E7490', profile: [58, 61, 39, 26, 12, 19, 11] },
{ name: 'Cobalt', color: '#15803D', profile: [41, 38, 57, 34, 9, 24, 6] },
{ name: 'Delta', color: '#B45309', profile: [67, 44, 31, 17, 26, 12, 14] },
{ name: 'Ember', color: '#B91C1C', profile: [35, 29, 62, 48, 7, 31, 9] },
{ name: 'Forge', color: '#0F766E', profile: [52, 47, 36, 21, 33, 16, 12] },
{ name: 'Harbor', color: '#A16207', profile: [46, 55, 42, 19, 11, 27, 18] },
{ name: 'Ivy', color: '#475569', profile: [61, 33, 28, 39, 15, 22, 7] },
];
private rand: any = this.mulberry32(20260821);
private teamSeries: any = this.TEAMS.map(function (t) {
return {
name: 'Weekly use',
team: t.name,
data: this.TASKS.map(function (task, ti) {
// A little jitter around the profile, clamped to the shared 0-70 frame.
var v = t.profile[ti] * (0.92 + this.rand() * 0.16)
return { x: task, y: Math.min(70, Math.max(2, Math.round(v))) }
}),
}
});
private TEAM_COLORS: any = {};
public chartOptions: Partial<ChartOptions> = {
series: this.teamSeries,
chart: {
id: 'taskMixTrellis',
type: 'bar',
height: 620,
animations: {
enabled: false,
},
},
trellis: {
by: 'team',
columns: 4,
minPanelWidth: 200,
gap: 10,
panel: (key) => {
return { colors: [this.TEAM_COLORS[key] || '#475569'] }
},
},
plotOptions: {
bar: {
horizontal: true,
barHeight: '68%',
borderRadius: 2,
borderRadiusApplication: 'end',
},
},
xaxis: {
type: 'category',
labels: {
formatter: (val) => {
return Math.round(Number(val)) + '%'
},
},
},
dataLabels: {
enabled: false,
},
grid: {
xaxis: {
lines: {
show: true,
},
},
yaxis: {
lines: {
show: false,
},
},
},
};
ngAfterViewInit() {
(window as any).ApexCharts.setLicense('APEX-eyJleHBpcnlEYXRlIjoiMjEyNi0wNy0wNCIsImlzc3VlRGF0ZSI6IjIwMjYtMDctMjgiLCJwbGFuIjoicHJlbWl1bSIsImRvbWFpbnMiOlsiYXBleGNoYXJ0cy5jb20iLCIxMjcuMC4wLjEiLCJsb2NhbGhvc3QiXSwic2lnIjoieVBmb1VCc0Z3TU9ZdUEyaEZkR0I2Y1FtZ0JITUtXcVdJSjB2NVRESXRZbFR3eDJMUmh6R2x0RUc3VXJ4X0s3b25ZMWRZb2Z2VGItN01ydFYyNDVyOWcifQ==');
this.TEAMS.forEach(function (t) {
this.TEAM_COLORS[t.name] = t.color
})
}
ngOnDestroy() {
// no cleanup needed
}
}