ChartJS: Get Points Point Information

I successfully received the information using the function onClick. But is there any method I can get information about points on hovering above the point. Right now onHover, as mentioned in the docs, it doesn't work to get the point. This is my jsFiddle .

+4
source share
1 answer

In previous versions of Chart.js (e.g. 2.6), the onHover handler should be configured as follows:

  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 target data

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

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

+2

Source: https://habr.com/ru/post/1691993/


All Articles