Chartjs-Chart with tool tip values

1👍

you can use jtblin/angular-chart.js as the libraries in the sample are not showing percentage.

fiddle link

also added tooltip callback

  tooltips: {
    callbacks: {
      label: function(tooltipItem, data) {
        //get the concerned dataset
        var dataset = data.datasets[tooltipItem.datasetIndex];
        //calculate the total of this data set
        var total = dataset.data.reduce(function(previousValue, currentValue, currentIndex, array) {
          return previousValue + currentValue;
        });
        //get the current items value
        var currentValue = dataset.data[tooltipItem.index];
        //calculate the precentage based on the total and current item, also this does a rough rounding to give a whole number
        var precentage = Math.floor(((currentValue / total) * 100) + 0.5);

        return precentage + "%";
      }
    }
  }

Leave a comment