angular - 带有 Angular 组件的 Chart.js - 类型“字符串”不可分配给类型“ChartTitleOptions | 不明确的'
问题描述
我正在尝试使用 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
}
}]
}
});
}
}
解决方案
title 属性不接受选项的字符串。相反,它需要一个对象,您可以在其中配置有关标题的内容,包括字符串。所以你的配置看起来像这样:
options: {
title:{
display: true,
text: 'TitleText to display'
}
}
文档:https ://www.chartjs.org/docs/2.9.4/configuration/title.html
推荐阅读
- javascript - 如何在多个 div 中生成相同的元素?
- node.js - ffmpeg:实例中视频未开始流式传输
- c++ - 在两个重复字符之间递归插入“22”
- c - arm-gcc-8.2.0 不知道怎么解决无返回值问题
- android - 尝试从 Firebase 获取纬度和经度数据
- java - 当 target == list[mid] 时,二分搜索在 while 循环的第一次迭代中不返回 true
- flutter - 如何在 Flutter 中使屏幕可滚动?
- avaudiosession - AVSpeechSynthesizer 忽略 iOS 13 上的静音开关
- r - 来自 lodown 包的 SCF 数据问题
- json - 查找json数组中字符串的长度是否超过一定的限制