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 signal = (): any => {
var out = []
for (var i = 0; i < 40; i++) {
var v = 50 + 22 * Math.sin(i / 4.0) + 9 * Math.sin(i / 1.4) + i * 0.4
out.push([i, Math.round(v)])
}
return out
};
private readout: any = document.getElementById('ink-readout');
public chartOptions: Partial<ChartOptions> = {
series: [{ name: 'Signal', data: this.signal() }],
chart: {
id: 'signal',
type: 'line',
height: 380,
fontFamily: 'Helvetica, Arial, sans-serif',
animations: { enabled: false },
ink: { enabled: true, palette: true },
history: { enabled: true },
toolbar: { show: false },
zoom: { enabled: false },
},
stroke: { width: 2, curve: 'smooth' },
colors: ['#0EA5E9'],
title: { text: 'Signal (drag the callouts)', align: 'left' },
xaxis: { type: 'numeric', title: { text: 'Sample' } },
yaxis: { title: { text: 'Value' } },
annotations: {
points: [
{
x: 6,
y: 74,
id: 'peak',
marker: {
size: 7,
fillColor: '#fff',
strokeColor: '#0EA5E9',
strokeWidth: 3,
},
label: {
text: 'Peak',
borderColor: '#0EA5E9',
style: { color: '#fff', background: '#0EA5E9' },
},
},
{
x: 20,
y: 52,
id: 'dip',
marker: {
size: 7,
fillColor: '#fff',
strokeColor: '#ef4444',
strokeWidth: 3,
},
label: {
text: 'Watch',
borderColor: '#ef4444',
style: { color: '#fff', background: '#ef4444' },
},
},
],
xaxis: [
{
x: 10,
x2: 16,
id: 'window',
fillColor: '#7DD3FC',
opacity: 0.28,
label: {
text: 'Window',
style: { color: '#fff', background: '#0EA5E9' },
},
},
],
yaxis: [
{
y: 62,
id: 'target',
borderColor: '#f59e0b',
strokeDashArray: 4,
label: {
text: 'Target',
style: { color: '#fff', background: '#f59e0b' },
},
},
],
},
};
ngAfterViewInit() {
(window as any).ApexCharts.setLicense('APEX-eyJleHBpcnlEYXRlIjoiMjEyNi0wNy0wNCIsImlzc3VlRGF0ZSI6IjIwMjYtMDctMjgiLCJwbGFuIjoicHJlbWl1bSIsImRvbWFpbnMiOlsiYXBleGNoYXJ0cy5jb20iLCIxMjcuMC4wLjEiLCJsb2NhbGhvc3QiXSwic2lnIjoieVBmb1VCc0Z3TU9ZdUEyaEZkR0I2Y1FtZ0JITUtXcVdJSjB2NVRESXRZbFR3eDJMUmh6R2x0RUc3VXJ4X0s3b25ZMWRZb2Z2VGItN01ydFYyNDVyOWcifQ==');
this.chart.addEventListener('annotationDragged', (c, o) => {
this.readout.textContent =
"Moved '" +
o.id +
"' to x=" +
Number(o.x).toFixed(2) +
', y=' +
Number(o.y).toFixed(2)
})
this.chart.addEventListener('annotationStyled', (c, o) => {
this.readout.textContent = "Restyled '" + o.id + "'"
})
this.chart.addEventListener('annotationDeleted', (c, o) => {
this.readout.textContent = "Deleted '" + o.id + "' (Ctrl/Cmd+Z restores it)"
})
}
ngOnDestroy() {
// no cleanup needed
}
}