0

This is my current doughnut chart and I want to show the values of each arc on the arc itself.

This is the configurations of the chart.

const genderConfig={
  plugins: {
    title: {
      display: true,
      text: "GENDER",
      font: {
        size: 20,
      },
    },
    legend: {
      labels: {
        boxHeight: 20,
        boxWidth: 25,
      },
      position: "bottom",
    },
  },
}

P.s. I know that there is a very similar question, I already tried the solution mentioned in that thread but I think that solution is not existing anymore to the current version of Chart.js.

Albert
  • 19
  • 4

1 Answers1

1

You can make use of the chart.js datalabels plugin, vor V3 they currently have a release candidate, there is 1 issue thats needs to be resolved before it can be released officially according to this issue of them: https://github.com/chartjs/chartjs-plugin-datalabels/discussions/213

V3 example:

Chart.register(ChartDataLabels)
var options = {
  type: 'pie',
  data: {
    labels: ["Red", "Blue", "Yellow", "Green", "Purple", "Orange"],
    datasets: [{
        label: '# of Votes',
        data: [12, 19, 3, 5, 2, 3],
        borderWidth: 1
      },
      {
        label: '# of Points',
        data: [7, 11, 5, 8, 3, 7],
        borderWidth: 1
      }
    ]
  },
  options: {}
}

var ctx = document.getElementById('chartJSContainer').getContext('2d');
new Chart(ctx, options);
<body>
  <canvas id="chartJSContainer" width="600" height="400"></canvas>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/3.2.1/chart.js"></script>
  <script src="https://cdn.jsdelivr.net/npm/chartjs-plugin-datalabels@2.0.0-rc/dist/chartjs-plugin-datalabels.min.js"></script>

</body>
LeeLenalee
  • 27,463
  • 6
  • 45
  • 69