mykola-digtiar / chartjs-plugin-piechart-outlabels

Highly customizable Chart.js plugin that displays labels outside the pie/doughnut chart.
https://piechart-outlabels.netlify.com/sample/
MIT License
51 stars 38 forks source link

Support for function type for the text option #10

Open json2d opened 5 years ago

json2d commented 5 years ago

I have a use case where I need to do some extra formatting to the text for the outlabel.

So for that I'm thinking it could be done with:

    var chart = new Chart('outlabeledChart', {
        type: 'outlabeledPie',
        data: {
            labels: [/* ... */],
            datasets: [/* ... */]
        },
        options: {
            plugins: {
                outlabels: {
                    text: (label, percentage, value) => myCustomFormatter(value),
                }
            }
        }
    });
srac1402 commented 3 years ago
outlabels: {
          text: function(label) {
          const v = parseFloat(label['percent']) * 100;
          return `${v.toFixed(2).replace('.', ',')}%`;
        },
}