santhi Posted December 13, 2006 Share Posted December 13, 2006 Hi All, I have a problem with percentage in jasper reports. How do i get the percenate of particular group and a single record.. Thanks,Santhi Link to comment Share on other sites More sharing options...
lucianc Posted December 13, 2006 Share Posted December 13, 2006 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 likeCode:<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 More sharing options...
lucianc Posted December 13, 2006 Share Posted December 13, 2006 lucianc wrote:You can take a look at the Jasper sample on this page if you want to see a report with percentage calculations. Oops, apparently the sample present on the page is an old version that doesn't include percentage calculations. You should download the full JR distribution for the updated samples. Regards,Lucian Link to comment Share on other sites More sharing options...
santhi Posted December 19, 2006 Author Share Posted December 19, 2006 Hi lucianc, I have gone through that examples. But i am unable to find the percentage example. can u help in this.. Thanks in Advance.Santhi Link to comment Share on other sites More sharing options...
lucianc Posted January 3, 2007 Share Posted January 3, 2007 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 More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now