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: 'DIAMOND',
data: generateDayWiseTimeSeries(
new Date('01 Jun 2024 GMT').getTime(),
10,
{
min: 5,
max: 60,
},
),
},
{
name: 'TRIANGLE',
data: generateDayWiseTimeSeries(
new Date('01 Jun 2024 GMT').getTime(),
10,
{
min: 54,
max: 90,
},
),
},
{
name: 'CROSS',
data: generateDayWiseTimeSeries(
new Date('01 Jun 2024 GMT').getTime(),
8,
{
min: 10,
max: 50,
},
),
},
{
name: 'PLUS',
data: generateDayWiseTimeSeries(
new Date('01 Jun 2024 GMT').getTime(),
16,
{
min: 30,
max: 99,
},
),
},
{
name: 'SQUARE',
data: generateDayWiseTimeSeries(
new Date('01 Jun 2024 GMT').getTime(),
10,
{
min: 0,
max: 59,
},
),
},
{
name: 'LINE',
data: generateDayWiseTimeSeries(
new Date('01 Jun 2024 GMT').getTime(),
10,
{
min: 0,
max: 90,
},
),
},
{
name: 'CIRCLE',
data: generateDayWiseTimeSeries(
new Date('01 Jun 2024 GMT').getTime(),
10,
{
min: 5,
max: 35,
},
),
},
{
name: 'STAR',
data: generateDayWiseTimeSeries(
new Date('01 Jun 2024 GMT').getTime(),
10,
{
min: 15,
max: 60,
},
),
},
{
name: 'SPARKLE',
data: generateDayWiseTimeSeries(
new Date('01 Jun 2024 GMT').getTime(),
10,
{
min: 45,
max: 99,
},
),
},
],
chart: {
height: 350,
type: 'scatter',
zoom: {
type: 'xy',
},
},
colors: [
'#008FFB',
'#00E396',
'#FEB019',
'#FF4560',
'#775DD0',
'#546E7A',
'#26A69A',
'#D4526E',
'#F86624',
],
dataLabels: {
enabled: false,
},
grid: {
xaxis: {
lines: {
show: true,
},
},
yaxis: {
lines: {
show: true,
},
},
},
xaxis: {
type: 'datetime',
},
yaxis: {},
legend: {
markers: {
strokeWidth: [1, 1, 3, 3, 1, 4, 1, 1, 1],
},
},
markers: {
shape: [
'diamond',
'triangle',
'cross',
'plus',
'square',
'line',
'circle',
'star',
'sparkle',
],
size: 10,
fillOpacity: 0.8,
strokeColors: '#333',
strokeWidth: [1, 1, 3, 3, 1, 4, 1, 1, 1],
},
tooltip: {
shared: true,
intersect: false,
},
};
ngAfterViewInit() {
(window as any).ApexCharts.setLicense('APEX-eyJpc3N1ZURhdGUiOiIyMDI2LTA0LTE2IiwiZXhwaXJ5RGF0ZSI6IjIwNTItMDQtMTciLCJwbGFuIjoiZW50ZXJwcmlzZSIsImRvbWFpbnMiOlsiYXBleGNoYXJ0cy5jb20iLCIxMjcuMC4wLjEiXX0=');
}
ngOnDestroy() {
// no cleanup needed
}
}