Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

chartjs stacked bar show total

callbacks: {
    label: function(tooltipItem, data) {
        var corporation = data.datasets[tooltipItem.datasetIndex].label;
        var valor = data.datasets[tooltipItem.datasetIndex].data[tooltipItem.index];

        // Loop through all datasets to get the actual total of the index
        var total = 0;
        for (var i = 0; i < data.datasets.length; i++)
            total += data.datasets[i].data[tooltipItem.index];

        // If it is not the last dataset, you display it as you usually do
        if (tooltipItem.datasetIndex != data.datasets.length - 1) {
            return corporation + " : $" + valor.toFixed(2).replace(/(d)(?=(d{3})+.)/g, '$1,');
        } else { // .. else, you display the dataset and the total, using an array
            return [corporation + " : $" + valor.toFixed(2).replace(/(d)(?=(d{3})+.)/g, '$1,'), "Total : $" + total];
        }
    }
}
Comment

PREVIOUS NEXT
Code Example
Javascript :: JavaScript how to put value 
Javascript :: javascript dynamicly include another js file 
Javascript :: adding new sass version 
Javascript :: copy dict js 
Javascript :: integers to space separated string in javascript 
Javascript :: set background opacity react native 
Javascript :: react hook toggle state 
Javascript :: lodash pascal case 
Javascript :: js sort 1 or -1 
Javascript :: javascript every other element in array 
Javascript :: discord.js get username 
Javascript :: the update operation document must contain atomic operators mongodb 
Javascript :: flutter parse json 
Javascript :: express cors error 
Javascript :: disable submit button until checkbox is checked javascript 
Javascript :: load +main.js with system.import 
Javascript :: exec js 
Javascript :: tolowercase 
Javascript :: react native scrollview detect end 
Javascript :: store data in array jquery 
Javascript :: jquery capture tab 
Javascript :: javascript display 2 number after comma 
Javascript :: js sort array of objects 
Javascript :: js replace all 
Javascript :: how to make a rectangle in javascript 
Javascript :: electron main.js template 
Javascript :: classlist js 
Javascript :: concat array of objects javascript 
Javascript :: assign key and value to object 
Javascript :: getusermedia example 
ADD CONTENT
Topic
Content
Source link
Name
7+3 =