ChartJS 获取所有注解的列表

z3yyvxxp  于 2023-01-05  发布在  Chart.js
关注(0)|答案(1)|浏览(132)

当鼠标悬停在这些点上时,我尝试切换一个注解的可见性(display: true/false)。
我从定义onHover交互开始

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

现在,我被困在获取所有已定义注解的列表上。
浏览时发现this issue是关于注解的,假设myLine对应chart,本以为会得到第一个带chart.options.annotation.annotations[0]的注解,但是chart.options.annotation没有定义。
我是否遗漏了什么?是否可以通过编程方式获得被拒绝注解的列表?

pkwftd7m

pkwftd7m1#

您在options.plugins.annotation名称空间中配置注解,因此还需要从那里而不是从options.annotation检索注解。
因此,使用onHover将列出您的注解:

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

相关问题