我正在使用 http://github.com/krzysu/flot.tooltip .它显示数据的百分比如下。但我需要显示实际值而不是百分比。我该怎么做?
Json 数据
[{"data":350,"label":"Transport"},{"data":250,"label":"Meals"},{"data":250,"label":"Kitchen"},{"data":7280.5,"label":"Construction"},{"data":3725,"label":"Fuel"},{"data":160,"label":"Stationary"}]
脚本
function make_chart() {
$.ajax({
cache : 'false',
type : 'GET',
dataType : 'json',
url : "piechart",
success : function(json) {
var plotObj = $.plot($("#flot-pie-chart"), json, {
series: {
pie: {
show: true
}
},
grid: {
hoverable: true
},
tooltip: true,
tooltipOpts: {
content: "%p.0%, %s", // show percentages, rounding to 2 decimal places
shifts: {
x: 20,
y: 0
},
defaultTheme: false
}
});
}
});
}
最佳答案
只需修改tooltipOpts:content
属性;将 %p
替换为 %y
:
tooltipOpts: {
content: "%y.0, %s", // show value to 0 decimals
shifts: {
x: 20,
y: 0
},
defaultTheme: false
}
fiddle here .
或者使用函数以获得更大的灵 active :
content: function(label,x,y){
return y+", "+label;
},
fiddle here .
关于javascript - 在 Flot 饼图中显示数据值而不是百分比,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24413003/