Chartjs-ChartJS: Show all tooltips with Total for Multi Pie chart

1👍

To see every label remove the tooltipItem.index

        var label = data.datasets[tooltipItem.datasetIndex].labels;

To list all the labels in the tool tip is straight forward.

var label = [];
    for (var j in labels) {
        var percentage = Math.round((values[j] / total) * 100);
        label.push (labels[j] + " : " + values[j].toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",") + ' (' + percentage + '%)');
    }       
    label.push("Total : " + totally)
    return label;

Label color is derived from the datasetIndex so the label background colour doesn’t propagate, you will have to create a custom tooltip or disable displayColors.

custom: function(tooltip) {
    tooltip.displayColors = false;
},

https://jsfiddle.net/drillep/xb4g19en/2/

0👍

The label variable in the label function needs an array index.

var label = data.datasets[tooltipItem.datasetIndex].labels[tooltipItem.index];

https://jsfiddle.net/drillep/40htzrdn/

Leave a comment