我正在嘗試使用 Chart.js 在我的網站上實作一個聊天組件,但出現錯誤
“型別 'string' 不可分配給型別 'ChartTitleOptions | undefined'”
,是不是版本有問題?
import { Component, OnInit, Input, ViewChild } from '@angular/core';
import { Chart } from 'chart.js'
@Component({
selector: 'app-line-chart',
templateUrl: './line-chart.component.html',
styleUrls: ['./line-chart.component.css']
})
export class LineChartComponent implements OnInit {
@Input() stock!: string;
LineChart:any = []
constructor() { }
ngOnInit() {
this.LineChart = new Chart('linechart', {
type: 'line',
data: {
labels: ['jan', 'fev'],
datasets: [{
label: 'Number xxxxxx',
data: [1, 2],
fill: false,
lineTension: 0.3,
borderColor: 'red',
borderWidth: 1
}]
},
options: {
title: 'Line Chart',
display: true
},
scales: {
yAxes: [{
ticks: {
beginAtZero: true
}
}]
}
});
}
}
uj5u.com熱心網友回復:
title 屬性不接受選項字串。相反,它需要一個物件,您可以在其中配置有關標題的內容,包括字串。所以你的配置看起來像這樣:
options: {
title:{
display: true,
text: 'TitleText to display'
}
}
檔案:https : //www.chartjs.org/docs/2.9.4/configuration/title.html
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/334780.html
上一篇:錯誤型別錯誤:無法讀取SafeSubscriber.settingsService.create.subscribe.loading[as_next]處未定義的屬性“重置”
