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 STORES: any = [
'Aurora',
'Brookfield',
'Cedar Park',
'Dunwoody',
'Eastvale',
'Fairfield',
'Glenview',
'Harborside',
'Ironwood',
'Junction',
'Kingsford',
'Lakeshore',
'Maplewood',
'Northgate',
'Oakhurst',
'Pinecrest',
'Quarry Bay',
'Riverton',
];
private rand: any = this.mulberry32(20260821);
private gaugeSeries: any = this.STORES.map(function (store) {
// Attainment 48..104%, a few clear laggards in the mix.
var v = Math.round(48 + this.rand() * 56)
return { name: 'Attainment', store: store, data: [Math.min(v, 100)] }
});
public chartOptions: Partial<ChartOptions> = {
series: this.gaugeSeries,
chart: {
id: 'gaugeTrellis',
type: 'radialBar',
height: 560,
animations: {
enabled: false,
},
},
trellis: {
by: 'store',
columns: 6,
minPanelWidth: 150,
gap: 8,
panel: (key, meta) => {
var s = this.gaugeSeries[meta.index]
var v = s && s.data[0] ? s.data[0] : 0
var color = v >= 85 ? '#15803D' : v >= 65 ? '#D97706' : '#DC2626'
return { colors: [color] }
},
},
plotOptions: {
radialBar: {
hollow: {
size: '54%',
},
track: {
background: '#E5E7EB',
},
dataLabels: {
name: {
show: false,
},
value: {
show: true,
offsetY: 6,
fontSize: '15px',
fontWeight: 700,
formatter: (val) => {
return Math.round(Number(val)) + '%'
},
},
},
},
},
stroke: {
lineCap: 'round',
},
labels: ['Attainment'],
};
ngAfterViewInit() {
(window as any).ApexCharts.setLicense('APEX-eyJleHBpcnlEYXRlIjoiMjEyNi0wNy0wNCIsImlzc3VlRGF0ZSI6IjIwMjYtMDctMjgiLCJwbGFuIjoicHJlbWl1bSIsImRvbWFpbnMiOlsiYXBleGNoYXJ0cy5jb20iLCIxMjcuMC4wLjEiLCJsb2NhbGhvc3QiXSwic2lnIjoieVBmb1VCc0Z3TU9ZdUEyaEZkR0I2Y1FtZ0JITUtXcVdJSjB2NVRESXRZbFR3eDJMUmh6R2x0RUc3VXJ4X0s3b25ZMWRZb2Z2VGItN01ydFYyNDVyOWcifQ==');
}
ngOnDestroy() {
// no cleanup needed
}
}