score:3

Accepted answer

You can use closure in createDonatsChart functions. Set const as const originalData = [...data] and then you can access to data in afterLabel callback (as example):

tooltips: {
    callbacks: {
      afterLabel: function(tooltipItem, data) {
        const sexArray = originalData[tooltipItem['index']].sex
        const precent = sexArray.reduce((a, b) => a + b, 0) // your calculation here          
        return '(' + precent + '%)';
    }
  }
}

See example in playground: https://jsfiddle.net/denisstukalov/upw6asjm/63/#&togetherjs=3CN0LJDjbl


Related Query

More Query from same tag