2
votes

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.

  • {0} item name
  • {1} value
  • {2} percentage

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?

1
Have you checked the "Show Labels" checkbox in iReport?Lisa
Yes, This is what I get. link. For some reason iReport ignores the labelFormat="{0} ({2})ceochronos

1 Answers

4
votes

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>