我有一个类似于 link 中显示的条形图.
我想向此条形图添加两个功能
我希望工具提示标题显示给定坐标处条形显示的计数总和,而不是数字。
我想在工具提示中显示 %,而不是实际计数。
有人可以帮我解决这个问题吗?
最佳答案
这可以通过配置 tooltip.format.title 来完成:
tooltip: {
format: {
title: function (index) {
return totals[index]
}
value: function (value, ratio, id, index) {
return d3.format("%")(value / totals[index])
}
}
}
正如您在上面看到的,您需要计算数据组的总值(value):
var totals = [390, 500, 500, 900, 550, 550]
参见example 。
关于javascript - 在c3js工具提示标题中显示条形图的总数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44889866/