user1746050
user1746050

Reputation: 2575

Displaying decimal places on primefaces pie chart

I would like to check how do I display decimals for primefaces ver 3.3 pie chart label?

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?

Upvotes: 2

Views: 7898

Answers (2)

Divyesh Kanzariya
Divyesh Kanzariya

Reputation: 3789

Define an extender function like:

function ext() {
    this.cfg.seriesDefaults.rendererOptions.dataLabelFormatString = '%#.4f';
    this.cfg.seriesDefaults.rendererOptions.dataLabelThreshold = 0;
}

in my case '%.4s%%' (PF 4.0) is not working so instead of I used'%#.4f' that work fine.

Upvotes: 0

Akos K
Akos K

Reputation: 7133

Define an extender function like:

function ext() {
    this.cfg.seriesDefaults.rendererOptions.dataLabelFormatString = '%.4s%%';
    this.cfg.seriesDefaults.rendererOptions.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.

Finally attach this extender function on your p:pieChart:

<p:pieChart id="sample" value="#{testClazz.pieModel}"
                extender="ext" showDataLabels="true"/>

Upvotes: 4

Related Questions