[Chartjs]-How to add an image to a slice of a donut chart in chart.js?

0👍

This can be done with chartjs-plugin-labels as follows:

var myChart = new Chart(document.getElementById('myChart'), {
  type: 'doughnut',
  data: {
    labels: ['A', 'B', 'C'],
    datasets: [{
      data: [11, 39, 20],
      backgroundColor: ['#ffb74d', '#4db6ac', '#bf360c']
    }]
  },
  options: {
    responsive: true,
    plugins: {
      labels: {
        render: 'image',
        images: [
          null, 
          null, 
          {
            src: 'https://i.stack.imgur.com/9EMtU.png',
            width: 20,
            height: 20
          }
        ]
      }
    }
  }
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.9.3/Chart.min.js"></script>
<script src="https://cdn.jsdelivr.net/gh/emn178/chartjs-plugin-labels/src/chartjs-plugin-labels.js"></script>
<canvas id="myChart" height="100"></canvas>

Leave a comment