4👍
✅
Yes! That’s absolutely possible.
Though you could create your own plugin but, I would suggest using a ChartJS plugin called Chart.PieceLabel.js
, which makes it much more easier to accomplish.
usage add the following in your chart options
pieceLabel: {
mode: 'value'
}
var randomScalingFactor = function() {
return Math.round(Math.random() * 100);
};
var ctx = document.getElementById("chart-area").getContext("2d");
var myDoughnut = new Chart(ctx, {
type: 'doughnut',
data: {
labels: ["January", "February", "March", "April", "May"],
datasets: [{
data: [
randomScalingFactor(),
randomScalingFactor(),
randomScalingFactor(),
randomScalingFactor(),
randomScalingFactor(),
],
backgroundColor: ['#ff3d67', '#ff9f40', '#ffcd56', '#4bc0c0', '#999999'],
borderColor: 'white',
borderWidth: 5,
}]
},
showDatapoints: true,
options: {
tooltips: {
enabled: false
},
pieceLabel: {
mode: 'value'
},
responsive: true,
legend: {
position: 'bottom',
},
title: {
display: true,
text: 'Idades',
fontSize: 20
},
animation: {
animateScale: true,
animateRotate: true
}
}
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.5.0/Chart.min.js"></script>
<script src="https://cdn.rawgit.com/emn178/Chart.PieceLabel.js/master/build/Chart.PieceLabel.min.js"></script>
<canvas id="chart-area"></canvas>
Source:stackexchange.com