Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to show the total per column in tooltip title with c3.js?

toke it from c3 official page

In this case I would like to show 180 instead of 0 on tooltip title. I know that it can be customized like it is done in c3 official documentation. But I don't find the way to get the total per column.

like image 444
AlexLarra Avatar asked Jul 01 '15 11:07

AlexLarra


1 Answers

Just write your own tooltip contents function

tooltip: {
    contents: function (d, defaultTitleFormat, defaultValueFormat, color) {
        var sum = 0;
        d.forEach(function (e) {
            sum += e.value
        })
        defaultTitleFormat = function () {
            return sum
        };
        return c3.chart.internal.fn.getTooltipContent.apply(this, arguments);
    }
}

Fiddle - http://jsfiddle.net/x0b3w32e/

like image 74
potatopeelings Avatar answered Nov 15 '22 00:11

potatopeelings