简体   繁体   English

如何在chartjs甜甜圈图hover上更改cursor?

[英]How to change cursor on chartjs doughnut chart hover?

I have a doughnut chart created with chartjs.我有一个用 chartjs 创建的圆环图。 I want to chart the mouse cursor to "pointer" when I hover any of the doughnut sections.当我 hover 任何甜甜圈部分时,我想将鼠标 cursor 绘制为“指针”。 How do I do that?我怎么做? Here is my code这是我的代码

  <canvas id="myChart" width="50" height="40"></canvas>

<script src="https://cdn.jsdelivr.net/npm/chart.js@2.9.3/dist/Chart.min.js"></script>

<script type="text/javascript">
      
 
 const data2 = {
  labels: {{chart_labels|safe}},
  datasets: [{
    label: 'My First Dataset',
    data: {{chart_data|safe}},
    backgroundColor: [
      'rgb(54, 162, 235)',
      'rgb(255, 99, 132)',
    ],
    hoverOffset: 4
  }]
};
        var ctx = $("#myChart").get(0).getContext("2d");
              var myChart =   new Chart(ctx, {
                    type: 'doughnut', data: data2
                });
        </script>

You can give cursor:"pointer" to the canvas element.您可以将 cursor:"pointer" 指向 canvas 元素。 <canvas id="myChart" width="50" height="40" style="cursor: pointer;"></canvas>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM