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 lollipopData: any = [
{ x: 'Jan', y: 41 },
{ x: 'Feb', y: 58 },
{ x: 'Mar', y: 45 },
{ x: 'Apr', y: 72 },
{ x: 'May', y: 68 },
{ x: 'Jun', y: 91 },
{ x: 'Jul', y: 84 },
{ x: 'Aug', y: 63 },
{ x: 'Sep', y: 49 },
{ x: 'Oct', y: 77 },
{ x: 'Nov', y: 88 },
{ x: 'Dec', y: 102 },
];
public chartOptions: Partial<ChartOptions> = {
series: [{ name: 'Signups', data: this.lollipopData }],
chart: {
height: 440,
type: 'lollipop',
animations: { enabled: false },
toolbar: { show: false },
},
colors: ['#775DD0'],
grid: {
padding: { left: 12, right: 12 },
},
title: {
text: 'Monthly active signups',
align: 'left',
},
subtitle: {
text: 'A custom "lollipop" series type built with Marks (registerSeriesType)',
align: 'left',
},
xaxis: {
type: 'category',
tooltip: { enabled: false },
},
yaxis: {
min: 0,
max: 120,
tickAmount: 6,
},
};
ngAfterViewInit() {
(window as any).ApexCharts.setLicense('APEX-eyJleHBpcnlEYXRlIjoiMjEyNi0wNy0wNCIsImlzc3VlRGF0ZSI6IjIwMjYtMDctMjgiLCJwbGFuIjoicHJlbWl1bSIsImRvbWFpbnMiOlsiYXBleGNoYXJ0cy5jb20iLCIxMjcuMC4wLjEiLCJsb2NhbGhvc3QiXSwic2lnIjoieVBmb1VCc0Z3TU9ZdUEyaEZkR0I2Y1FtZ0JITUtXcVdJSjB2NVRESXRZbFR3eDJMUmh6R2x0RUc3VXJ4X0s3b25ZMWRZb2Z2VGItN01ydFYyNDVyOWcifQ==');
ApexCharts.registerSeriesType('lollipop', {
renderItem: (ctx) => {
var x = ctx.x
var y = ctx.y
var scales = ctx.scales
var api = ctx.api
var color = ctx.color
var baseline = scales.y(0)
api.line({ x1: x, y1: baseline, x2: x, y2: y, stroke: color, width: 2 })
api.circle({ cx: x, cy: y, r: 6, fill: color })
},
})
}
ngOnDestroy() {
// no cleanup needed
}
}