当悬停在点上时,我试图切换一个注释的可见性(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)
}