【发布时间】:2018-08-03 03:05:09
【问题描述】:
使用 chart.js 和插件 chartjs-plugin-annotation 时,使用 angular 5 时不显示注释,不显示错误消息。
我创建了一个显示问题的代码的精简示例
console.log(Chart.plugins) 显示插件看起来注册为插件 [3] 但它没有内置的 id,这是一个问题吗?
chart.component.ts
import { Component, Inject } from '@angular/core';
import { Chart } from 'chart.js';
import 'chartjs-plugin-annotation';
@Component({
selector: 'app-chart-component',
templateUrl: './chart.component.html'
})
export class ChartComponent {
public currentCount = 0;
chart : Chart ; // This will hold our chart info
simpleChart() {
console.log(Chart.plugins);
this.chart = new Chart('canvas', {
type: 'line',
data: {
labels: ['0','1','2', '3','4'],
datasets: [
{
data: [0,1,2,5,4,5],
borderColor: "#3cba9f",
fill: false,
},
]
},
options: {
legend: {
display: false
},
scales: {
xAxes: [{
display: true
}],
yAxes: [{
display: true,
id: 'y-axis-0'
},
]
},
plugins: {
annotation: {
annotations: [{
type: 'line',
id: 'hLine',
mode: 'horizontal',
scaleID: 'y-axis-0',
value: 2.5, // data-value at which the line is drawn
borderWidth: 2.5,
borderColor: 'black'
}]
}
}
}
});
}
ngOnInit() {
this.simpleChart();
}
}
任何帮助将不胜感激。
【问题讨论】: