ceochronos
ceochronos

Reputation: 350

How to show percentage in pie chart?

I am using iReport and JasperReports, both in v4.7.

I want to show the percentage of each slice in the label. Something like "Option 1 (45.67%)".

After reading many sites I came to the following snippet.

<piePlot labelFormat="{0} ({2})" legendLabelFormat="{0} ({2})">
    <plot/>
    <itemLabel/>
</piePlot>

According to the documentation of iReport.

However, when I run the report on iReport or JasperReports I get only the percentage in the legend area (legendLabelFormat) not in label (labelFormat) of each slice and, also, the percentage is show as an integer not as a float.

Somebody knows how to show the percentage in the label and -if possible- with decimal values?

Upvotes: 3

Views: 7108

Answers (1)

user3046497
user3046497

Reputation: 61

Found the solution here. Remove your lableExpression from the pieDataset, it overwrites your piePlot lables.

<pieDataset>
  <keyExpression><![CDATA[$F{GENERATION}]]></keyExpression>
  <valueExpression><![CDATA[$F{SUBTOTAL}]]></valueExpression>
</pieDataset>
<piePlot isShowLabels="false" isCircular="true" labelFormat="({2})" legendLabelFormat="{0}">
  <plot/>
  <itemLabel/>
</piePlot>

Upvotes: 6

Related Questions