Closed jonathancounihan closed 5 years ago
Pull request #6 fixes this issue.
Fixes #6 , #5
sure @ciprianciurea, will do so. The basic one I can think of is when the legend is displayed and you toggle a segments visibility as shown here:
The relevant code, using the changes I made:
text: function() {
var total = cht.config.data.datasets[0]._meta[0].total;
return total;
},
Thanks @jonathancounihan , managed to update the samples in the meantime.
The code @jonathancounihan posted does not work here (chart.js 2.8.0). _meta[0]
is not defined. I had to use this: chart.data.datasets[0]._meta[Object.keys(theChart.data.datasets[0]._meta)[0]].total
My other problem with your example is that I have no access to cht
in this scope in my project. So I would like to do a PR which passes the chart object to the text()
function (similar to other Chart.js plugins).
You'll find my PR here: #11
As I had several trouble using the internal _meta
property you should not use this. As stated in https://github.com/chartjs/Chart.js/issues/4731#issuecomment-328279321 you should use getDatasetMeta () instead.
chart.getDatasetMeta(0).total
works nicely
Add the ability for the label text to be created via a function, to support dynamically changing text.
Olá boa noite
Add the ability for the label text to be created via a function, to support dynamically changing text.