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 SERVICES: any = [
{ name: 'gateway', seed: 3, base: 120 },
{ name: 'auth', seed: 11, base: 85 },
{ name: 'catalog', seed: 19, base: 140 },
{ name: 'search', seed: 27, base: 210 },
{ name: 'cart', seed: 35, base: 95 },
{ name: 'checkout', seed: 43, base: 150 },
{ name: 'payments', seed: 51, base: 180 },
{ name: 'shipping', seed: 59, base: 110 },
{ name: 'notifications', seed: 67, base: 70 },
];
private latency = (seed: any, base: any, degradeFrom: any): any => {
var rand = this.mulberry32(seed)
var out = []
var ts = new Date('01 Jan 2025').getTime()
var val = base
for (var i = 0; i < 72; i++) {
val = Math.max(40, val + (rand() - 0.5) * base * 0.1)
var v = val
// checkout degrades in steps after hour 40: the shape you promote to see.
if (degradeFrom && i >= degradeFrom) {
v = val + Math.min(320, (i - degradeFrom) * 14)
}
out.push([ts, Math.round(v)])
ts += 3600000 // hourly
}
return out
};
private latencySeries: any = this.SERVICES.map(function (s) {
return {
name: 'p99 latency',
service: s.name,
data: this.latency(s.seed, s.base, s.name === 'checkout' ? 40 : 0),
}
});
public chartOptions: Partial<ChartOptions> = {
series: this.latencySeries,
chart: {
id: 'latencyTrellis',
type: 'line',
animations: {
enabled: false,
},
},
trellis: {
by: 'service',
minPanelWidth: 250,
panelHeight: 140,
gap: 12,
},
colors: ['#0891B2'],
stroke: {
width: 2,
curve: 'straight',
},
xaxis: {
type: 'datetime',
},
yaxis: {
labels: {
formatter: (val) => {
return Math.round(val) + ' ms'
},
},
},
dataLabels: {
enabled: false,
},
tooltip: {
x: {
format: 'dd MMM HH:mm',
},
},
};
ngAfterViewInit() {
(window as any).ApexCharts.setLicense('APEX-eyJleHBpcnlEYXRlIjoiMjEyNi0wNy0wNCIsImlzc3VlRGF0ZSI6IjIwMjYtMDctMjgiLCJwbGFuIjoicHJlbWl1bSIsImRvbWFpbnMiOlsiYXBleGNoYXJ0cy5jb20iLCIxMjcuMC4wLjEiLCJsb2NhbGhvc3QiXSwic2lnIjoieVBmb1VCc0Z3TU9ZdUEyaEZkR0I2Y1FtZ0JITUtXcVdJSjB2NVRESXRZbFR3eDJMUmh6R2x0RUc3VXJ4X0s3b25ZMWRZb2Z2VGItN01ydFYyNDVyOWcifQ==');
}
ngOnDestroy() {
// no cleanup needed
}
}