获取所有注释的列表



当悬停在点上时,我试图切换一个注释的可见性(display: true/false)。

我从定义onHover相互作用

开始
options: {
plugins: {
annotation: {
annotations: {
one,
two,
three
},
},
},
onHover: (event, elements, chart) => {
if (elements[0]) {
// get the list of all annotations
}
}
},

现在,我被困在获取所有已定义注释的列表上。

在浏览时,我发现了这个关于注释的问题。假设myLine对应于chart,我期望获得chart.options.annotation.annotations[0]的第一个注释。但是,chart.options.annotation没有定义。

我在这里错过了什么吗?是否有可能以编程方式获得拒绝注释的列表?

您正在配置options.plugins.annotation命名空间中的注释,因此您还需要从那里而不是options.annotation检索它们。

所以使用onHover会列出你的注释:

onHover: (event, elements, chart) => {
console.log(chart.options.plugins.annotation.annotations)
}

最新更新