How to show the total number of columns in a tooltip header using c3.js?

toke it from c3 official page

In this case, I would like to show 180 instead of 0 in the tooltip title. I know that it can be configured as it is done in the official c3 documentation . But I did not find a way to get the total number of columns.

+4
source share
1 answer

Just write your own tooltip content 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/

+6
source

All Articles