Chartjs-Multiple Chart JS percentage labels

0👍

I was able to solve this by using the following formula:

          afterLabel : function(tooltipItem, data) {
              var allData = data.datasets[tooltipItem.datasetIndex].data;
              var tooltipData = allData[tooltipItem.index];
              var total = 0;
              for (var i=0; i<allData.length; i++) {
                  total += allData[i];
              }
              var tooltipPercentage = Math.round((tooltipData / total) * 100);
              return tooltipPercentage + '%';
          },              

It’s not a global formula but it works on each chart I add to the page.

Leave a comment