Daniel
Daniel

Reputation: 93

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)

Upvotes: 7

Views: 17292

Answers (1)

Miguel Varas
Miguel Varas

Reputation: 321

Try this:

tooltips: {
    mode: 'label',
    callbacks: {
        label: function(tooltipItem, data) { 
            var indice = tooltipItem.index;                 
            return  data.labels[indice] +': '+data.datasets[0].data[indice] + '';
        }
    }
},

Upvotes: 22

Related Questions