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;
public chartOptions: Partial<ChartOptions> = {
series: [
{
name: 'box',
type: 'boxPlot',
data: [
{
x: 'us-east',
y: [54, 66, 69, 75, 88],
goals: [
{
value: 32,
strokeWidth: 0,
strokeHeight: 13,
strokeLineCap: 'round',
strokeColor: '#FEB019',
},
],
},
{
x: 'us-west',
y: [43, 65, 69, 76, 81],
goals: [
{
value: 35,
strokeWidth: 0,
strokeHeight: 13,
strokeLineCap: 'round',
strokeColor: '#FEB019',
},
{
value: 95,
strokeWidth: 0,
strokeHeight: 13,
strokeLineCap: 'round',
strokeColor: '#FEB019',
},
],
},
{
x: 'eu-central',
y: [31, 39, 45, 51, 59],
goals: [
{
value: 64,
strokeWidth: 0,
strokeHeight: 13,
strokeLineCap: 'round',
strokeColor: '#FEB019',
},
{
value: 75,
strokeWidth: 0,
strokeHeight: 13,
strokeLineCap: 'round',
strokeColor: '#FEB019',
},
],
},
{
x: 'ap-south',
y: [39, 46, 55, 65, 71],
goals: [
{
value: 27,
strokeWidth: 0,
strokeHeight: 13,
strokeLineCap: 'round',
strokeColor: '#FEB019',
},
{
value: 77,
strokeWidth: 0,
strokeHeight: 13,
strokeLineCap: 'round',
strokeColor: '#FEB019',
},
],
},
{
x: 'sa-east',
y: [29, 31, 35, 39, 44],
goals: [
{
value: 10,
strokeWidth: 0,
strokeHeight: 13,
strokeLineCap: 'round',
strokeColor: '#FEB019',
},
{
value: 56,
strokeWidth: 0,
strokeHeight: 13,
strokeLineCap: 'round',
strokeColor: '#FEB019',
},
{
value: 62,
strokeWidth: 0,
strokeHeight: 13,
strokeLineCap: 'round',
strokeColor: '#FEB019',
},
{
value: 98,
strokeWidth: 0,
strokeHeight: 13,
strokeLineCap: 'round',
strokeColor: '#FEB019',
},
],
},
],
},
],
chart: {
type: 'boxPlot',
height: 350,
},
colors: ['#008FFB', '#FEB019'],
title: {
text: 'Request Latency by Region (ms)',
align: 'left',
},
xaxis: {
type: 'category',
},
};
ngAfterViewInit() {
(window as any).ApexCharts.setLicense('APEX-eyJpc3N1ZURhdGUiOiIyMDI2LTA0LTE2IiwiZXhwaXJ5RGF0ZSI6IjIwNTItMDQtMTciLCJwbGFuIjoiZW50ZXJwcmlzZSIsImRvbWFpbnMiOlsiYXBleGNoYXJ0cy5jb20iLCIxMjcuMC4wLjEiXX0=');
}
ngOnDestroy() {
// no cleanup needed
}
}