onHover event is not triggering in chart.js

前端 未结 1 862
难免孤独
难免孤独 2021-01-21 23:27

I want to change the cursor when the mouse moves on the chart, something like this fiddle. This works with chart.js v2.4 but not works with v2.6 &

1条回答
  •  栀梦
    栀梦 (楼主)
    2021-01-21 23:45

    From v2.5 onwards parameters of onHover callback has been changed. See PR#3669

    onHover callback now has 3 parameters. The 2nd parameter is the event that triggered the hover. This was done for consistency with the onClick callback.

    function(event, activeElements) {
    
    }
    

    Previously, activeEvents was the first argument, and event was not passed.

    You can check release notes of v2.5

    So you've to change your onHover callback as follows:

      onHover: function(event,elements) {
        $("#canvas1").css("cursor", elements[0] ? "pointer" : "default");
      }
    

    updated jsFiddle

    0 讨论(0)
提交回复
热议问题