0

I am working on a project using chart.js for work and I need to know if there is a way to add some space between datasets of a pie chart.

What I have so far is in the chart depicted below, and I want there to be some padding between the inner and outer datasets.

I have tried setting one of the charts to a doughnut type or adding a thicker outer border on the inner chart, and neither of those are what I needed.

enter image description here

Xyloking17
  • 83
  • 1
  • 5

1 Answers1

2

You can obtain the desired result by adding an empty dataset between the two existing ones and defining a weight property on the empty and the inner dataset.

const colors = ["#FF6384", "#36A2EB", "#FFCE56"];
var pieChart = new Chart("myChart", {
  type: 'pie',
  data: {
    labels: ["Red", "Blue", "Yellow"],
    datasets: [{      
      data: [8, 5, 6],
      backgroundColor: colors,
    }, 
    { 
      weight: 0.2
    },
    { 
      data: [5, 7, 4],
      backgroundColor: colors,
      weight: 1.2
    }]
  }
})
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.9.3/Chart.min.js"></script>
<canvas id="myChart"></canvas>
uminder
  • 23,831
  • 5
  • 37
  • 72