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 salesSpark: any = [
31, 40, 33, 52, 46, 58, 49, 61, 55, 70, 64, 78, 72, 85, 79, 92, 88, 101, 96,
108, 104, 118, 112, 126,
];
private expensesSpark: any = [
28, 34, 30, 41, 37, 33, 45, 40, 52, 47, 43, 55, 50, 46, 58, 53, 49, 61, 56,
52, 64, 59, 55, 67,
];
private profitSpark: any = this.salesSpark.map(function (v, i) {
return v - this.expensesSpark[i]
});
public chartOptions: Partial<ChartOptions> = {
series: [
{
data: this.salesSpark,
},
],
chart: {
type: 'area',
height: 160,
sparkline: {
enabled: true,
},
},
stroke: {
curve: 'straight',
},
fill: {
opacity: 0.3,
},
yaxis: {
min: 0,
},
colors: ['#00E396'],
title: {
text: '$424,652',
offsetX: 0,
style: {
fontSize: '24px',
},
},
subtitle: {
text: 'Sales',
offsetX: 0,
style: {
fontSize: '14px',
},
},
};
public chartOptions2: Partial<ChartOptions> = {
series: [
{
data: this.expensesSpark,
},
],
chart: {
type: 'area',
height: 160,
sparkline: {
enabled: true,
},
},
stroke: {
curve: 'straight',
},
fill: {
opacity: 0.3,
},
yaxis: {
min: 0,
},
colors: ['#FF4560'],
title: {
text: '$235,312',
offsetX: 0,
style: {
fontSize: '24px',
},
},
subtitle: {
text: 'Expenses',
offsetX: 0,
style: {
fontSize: '14px',
},
},
};
public chartOptions3: Partial<ChartOptions> = {
series: [
{
data: this.profitSpark,
},
],
chart: {
type: 'area',
height: 160,
sparkline: {
enabled: true,
},
},
stroke: {
curve: 'straight',
},
fill: {
opacity: 0.3,
},
xaxis: {
crosshairs: {
width: 1,
},
},
yaxis: {
min: 0,
},
colors: ['#008FFB'],
title: {
text: '$189,340',
offsetX: 0,
style: {
fontSize: '24px',
},
},
subtitle: {
text: 'Profits',
offsetX: 0,
style: {
fontSize: '14px',
},
},
};
public chartOptions4: Partial<ChartOptions> = {
series: [
{
data: [25, 66, 41, 89, 63, 25, 44, 12, 36, 9, 54],
},
],
chart: {
type: 'line',
width: 100,
height: 35,
sparkline: {
enabled: true,
},
},
tooltip: {
fixed: {
enabled: false,
},
x: {
show: false,
},
y: {
title: {
formatter: (seriesName) => {
return ''
},
},
},
marker: {
show: false,
},
},
};
public chartOptions5: Partial<ChartOptions> = {
series: [
{
data: [12, 14, 2, 47, 42, 15, 47, 75, 65, 19, 14],
},
],
chart: {
type: 'line',
width: 100,
height: 35,
sparkline: {
enabled: true,
},
},
tooltip: {
fixed: {
enabled: false,
},
x: {
show: false,
},
y: {
title: {
formatter: (seriesName) => {
return ''
},
},
},
marker: {
show: false,
},
},
};
public chartOptions6: Partial<ChartOptions> = {
series: [43, 32, 12, 9],
chart: {
type: 'pie',
width: 40,
height: 40,
sparkline: {
enabled: true,
},
},
stroke: {
width: 1,
},
tooltip: {
fixed: {
enabled: false,
},
},
};
public chartOptions7: Partial<ChartOptions> = {
series: [43, 32, 12, 9],
chart: {
type: 'donut',
width: 40,
height: 40,
sparkline: {
enabled: true,
},
},
stroke: {
width: 1,
},
tooltip: {
fixed: {
enabled: false,
},
},
};
public chartOptions8: Partial<ChartOptions> = {
series: [
{
data: [25, 66, 41, 89, 63, 25, 44, 12, 36, 9, 54],
},
],
chart: {
type: 'bar',
width: 100,
height: 35,
sparkline: {
enabled: true,
},
},
plotOptions: {
bar: {
columnWidth: '80%',
},
},
labels: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11],
xaxis: {
crosshairs: {
width: 1,
},
},
tooltip: {
fixed: {
enabled: false,
},
x: {
show: false,
},
y: {
title: {
formatter: (seriesName) => {
return ''
},
},
},
marker: {
show: false,
},
},
};
public chartOptions9: Partial<ChartOptions> = {
series: [
{
data: [12, 14, 2, 47, 42, 15, 47, 75, 65, 19, 14],
},
],
chart: {
type: 'bar',
width: 100,
height: 35,
sparkline: {
enabled: true,
},
},
plotOptions: {
bar: {
columnWidth: '80%',
},
},
labels: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11],
xaxis: {
crosshairs: {
width: 1,
},
},
tooltip: {
fixed: {
enabled: false,
},
x: {
show: false,
},
y: {
title: {
formatter: (seriesName) => {
return ''
},
},
},
marker: {
show: false,
},
},
};
public chartOptions10: Partial<ChartOptions> = {
series: [45],
chart: {
type: 'radialBar',
width: 50,
height: 50,
sparkline: {
enabled: true,
},
},
dataLabels: {
enabled: false,
},
plotOptions: {
radialBar: {
hollow: {
margin: 0,
size: '50%',
},
track: {
margin: 0,
},
dataLabels: {
show: false,
},
},
},
};
public chartOptions11: Partial<ChartOptions> = {
series: [53, 67],
chart: {
type: 'radialBar',
width: 40,
height: 40,
sparkline: {
enabled: true,
},
},
dataLabels: {
enabled: false,
},
plotOptions: {
radialBar: {
hollow: {
margin: 0,
size: '50%',
},
track: {
margin: 1,
},
dataLabels: {
show: false,
},
},
},
};
ngAfterViewInit() {
(window as any).ApexCharts.setLicense('APEX-eyJleHBpcnlEYXRlIjoiMjEyNi0wNy0wNCIsImlzc3VlRGF0ZSI6IjIwMjYtMDctMjgiLCJwbGFuIjoicHJlbWl1bSIsImRvbWFpbnMiOlsiYXBleGNoYXJ0cy5jb20iLCIxMjcuMC4wLjEiLCJsb2NhbGhvc3QiXSwic2lnIjoieVBmb1VCc0Z3TU9ZdUEyaEZkR0I2Y1FtZ0JITUtXcVdJSjB2NVRESXRZbFR3eDJMUmh6R2x0RUc3VXJ4X0s3b25ZMWRZb2Z2VGItN01ydFYyNDVyOWcifQ==');
(window as any).Apex = {
stroke: {
width: 3,
},
markers: {
size: 0,
},
tooltip: {
fixed: {
enabled: true,
},
},
}
}
ngOnDestroy() {
// no cleanup needed
}
}