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