在素面饼图上显示小数位 [英] Displaying decimal places on primefaces pie chart
问题描述
我想检查如何在 3.3 版饼图标签中显示素数面的小数点?
I would like to check how do I display decimals for primefaces ver 3.3 pie chart label?
目前,我的图表中有两个比例.标签 A 和标签 B.标签 A 有一个非常大的数字,如 100000,但标签 B 有 100.因此,在饼图中,标签 A 不是 100%.但是,primefaces 将其转换为 100%,这是错误的.有什么方法可以在饼图上显示小数位而不是整数作为标签?
Currently, there are two proportions in my chart. Label A and Label B. Label A has a very big number like 100000 but label B has 100. Therefore, in the pie chart, Label A is not 100%. However, primefaces converts this to 100% which is wrong. Is there any way I can show the decimal places instead of whole numbers as labels on the pie chart?
推荐答案
定义一个扩展函数,如:
Define an extender function like:
function ext() {
this.cfg.seriesDefaults.rendererOptions.dataLabelFormatString = '%.4s%%';
this.cfg.seriesDefaults.rendererOptions.dataLabelThreshold = 0;
}
这将格式化您的输出标签以显示小数点后最多 4 位数字的百分比.jqPlot 默认情况下,对于小于 3% 的区域不会显示任何标签.您必须使用 dataLabelThreshold = 0
覆盖此值.
This will format your output labels to show percentage up to 4 digits after the decimal point. Also jqPlot by default, for areas smaller than 3% won't display any labels. You have to overwrite this value with dataLabelThreshold = 0
.
最后在你的 p:pieChart
上附加这个扩展函数:
Finally attach this extender function on your p:pieChart
:
<p:pieChart id="sample" value="#{testClazz.pieModel}"
extender="ext" showDataLabels="true"/>
这篇关于在素面饼图上显示小数位的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!