如何在悬停的甜甜圈chartjs中缩放扇区?

时间:2020-04-30 09:14:57

标签: chart.js

如何在悬停的甜甜圈chartjs中缩放扇区? 例: enter image description here

1 个答案:

答案 0 :(得分:1)

最简单的解决方案是按如下方式在borderWidth上定义不同的hoverBorderWidthdataset

new Chart(document.getElementById('myChart'), {
  type: 'doughnut',
  data: {
    labels: ['red', 'green', 'gray', 'blue'],
    datasets: [{
      label: 'My First dataset',
      backgroundColor: ['red', 'green', 'gray', 'blue'],
      borderColor: 'white',
      data: [3, 4, 5, 3],
      borderWidth: 4,
      hoverBorderWidth: 0,
      borderAlign: 'center'
    }]
  },
  options: {
     responsive:true,
     cutoutPercentage: 65
  }
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.9.3/Chart.bundle.min.js"></script>
<canvas id="myChart"></canvas>