我正在 Angular8 中做一个项目并使用 ChartJS 创建图表。运行项目后,它将显示图表。但它会给出一个错误说:
Property 'getContext' does not exist on type 'HTMLElement'.
Run Code Online (Sandbox Code Playgroud)
我如何摆脱这个错误?
这是我的代码:
图表.component.html
<div id="container" style="width:350px;height:250px">
<canvas id="myChart" width=300 height=300></canvas>
</div>
Run Code Online (Sandbox Code Playgroud)
图表组件.ts
import {Component, OnInit} from '@angular/core';
import {Chart} from 'chart.js';
import {ChartService} from '../charts/chart.service';
import {HttpClient} from '@angular/common/http';
// import {DATA} from '../CHART/CHARTS.MODEL';
@Component({
selector: 'app-charts',
templateUrl: './charts.component.html',
styleUrls: ['./charts.component.scss']
})
export class ChartsComponent implements OnInit {
constructor(
private ChartItems: ChartService,
private httpClient: HttpClient
) { }
ngOnInit() {
this.getChartDetails();
}
getChartDetails() {
this.ChartItems.getChart().subscribe(data => { …Run Code Online (Sandbox Code Playgroud)