Jump to content

Crosstab conditional text color


chaddn

Recommended Posts

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,

Chadd



Post Edited by Chadd Nelson at 01/22/09 19:07
Link to comment
Share on other sites

  • Replies 5
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

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

$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

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...