简体   繁体   中英

Showing total count for bar chart in c3js tooltip title

I have a bar chart similar to the one shown in this link .

I wanted to add two features to this bar chart

  1. Instead of numbers, I want the tooltip title to display the sum of the count displayed by the bars at the given cordinate.

  2. I wanted to display the % in the tooltip instead of the actual count.

Could someone please help me with this?

This can be done by configuring tooltip.format.title :

   tooltip: {
      format: {
        title: function (index) {
          return totals[index]
        }

and tooltip.format.value :

        value: function (value, ratio, id, index) {
          return d3.format("%")(value / totals[index])
        }
     }
  }

And as you can see above, you need to calculate total values of your data groups:

var totals = [390, 500, 500, 900, 550, 550]

See example .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM