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

Conditional formatting - basic help needed


motoman

Recommended Posts

...I am sure this question has been posed before, but I didn't really find the kind of help I'm looking for with a search.

 

Just started using iReport 3.1.2.  On a basic report, I want to conditionally format a value/row based on an evaluation of the value.  For example, if it's >= 5 then I want to have a yellow background and black font...if it's >=10 I want a red background and white font...that kind of thing.

 

Any pointers would be greatly appreciated. 

Link to comment
Share on other sites

  • Replies 12
  • Created
  • Last Reply

Top Posters In This Topic

Popular Days

Top Posters In This Topic

First drag and drop the field that you want to have dyanamic color twice. Change background color for first field to Yellow and the second field to Red.

Now right click Yellow field, click Properties, select Common tab and write this code in the 'Print when expression' box: (make sure to replace myconditionalfield with your actual field name)

$F{MyConditinalField}.intValue()>= 5 && $F{MyConditinalField}.intValue()<10?Boolean.TRUE:Boolean.FALSE

//if >=5 and <10 then show Yellow field

 

//Code for Red field at the same place just like above

$F{MyConditinalField}.intValue()>= 10?Boolean.TRUE:Boolean.FALSE

 

Hope this helps.

 

Link to comment
Share on other sites

...I'm sure that probably would work, but I stumbled across the "conditional" bit in a Style I created, which is I reckon what others are directing me to.

 

However, when I try to define the simplest expression for the condition, I get an error. Like "$F{value} >= 5" - which is as simple an expression as one can get. It tells me that "the operator >= is undefined for the argument type(s) Double, int" - ...I am wondering how a basic operator like that can be undefined for numeric data types...? What am I doing wrong?

Link to comment
Share on other sites

Just play around with field datatypes. Try to change the datatype of your conditional field to BigDecimal and then use following expressions.

 

//yellow

$F{MyConditinalField}.doubleValue()>= 5 && $F{MyConditinalField}.intValue()<10?Boolean.TRUE:Boolean.FALSE

//red

$F{MyConditinalField}.doubleValue()>= 10?Boolean.TRUE:Boolean.FALSE

 

Also, if your value is <5, what would you like to display?

Link to comment
Share on other sites

...changing the data type on my field seems to make the report not run.

 

From what I can tell, or at least what I'm guessing, I'm just trying to define the condition under which this style is used. I made a style, and then added a Conditional to it, and the condition should be that the style is used when my value is >= 5.

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