Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Chart.js tooltips callback function with pie charts

In a chart options configurations I can make my own label. This is for a bar chart:

tooltips: {
      callbacks: {
        label: function(tooltipItem) {
          var label = tooltipItem.yLabel;
          return  'Scans : ' + label;
        }
      }
    }

But for a pie chart all the tooltipItems are empty or 0 values. What argument can i use to get only the value of where i am hovering in my pie chart? (The value of that specific slice)

like image 713
Daniel Avatar asked Jun 02 '16 10:06

Daniel


1 Answers

Try this:

tooltips: {
    mode: 'label',
    callbacks: {
        label: function(tooltipItem, data) { 
            var indice = tooltipItem.index;                 
            return  data.labels[indice] +': '+data.datasets[0].data[indice] + '';
        }
    }
},
like image 145
Miguel Varas Avatar answered Sep 20 '22 10:09

Miguel Varas