Search code examples
javascriptd3.jsc3

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.


Solution

  • 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/