首页 > 解决方案 > ChartJs 注释不适用于 Tooltip

问题描述

我有一个要求,在悬停时我需要显示一条水平线,如下面的小提琴。但是一旦绘制悬停水平线,工具提示就会消失。任何人都可以帮助我如何获得工具提示和水平线。

请注意,在下面的小提琴中,我们在悬停时遇到问题,这需要时间,但在我的实际项目中,悬停工作正常,我只是遇到悬停后工具提示在一段时间后不起作用的问题。 https://jsfiddle.net/h8ow63be/

var option = {
  legend: false,
  title: {
    display: true,
  },
  onHover: function(evt) {
    var item = myLineChart.getElementAtEvent(evt);
    if (item.length) {
     updateChart(data.datasets[0].data[item[0]._index].y)
    }
  },
  animation: {
                duration: 0
            },
  annotation: {
   annotations: lines
  },
  scales: {
    xAxes: [{
      id: 'x-axis',
      type: 'linear',
      position: 'bottom',
      ticks: {
        max: 12,
        min: 1,
        stepSize: 1
      }
    }],
    yAxes: [{
      id: 'y-axis',
      type: 'linear',
    }],
  }

};

标签: chart.js

解决方案


推荐阅读