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: 'Profit',
type: 'column',
data: [5, 12, -8, 14, -3, 9, -2, 6],
},
{
name: 'Units Sold',
type: 'column',
data: [1.2, 2.1, 1.8, 2.7, 2.0, 2.4, 1.9, 2.6],
},
{
name: 'Index',
type: 'line',
data: [25, 27, 26, 29, 28, 29, 30, 30],
},
],
chart: {
height: 350,
type: 'line',
stacked: false,
},
stroke: {
width: [0, 0, 4],
},
title: {
text: 'Multiple Y-Axes With Aligned Zero',
align: 'left',
},
xaxis: {
categories: ['Q1', 'Q2', 'Q3', 'Q4', 'Q5', 'Q6', 'Q7', 'Q8'],
},
yaxis: [
{
seriesName: 'Profit',
alignZero: true,
axisTicks: { show: true },
axisBorder: { show: true, color: '#008FFB' },
labels: { style: { colors: '#008FFB' } },
title: { text: 'Profit (mixed +/-)', style: { color: '#008FFB' } },
},
{
seriesName: 'Units Sold',
alignZero: true,
opposite: true,
axisTicks: { show: true },
axisBorder: { show: true, color: '#00E396' },
labels: { style: { colors: '#00E396' } },
title: { text: 'Units (positive only)', style: { color: '#00E396' } },
},
{
seriesName: 'Index',
alignZero: true,
opposite: true,
axisTicks: { show: true },
axisBorder: { show: true, color: '#FEB019' },
labels: { style: { colors: '#FEB019' } },
title: { text: 'Index', style: { color: '#FEB019' } },
},
],
tooltip: { shared: true, intersect: false },
legend: { horizontalAlign: 'left' },
};
ngAfterViewInit() {
(window as any).ApexCharts.setLicense('APEX-eyJpc3N1ZURhdGUiOiIyMDI2LTA0LTE2IiwiZXhwaXJ5RGF0ZSI6IjIwNTItMDQtMTciLCJwbGFuIjoiZW50ZXJwcmlzZSIsImRvbWFpbnMiOlsiYXBleGNoYXJ0cy5jb20iLCIxMjcuMC4wLjEiXX0=');
}
ngOnDestroy() {
// no cleanup needed
}
}