Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to to change mouse cursor on chart.js doughnut graph?

When using the Chart.js library, I want to change cursor when hovering the mouse over the doughnut.

I do this :

$("#dc_LoadTime").mouseleave(function(){
    $("#dc_LoadTime").css("cursor", "default");
}); 
$("#dc_LoadTime").mouseenter(function(){
    $("#dc_LoadTime").css("cursor", "pointer");
});

With this in html page

<canvas id="dc_LoadTime"></canvas>

But this change cursor when mouse enter or leave canvas not on doughnut chart. I cannot find a way to do this. Does anybody know if this is possible?

like image 329
LeMoussel Avatar asked Feb 22 '16 08:02

LeMoussel


People also ask

How do I change my cursor to a selector?

Change your mouse cursor natively in Windows 10Step 1: Click on the Search box located in the taskbar. Step 2: Type in "mouse." Step 3: Select Change your mouse settings from the resulting list of options to open the primary mouse settings menu. Step 4: Select Additional mouse options.

What is cursor property in Javascript?

The cursor property sets or returns the type of cursor to display for the mouse pointer.


1 Answers

In chartjs 2.0 < 2.5 I use hover in option section of the chart, like this:

options: {
  hover: {
    onHover: function(e) {
      $("#id-of-your-canvas").css("cursor", e[0] ? "pointer" : "default");
    }
  }
}

...and here is a complete example: https://jsfiddle.net/su5fgb5h/5/

In version 2.5 onhover callback has changed and we need second parameter to change cursor:

options: {
  hover: {
    onHover: function(e, el) {
      $("#id-of-your-canvas").css("cursor", el[0] ? "pointer" : "default");
    }
  }
}
like image 170
birrein Avatar answered Sep 28 '22 04:09

birrein