ChartJS: get points information on hovering the points

a 夏天 提交于 2020-02-03 04:38:05

问题


I have successfully got the information by onClick function. But is there any method i can get the point information on Hovering over the point. Right now onHover as mentioned in docs is not working to get the point. This is my jsFiddle.


回答1:


In previous versions of Chart.js (for example 2.6) the onHover handler has to be configured as below:

  hover: { 
     onHover: function(evt, item) { 
        if (item.length) {
            console.log("onHover", item, evt.type);
            console.log(">data", item[0]._index, data.datasets[0].data[item[0]._index]);
        }
     }
  },

itme[0]._index property points to data of target item

So your fiddle (chart.js 2.6) updated is: https://jsfiddle.net/beaver71/440L5661/

With chart.js 2.7: https://jsfiddle.net/beaver71/ttrak7sj/



来源:https://stackoverflow.com/questions/48191984/chartjs-get-points-information-on-hovering-the-points

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!