我无法在 Chartjs 中配置插件 chartjs-plugin-annotation。
从文档中,我安装了 V 0.5.7,因为我使用的是 Chart.js V 2.9.4。
这是我的配置:
注册插件:
import Chart from "chart.js";
import annotationPlugin from "chartjs-plugin-annotation";
Chart.plugins.register(annotationPlugin);
//Chart.pluginService.register(annotationPlugin); //also tried this but doesn't work
这里是选项配置(简化),我也尝试在“插件”中包装“注释”,但它不起作用:
scales: {
yAxes: [
{
scaleLabel: {
...
},
ticks: {
...
},
gridLines: {
...
},
},
],
xAxes: [
{
gridLines: {
...
},
ticks: {
...
},
},
],
},
maintainAspectRatio: false,
legend: {
...
labels: {
...
},
},
tooltips: {
...
},
annotation: {
annotations: [
{
type: "line",
mode: "horizontal",
scaleID: "yAxes",
value: 2.62,
borderColor: "white",
borderWidth: 4,
},
],
},
hover: {
...
},
我究竟做错了什么?