AlexLarra
AlexLarra

Reputation: 881

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.

Upvotes: 6

Views: 2072

Answers (1)

potatopeelings
potatopeelings

Reputation: 41065

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/

Upvotes: 7

Related Questions