0👍
Okay, found the issue. I’ve already tried that but for some reasons that not worked, but now (maybe app.js was cached) that is what you have to do: you should pass ‘index’ property in ‘generatelabels’ like this:
legend_labels_options: {
display: true,
position: 'left',
onClick: function (e, legendItem) {
console.log(e, legendItem)
Chart.defaults.doughnut.legend.onClick.call(this, e, legendItem)
},
labels: {
generateLabels: chart => {
if (chart.data.datasets.length > 0) {
let options = {}
return chart.data.datasets[0].data.map((mapping, index) => {
options['fillStyle'] = chart.data.datasets[0].backgroundColor[index]
if (chart.canvas.id === 'group-hours-chart') {
options['text'] = this.minutesToHMS(mapping)
return options
}
options['text'] = chart.data.labels[index]
options['index'] = index
return options
})
}
}
}
}
Source:stackexchange.com