gpt4 book ai didi

jquery - jqPlot 在饼图上显示百分比和值

转载 作者:行者123 更新时间:2023-12-03 22:30:02 25 4
gpt4 key购买 nike

我正在使用 jqPlot 和 jqplot.PieRenderer 来尝试显示饼图。我想在标签上显示值(百分比)。文档说您可以传递 dataLabel 标签类型数组 (source)但是,将 %d%% (百分比)和 %d (值)放入 dataLabelFormatString 选项中最终不会显示任何内容。

这里有什么想法吗?

{ 
seriesDefaults: {
renderer: jQuery.jqplot.PieRenderer,
rendererOptions: {
showDataLabels: true,
dataLabels: ['value', 'percent'],
dataLabelFormatString: "%d %d%%",
sliceMargin: 4,
fill: false
}
},
legend: { show:true, location: 'e' }
}

最佳答案

我对这些文档的阅读方式略有不同。它是选项“值”、“百分比”、“标签”或标签数组。不是一系列选项。要执行您想要的操作,您需要将数据标签创建为真正的标签数组。

例如:

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) + "%";}));

参见 fiddle 示例 here .

关于jquery - jqPlot 在饼图上显示百分比和值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11546501/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com