app.module.ts
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { NgApexchartsModule } from 'ng-apexcharts';
import { AppRoutingModule } from './app-routing.module';
import { AppComponent } from './app.component';
@NgModule({
declarations: [
AppComponent
],
imports: [
BrowserModule,
AppRoutingModule,
NgApexchartsModule
],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule { }
app.component.ts
import { Component, OnInit, ViewChild } from '@angular/core';
import * as ApexCharts from 'apexcharts';
import {
ApexAxisChartSeries,
ApexChart,
ChartComponent,
ApexDataLabels,
ApexXAxis,
ApexPlotOptions,
ApexStroke,
ApexTitleSubtitle,
ApexYAxis,
ApexTooltip,
ApexFill,
ApexLegend
} from "ng-apexcharts";
export type ChartOptions = {
series: ApexAxisChartSeries;
chart: ApexChart;
dataLabels: ApexDataLabels;
plotOptions: ApexPlotOptions;
xaxis: ApexXAxis;
yaxis: ApexYAxis;
stroke: ApexStroke;
title: ApexTitleSubtitle;
tooltip: ApexTooltip;
fill: ApexFill;
legend: ApexLegend;
};
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent {
@ViewChild("chart")
chart!: ChartComponent;
public chartOptions: Partial<ChartOptions>;
constructor() {
this.chartOptions = {
series: [
{
name: "Marine Sprite",
data: [44, 55, 41, 37, 22, 43, 21]
},
{
name: "Striking Calf",
data: [53, 32, 33, 52, 13, 43, 32]
},
{
name: "Tank Picture",
data: [12, 17, 11, 9, 15, 11, 20]
},
{
name: "Bucket Slope",
data: [9, 7, 5, 8, 6, 9, 4]
},
{
name: "Reborn Kid",
data: [25, 12, 19, 32, 25, 24, 10]
}
],
chart: {
type: "bar",
height: 350,
stacked: true
},
plotOptions: {
bar: {
horizontal: true
}
},
stroke: {
width: 1,
colors: ["#fff"]
},
title: {
text: "Fiction Books Sales"
},
xaxis: {
categories: [2008, 2009, 2010, 2011, 2012, 2013, 2014],
labels: {
formatter: function(val) {
return val + "K";
}
}
},
yaxis: {
title: {
text: undefined
}
},
tooltip: {
y: {
formatter: function(val) {
return val + "K";
}
}
},
fill: {
opacity: 1
},
legend: {
position: "top",
horizontalAlign: "left",
offsetX: 40
}
};
}
}
app.component.html
<div id="chart">
<apx-chart
[series]="chartOptions.series"
[chart]="chartOptions.chart"
[dataLabels]="chartOptions.dataLabels"
[plotOptions]="chartOptions.plotOptions"
[xaxis]="chartOptions.xaxis"
[stroke]="chartOptions.stroke"
[fill]="chartOptions.fill"
[yaxis]="chartOptions.yaxis"
[title]="chartOptions.title"
[tooltip]="chartOptions.tooltip"
[legend]="chartOptions.legend"
></apx-chart>
</div>
Error: src/app/app.component.html:3:6 - error TS2322: Type 'ApexAxisChartSeries | undefined' is not assignable to type 'ApexAxisChartSeries | ApexNonAxisChartSeries'. Type 'undefined' is not assignable to type 'ApexAxisChartSeries | ApexNonAxisChartSeries'.
3 [series]="chartOptions.series" ~~~~~~
src/app/app.component.ts:34:16 34 templateUrl: './app.component.html', ~~~~~~~~~~~~~~~~~~~~~~ Error occurs in the template of component AppComponent.
Error: src/app/app.component.html:4:6 - error TS2322: Type 'ApexChart | undefined' is not assignable to type 'ApexChart'. Type 'undefined' is not assignable to type 'ApexChart'.
4 [chart]="chartOptions.chart" ~~~~~
src/app/app.component.ts:34:16 34 templateUrl: './app.component.html', ~~~~~~~~~~~~~~~~~~~~~~ Error occurs in the template of component AppComponent.
Error: src/app/app.component.html:5:6 - error TS2322: Type 'ApexDataLabels | undefined' is not assignable to type 'ApexDataLabels'. Type 'undefined' is not assignable to type 'ApexDataLabels'.
5 [dataLabels]="chartOptions.dataLabels" ~~~~~~~~~~
src/app/app.component.ts:34:16 34 templateUrl: './app.component.html', ~~~~~~~~~~~~~~~~~~~~~~ Error occurs in the template of component AppComponent.
Error: src/app/app.component.html:6:6 - error TS2322: Type 'ApexPlotOptions | undefined' is not assignable to type 'ApexPlotOptions'. Type 'undefined' is not assignable to type 'ApexPlotOptions'.
6 [plotOptions]="chartOptions.plotOptions" ~~~~~~~~~~~
src/app/app.component.ts:34:16 34 templateUrl: './app.component.html', ~~~~~~~~~~~~~~~~~~~~~~ Error occurs in the template of component AppComponent.
Error: src/app/app.component.html:7:6 - error TS2322: Type 'ApexXAxis | undefined' is not assignable to type 'ApexXAxis'. Type 'undefined' is not assignable to type 'ApexXAxis'.
7 [xaxis]="chartOptions.xaxis" ~~~~~
src/app/app.component.ts:34:16 34 templateUrl: './app.component.html', ~~~~~~~~~~~~~~~~~~~~~~ Error occurs in the template of component AppComponent.
Error: src/app/app.component.html:8:6 - error TS2322: Type 'ApexStroke | undefined' is not assignable to type 'ApexStroke'. Type 'undefined' is not assignable to type 'ApexStroke'.
8 [stroke]="chartOptions.stroke" ~~~~~~
src/app/app.component.ts:34:16 34 templateUrl: './app.component.html', ~~~~~~~~~~~~~~~~~~~~~~ Error occurs in the template of component AppComponent.
Error: src/app/app.component.html:9:6 - error TS2322: Type 'ApexFill | undefined' is not assignable to type 'ApexFill'. Type 'undefined' is not assignable to type 'ApexFill'.
9 [fill]="chartOptions.fill" ~~~~
src/app/app.component.ts:34:16 34 templateUrl: './app.component.html', ~~~~~~~~~~~~~~~~~~~~~~ Error occurs in the template of component AppComponent.
Error: src/app/app.component.html:10:6 - error TS2322: Type 'ApexYAxis | undefined' is not assignable to type 'ApexYAxis | ApexYAxis[]'.
Type 'undefined' is not assignable to type 'ApexYAxis | ApexYAxis[]'.
10 [yaxis]="chartOptions.yaxis" ~~~~~
src/app/app.component.ts:34:16 34 templateUrl: './app.component.html', ~~~~~~~~~~~~~~~~~~~~~~ Error occurs in the template of component AppComponent.
Error: src/app/app.component.html:11:6 - error TS2322: Type 'ApexTitleSubtitle | undefined' is not assignable to type 'ApexTitleSubtitle'.
Type 'undefined' is not assignable to type 'ApexTitleSubtitle'.
11 [title]="chartOptions.title" ~~~~~
src/app/app.component.ts:34:16 34 templateUrl: './app.component.html', ~~~~~~~~~~~~~~~~~~~~~~ Error occurs in the template of component AppComponent.
Error: src/app/app.component.html:12:6 - error TS2322: Type 'ApexTooltip | undefined' is not assignable to type 'ApexTooltip'. Type 'undefined' is not assignable to type 'ApexTooltip'.
12 [tooltip]="chartOptions.tooltip" ~~~~~~~
src/app/app.component.ts:34:16 34 templateUrl: './app.component.html', ~~~~~~~~~~~~~~~~~~~~~~ Error occurs in the template of component AppComponent.
Error: src/app/app.component.html:13:6 - error TS2322: mType 'ApexLegend | undefined' is not assignable to type 'ApexLegend'. Type 'undefined' is not assignable to type 'ApexLegend'.
13 [legend]="chartOptions.legend" ~~~~~~
src/app/app.component.ts:34:16 34 templateUrl: './app.component.html', ~~~~~~~~~~~~~~~~~~~~~~ Error occurs in the template of component AppComponent.