[Chartjs]-How can I show percentages when hovering over my chart?

8👍

You can use tooltips callback in chart.js to change the tooltip suffix. Here is an example on how to add %. I hacked this together by doing some searches and finding other examples.

https://jsfiddle.net/nt50dzb7/

  options: {
    tooltips: {
      enabled: true,
      mode: 'single',
      callbacks: {
        label: function(tooltipItem, data) {
          var allData = data.datasets[tooltipItem.datasetIndex].data;
          var tooltipLabel = data.labels[tooltipItem.index];
          var tooltipData = allData[tooltipItem.index];
          return tooltipLabel + ": " + tooltipData + "%";
        }
      }
    }
  }
}

Leave a comment