Chart.js 与 Angular 组件 - 类型 'string' 不可分配给类型 'ChartTitleOptions | undefined'
Chart.js with Angular component - Type 'string' is not assignable to type 'ChartTitleOptions | undefined'
我正在尝试使用 Chart.js 在我的网站上实施一个聊天组件,但我收到错误消息
"Type 'string' is not assignable to type '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
}
}]
}
});
}
}
标题属性不接受选项的字符串。相反,它需要一个 object ,您可以在其中配置有关标题的内容,包括字符串。
所以您的配置将如下所示:
options: {
title:{
display: true,
text: 'TitleText to display'
}
}
文档:https://www.chartjs.org/docs/2.9.4/configuration/title.html
我正在尝试使用 Chart.js 在我的网站上实施一个聊天组件,但我收到错误消息
"Type 'string' is not assignable to type '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
}
}]
}
});
}
}
标题属性不接受选项的字符串。相反,它需要一个 object ,您可以在其中配置有关标题的内容,包括字符串。 所以您的配置将如下所示:
options: {
title:{
display: true,
text: 'TitleText to display'
}
}
文档:https://www.chartjs.org/docs/2.9.4/configuration/title.html