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 dumbbellData: any = [
{ x: 'Austin', y: [312, 498] },
{ x: 'Denver', y: [398, 545] },
{ x: 'Miami', y: [285, 610] },
{ x: 'Seattle', y: [512, 720] },
{ x: 'Boise', y: [255, 415] },
{ x: 'Raleigh', y: [268, 402] },
{ x: 'Phoenix', y: [295, 468] },
];
public chartOptions: Partial<ChartOptions> = {
series: [{ name: 'Price range', data: this.dumbbellData }],
chart: {
height: 440,
type: 'dumbbell',
animations: { enabled: false },
toolbar: { show: false },
},
grid: {
padding: { left: 15, right: 15 },
xaxis: { lines: { show: true } },
},
title: {
text: 'Median home price by city: 2019 vs 2024',
align: 'left',
},
subtitle: {
text: 'A custom "dumbbell" series type built with Marks (registerSeriesType)',
align: 'left',
},
xaxis: {
type: 'category',
tooltip: { enabled: false },
},
yaxis: {
min: 200,
tickAmount: 6,
labels: {
formatter: (val) => {
return '$' + Math.round(val) + 'k'
},
},
},
tooltip: {
y: {
formatter: (val) => {
return '$' + val + 'k'
},
},
},
};
ngAfterViewInit() {
(window as any).ApexCharts.setLicense('APEX-eyJleHBpcnlEYXRlIjoiMjEyNi0wNy0wNCIsImlzc3VlRGF0ZSI6IjIwMjYtMDctMjgiLCJwbGFuIjoicHJlbWl1bSIsImRvbWFpbnMiOlsiYXBleGNoYXJ0cy5jb20iLCIxMjcuMC4wLjEiLCJsb2NhbGhvc3QiXSwic2lnIjoieVBmb1VCc0Z3TU9ZdUEyaEZkR0I2Y1FtZ0JITUtXcVdJSjB2NVRESXRZbFR3eDJMUmh6R2x0RUc3VXJ4X0s3b25ZMWRZb2Z2VGItN01ydFYyNDVyOWcifQ==');
ApexCharts.registerSeriesType('dumbbell', {
dataType: 'rangeXY',
renderItem: (ctx) => {
var datum = ctx.datum
var x = ctx.x
var scales = ctx.scales
var api = ctx.api
var yStart = scales.y(datum.y[0])
var yEnd = scales.y(datum.y[1])
// connecting stem
api.line({
x1: x,
y1: yStart,
x2: x,
y2: yEnd,
stroke: '#d0d5dd',
width: 4,
lineCap: 'round',
})
// start marker (hollow ring) and end marker (filled)
api.circle({
cx: x,
cy: yStart,
r: 7,
fill: '#fff',
stroke: '#008FFB',
strokeWidth: 3,
})
api.circle({ cx: x, cy: yEnd, r: 7, fill: '#00B894' })
},
})
}
ngOnDestroy() {
// no cleanup needed
}
}