jqPlot显示饼图上的百分比和值

时间:2012-07-18 16:54:37

标签: jquery jqplot

我正在使用jqPlot和jqplot.PieRenderer来尝试显示饼图。在标签上,我想展示value (percent)。文档说您可以传递dataLabel一系列标签类型(source),但是%d%%(对于百分比)和%d(对于值){{1} }选项最终没有显示任何内容。

这里有什么想法吗?

dataLabelFormatString

2 个答案:

答案 0 :(得分:19)

我对这些文档的看法略有不同。这是选项'价值','百分比','标签'或一系列标签。不是一系列选项。要做你想做的事,你需要将你的数据标签创建为一个真正的标签阵列。

例如:

data = [
    ['Heavy Industry', 12],['Retail', 9], ['Light Industry', 14], 
    ['Out of home', 16],['Commuting', 7], ['Orientation', 9]
];

var total = 0;
$(data).map(function(){total += this[1];})

myLabels = $.makeArray($(data).map(function(){return this[1] + " " + Math.round(this[1]/total * 100) + "%";}));

参见示例小提琴here

答案 1 :(得分:0)

使用

 formatter: function(label, series){
                        return '<div style="font-size:14pt;text-align:center;padding:2px;color:white;">'+Math.round(series.percent)+"%<br/>" + series.data[0][1] +'</div>';
                    },
相关问题