我想使用 chart.js 以角度显示图表。我第一次尝试实现网上的一个例子,编译过程中没有问题。这是我的 .ts 中的代码:
import { Component, OnInit } from '@angular/core';
import { Chart } from "chart.js";
@Component({
...
})
export class MyChartComponent implements OnInit {
constructor(){
}
ngOnInit(): void {
new Chart("myChart", {
type: 'bar',
data: {
labels: ['Red', 'Blue', 'Yellow', 'Green', 'Purple', 'Orange'],
datasets: [{
label: '# of Votes',
data: [12, 19, 3, 5, 2, 3],
backgroundColor: [
'rgba(255, 99, 132, 0.2)',
'rgba(54, 162, 235, 0.2)',
'rgba(255, 206, 86, 0.2)',
'rgba(75, 192, 192, 0.2)',
'rgba(153, 102, 255, …Run Code Online (Sandbox Code Playgroud)