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 mulberry32 = (seed: any): any => {
return function () {
seed |= 0
seed = (seed + 0x6d2b79f5) | 0
var t = Math.imul(seed ^ (seed >>> 15), 1 | seed)
t = (t + Math.imul(t ^ (t >>> 7), 61 | t)) ^ t
return ((t ^ (t >>> 14)) >>> 0) / 4294967296
}
};
private ohlcWalk = (seed: any, start: any, vol: any): any => {
var rand = this.mulberry32(seed)
var r2 = function (v) {
return Math.round(v * 100) / 100
}
var out = []
var ts = new Date('01 Jan 2025').getTime()
var close = start
for (var i = 0; i < 40; i++) {
var open = close
close = Math.max(vol, open + (rand() - 0.48) * vol * 2)
var high = Math.max(open, close) + rand() * vol
var low = Math.max(vol * 0.2, Math.min(open, close) - rand() * vol)
out.push({ x: ts, y: [r2(open), r2(high), r2(low), r2(close)] })
ts += 86400000
}
return out
};
private TICKERS: any = [
{ ticker: 'ANVL', seed: 3, start: 24, vol: 0.9 },
{ ticker: 'BRCK', seed: 17, start: 61, vol: 2.1 },
{ ticker: 'CDER', seed: 29, start: 142, vol: 4.5 },
{ ticker: 'DELM', seed: 41, start: 310, vol: 9 },
{ ticker: 'ELMS', seed: 53, start: 78, vol: 2.6 },
{ ticker: 'FRST', seed: 67, start: 927, vol: 24 },
];
private stockSeries: any = this.TICKERS.map(function (t) {
return {
name: 'OHLC',
ticker: t.ticker,
data: this.ohlcWalk(t.seed, t.start, t.vol),
}
});
public chartOptions: Partial<ChartOptions> = {
series: this.stockSeries,
chart: {
id: 'stockTrellis',
type: 'candlestick',
height: 620,
animations: {
enabled: false,
},
},
trellis: {
by: 'ticker',
columns: 3,
gap: 14,
scales: {
y: 'independent',
},
},
xaxis: {
type: 'datetime',
},
yaxis: {
labels: {
formatter: (val) => {
return '$' + Math.round(val)
},
},
},
dataLabels: {
enabled: false,
},
tooltip: {
x: {
format: 'dd MMM',
},
},
};
ngAfterViewInit() {
(window as any).ApexCharts.setLicense('APEX-eyJleHBpcnlEYXRlIjoiMjEyNi0wNy0wNCIsImlzc3VlRGF0ZSI6IjIwMjYtMDctMjgiLCJwbGFuIjoicHJlbWl1bSIsImRvbWFpbnMiOlsiYXBleGNoYXJ0cy5jb20iLCIxMjcuMC4wLjEiLCJsb2NhbGhvc3QiXSwic2lnIjoieVBmb1VCc0Z3TU9ZdUEyaEZkR0I2Y1FtZ0JITUtXcVdJSjB2NVRESXRZbFR3eDJMUmh6R2x0RUc3VXJ4X0s3b25ZMWRZb2Z2VGItN01ydFYyNDVyOWcifQ==');
}
ngOnDestroy() {
// no cleanup needed
}
}