gstephens Posted October 14, 2009 Share Posted October 14, 2009 Each row of a report has a category with a value. I'd like to display on each row, the percentage of the total that the value represents:CatA 10% 100CatB 78% 780CatC 12% 120Total 1,000I can't get the percentage field to calculate correctly. I've tried setting different evaluationTime's for the textfield. <variable name="cat_PCT" class="java.lang.Float" resetType="Group" resetGroup="cat_class"> <variableExpression><![CDATA[$V{cat_value}.doubleValue()/$V{total_cat}.doubleValue()]]></variableExpression> </variable> <variable name="total_cat" class="java.math.BigDecimal" calculation="Sum"> <variableExpression><![CDATA[$F{cat_value}.plus()]]></variableExpression> </variable><textField evaluationTime="Auto" pattern="#,##0.0 %"> <reportElement x="415" y="0" width="39" height="20"/> <textElement textAlignment="Right"/> <textFieldExpression class="java.lang.Float"><![CDATA[$V{cat_PCT}]]></textFieldExpression></textField><textField evaluationTime="Report"> <reportElement x="254" y="0" width="100" height="20"/> <textElement textAlignment="Right"/> <textFieldExpression class="java.math.BigDecimal"><![CDATA[$V{total_cat}]]></textFieldExpression></textField> Link to comment Share on other sites More sharing options...
jahp00 Posted October 15, 2009 Share Posted October 15, 2009 The First thing you must do it's create a variable that calculates the total, and later create a text field that divide the individual value of each category and total (in the variable you created) and set the evaluation time to auto. Link to comment Share on other sites More sharing options...
gstephens Posted October 17, 2009 Author Share Posted October 17, 2009 total_cat (show above) is a variable I created to calculate the total. cat_PCT is the variable where I divide the individual value into the category (however it's a float, not a string as you suggested). If I change it to a string I get an "error evaluating expression". Link to comment Share on other sites More sharing options...
gstephens Posted October 18, 2009 Author Share Posted October 18, 2009 I found an example of what jahp00 was referring to in the ShipmentsReport.jrxml sample included with iReport and it worked. Thanks.<textFieldExpression class="java.lang.String"><![CDATA[msg("{0,number,##0.0%}", new Float($V{cat_value}.floatValue() / $V{total_cat}.floatValue()))]]></textFieldExpression> Post Edited by gstephens at 10/18/2009 15:39 Link to comment Share on other sites More sharing options...
tibidoudou Posted October 1, 2010 Share Posted October 1, 2010 Hi, I don't know if this is gonna be read but I was wondering I you could please post the jrxml file that you said worked. 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