在primefaces饼图上显示小数位 [英] 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"/>
这篇关于在primefaces饼图上显示小数位的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!