Change mouse cursor on chart.js doughnut chart - Javascript Chart.js

Javascript examples for Chart.js:Doughnut Chart

Description

Change mouse cursor on chart.js doughnut chart

Demo Code

ResultView the demo in separate window

<html>
   <head> 
      <title>Change cursor in chartjs</title> 
      <meta name="viewport" content="width=device-width, initial-scale=1"> 
      <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.4.0/Chart.js"></script> 
      <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script> 
      <script type="text/javascript">
    window.onload=function(){//ww  w . ja va  2s . c o m
var ctx = document.getElementById("canvas1").getContext("2d");
var mychart = new Chart(ctx, {
  type: 'doughnut',
  data: {
    labels: ['uno', 'dos', 'tres', 'cuatro'],
    datasets: [{
      data: [1, 2, 3, 4],
      backgroundColor: ["#BDC3C7","#9B59B6","#E74C3C","#26B99A"]
    }]
  },
  options: {
    hover: {
      onHover: function(e) {
        $("#canvas1").css("cursor", e[0] ? "pointer" : "default");
      }
    }
  }
});
    }

      </script> 
   </head> 
   <body> 
      <canvas id="canvas1" height="150"></canvas>  
   </body>
</html>

Related Tutorials