angular - 从@types/chartjs 切换到@types/chart.js
问题描述
我一直在使用以下软件包https://www.npmjs.com/package/@types/chartjs
,但现在已弃用。切换到https://www.npmjs.com/package/@types/chart.js
. 我收到以下错误。
paydate.component.ts(42,45): error TS2345: Argument of type '{ type: string; 数据:{标签:数字[];数据集:{填充:真;线张力:数字;pointRadiu...' 不可分配给“ChartConfiguration”类型的参数。属性“数据”的类型不兼容。输入'{标签:数字[]; 数据集:{填充:真;线张力:数字;点半径:数字;borderWidth...' 不可分配给类型 'ChartData'。属性“标签”的类型不兼容。类型 'number[]' 不能分配给类型 '(string | string[])[]'。类型 'number' 不可分配给类型 'string | 细绳[]'。
import * as Chart from 'chart.js';
const myChart = new Chart(this.ctx, {
type: 'line',
data: {
labels: labels,
datasets: [{
fill: true,
lineTension: 0.5,
pointRadius: 0, // Removes indiviual points/tooltips
borderWidth: 1,
label: 'Monthly Spending',
data: data,
backgroundColor: 'rgb(124,190,235,0.6)',
borderColor: 'rgb(63,81,181)'
}]
},
options: {
plugins: {
datalabels: {
display: false,
}
},
legend: {
display: false
},
annotation: {
annotations: [
{
type: 'line',
mode: 'vertical',
scaleID: 'x-axis-0',
value: payday,
borderColor: 'red',
borderWidth: 2,
// label: {
// content: 'TODAY',
// enabled: true,
// position: 'top'
// }
}
]
}
}
});
这里有什么问题?
更新:
将标签更改为字符串后,我得到了。
ERROR in src/app/reports/components/paydate/paydate.component.ts(69,17): error TS2345: Argument of type '{ type: string; data: { labels: string[]; datasets: { fill: true; lineTension: number; pointRadiu...' is not assignable to parameter of type 'ChartConfiguration'.
Types of property 'options' are incompatible.
Type '{ plugins: { datalabels: { display: boolean; }; }; legend: { display: false; }; annotation: { ann...' is not assignable to type 'ChartOptions'.
Object literal may only specify known properties, but 'annotation' does not exist in type 'ChartOptions'. Did you mean to write 'rotation'?
解决方案
推荐阅读
- angular - 如何显示填充了对象离子角度的数组中的数据
- javascript - Firebase 实时数据库查询导致数据库不可用
- elasticsearch - 如何从 AWS Elastic 搜索服务中删除索引?
- aws-amplify - 在哪里使用 AWS Amplify/AppSync 编写业务逻辑
- python - Mailchimp 嵌入式表单集成到 Django 应用程序错误
- reactjs - TypeError: Object(...) is not a function React with Redux
- reverse-proxy - 使用 Traefik,如何根据请求的主机重写路径?
- python - 创建虚拟环境后无法运行程序
- python - 如何通过 Gabor 过滤器对人的衣服进行分类?
- python - Python进程运行时防止Linux休眠