chaddn Posted January 22, 2009 Share Posted January 22, 2009 I have several crosstab reports I need to setup in iReport v 3.0.0 and for a specific field I would like all negative values to show in a red font color when you view the report. I got some code from the following thread, but I'm having trouble getting it to work.http://jasperforge.org/plugins/espforum/view.php?group_id=83&forumid=101&topicid=25350 The field I want to have this conditional text color is a variable sum, type is integer (in the query, the element, and the crosstab object). Here's the code I'm using in the "Text Field Expression" for the element in the crosstab. $V{diff_Sum}.intValue() < 0?"<style forecolor='#ff0000'>" + $V{diff_Sum}.toString() + "</style>" :"<style forecolor='#0000ff'>" + $V{diff_Sum}.toString() + "</style>" When I run the report I get the error message "Cannot cast from String to Integer". Also, please note I do have the "Is styled text" box checked under the font tab of the element. Any help would be greatly appreciated. Thanks,ChaddPost Edited by Chadd Nelson at 01/22/09 19:07 Link to comment Share on other sites More sharing options...
revathyraj Posted January 23, 2009 Share Posted January 23, 2009 Could you please post your full jrxml? Link to comment Share on other sites More sharing options...
revathyraj Posted January 23, 2009 Share Posted January 23, 2009 Please find the sample jrxml attached with diff_Sum variable. You have use the 'Text Field Expression Class' as java.lang.string. This is available under properties ---> Text field. Link to comment Share on other sites More sharing options...
chaddn Posted January 23, 2009 Author Share Posted January 23, 2009 Great, changing the text field to String worked.. However, now I lost my ability to apply a pattern to the integer. I would like the numbers to format like 1,234 if positive and (1,234) if negative. Is there away to do that now that the field is a string? Thanks for your help! Chadd Link to comment Share on other sites More sharing options...
revathyraj Posted January 23, 2009 Share Posted January 23, 2009 $V{sale}.doubleValue() < 0 ? ("<style forecolor='#FF0000' pattern='#,##0.0'>" +new DecimalFormat("#,##0.0;(#,##0.0)").format($V{sale})+ "</style>") : ("<style forecolor='#000000' pattern='#,##0.0'>" +new DecimalFormat("#,##0.0;(#,##0.0)").format($V{sale})+ "</style>") make sure that your are checking the isstyledtext property in the properties window. The new DecimalFormat("#,##0.0;(#,##0.0)") is for your positive and negative number distinguishing. Link to comment Share on other sites More sharing options...
chaddn Posted January 23, 2009 Author Share Posted January 23, 2009 That worked perfectly, thank you! 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