Jump to content
We've recently updated our Privacy Statement, available here ×

How do i get the percentage of one Group total


santhi

Recommended Posts

  • Replies 4
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

If you use JR 1.2.0 or later and you want to display such a percentage, you can use the "Auto" evaluation type.

 

Assuming that you compute a field group total and want to show for each row the percentage out of the group total, you would do something like

Code:

<field name="foo" class="java.lang.Double"/>
<variable name="fooBarSum" class="java.lang.Doube" calculation="Sum" resetType="Group" resetGroup="Bar">
<variableExpression>$F{foo}</variableExpression>
</variable>
<group name="Bar">
..
</group>
<detail>
..
<textField evaluationTime="Auto" pattern="#.00">
..
<textFieldExpression class="java.lang.Double">new Double(100d * $F{foo}.doubleValue() / $V{fooBarSum}.doubleValue())</textFieldExpression>
</textField>
..
</detail>

 

If you use Groovy or enable Java 1.5 report compilation, you can simplify the text field expression to 100d * $F{foo} / $V{fooBarSum}.

 

You can take a look at the Jasper sample on [url=http://jasperforge.org/sf/wiki/do/viewPage/projects.jasperreports/wiki/Samples]this page if you want to see a report with percentage calculations.

 

HTH,

Lucian

Link to comment
Share on other sites

  • 3 weeks later...

If you go to http://sourceforge.net/project/showfiles.php?group_id=36382

, download the jasperreports-x.y.z-project package and extract it somewhere, you would find the JasperReports samples under demo/samples. The sample in the "jasper" directory contains percentage calculations. You can run it to see the percentage values and then check the JRXML (search for evaluationTime="Auto" to identify the percentage text elements).

 

HTH,

Lucian

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...