Chart.js - how to disable everything on hover

后端 未结 6 1591
陌清茗
陌清茗 2021-02-01 15:30

How can I set the code that there will be no hover effects, hover options, (hover) links etc on chart?

I\'m using chart.js. Below is my code, where I set pie chart.

6条回答
  •  刺人心
    刺人心 (楼主)
    2021-02-01 16:23

    in order to remove all hover styles/tooltips from vanilla chart.js:

    var myChart = new Chart(canvas, {
      options: {
        tooltips: {enabled: false},
        hover: {mode: null},
      }
      ...
    })
    

    Chart.js is watching all mousemove events on the canvas within which it has instantiated your chart. Setting hover 'mode' to null seems to override all the ways the canvas looks for matching elements to assign activated :hover classes to.

    The tooltip event seems separate, so I had to use both lines to make the chart effectively static.

    Note, initial animations still work on a chart with these options.

    UPDATE: newest Chart.js has re-bundled the way hover is 'listened' for:

    var myChart = new Chart(canvas, {
      options: {
        events: []
      }
      ...
    })
    

    making the 'events' option an empty list (instead of ['click', 'hover', etc]) makes the chart 'blind'/static because it will be listening for no events.

提交回复
热议问题