motoman Posted February 26, 2009 Share Posted February 26, 2009 ...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 More sharing options...
dprogrammer Posted February 26, 2009 Share Posted February 26, 2009 I use an older version and I usually accomplish this by placing two fields with desired colors and backgrounds and the suppress either one using conditional logic. Link to comment Share on other sites More sharing options...
motoman Posted February 26, 2009 Author Share Posted February 26, 2009 OK...let's pretend I don't have any idea how to do that...so how would I do that? Link to comment Share on other sites More sharing options...
svenn Posted February 26, 2009 Share Posted February 26, 2009 I would use conditional styles. Do a search on this forum. This topic has been covered many times. Link to comment Share on other sites More sharing options...
motoman Posted February 26, 2009 Author Share Posted February 26, 2009 Thanks for the tip, but after preusing the results of searching that topic, I don't really see anything that tells you *how* to use conditional styles. Is there a tutorial or something somewhere? Link to comment Share on other sites More sharing options...
dprogrammer Posted February 26, 2009 Share Posted February 26, 2009 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 More sharing options...
motoman Posted February 26, 2009 Author Share Posted February 26, 2009 ...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 More sharing options...
dprogrammer Posted February 26, 2009 Share Posted February 26, 2009 Instead of .intValue(), try using .doubleValue() Link to comment Share on other sites More sharing options...
motoman Posted February 26, 2009 Author Share Posted February 26, 2009 ...where? I don't know where it's getting that from. The field is defined as a double, and I tried to create a variable to use that references that field, also set as double, and get the same result. Link to comment Share on other sites More sharing options...
motoman Posted February 26, 2009 Author Share Posted February 26, 2009 www.kaleb-world.com/webstuff/cond.jpg ...there's where I am at. That field is a double. I just want to be able to evaluate it, logically, as shown, and I believe I can get the rest to work. Pulling my hair out... Link to comment Share on other sites More sharing options...
dprogrammer Posted February 26, 2009 Share Posted February 26, 2009 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 More sharing options...
motoman Posted February 26, 2009 Author Share Posted February 26, 2009 ...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 More sharing options...
motoman Posted February 26, 2009 Author Share Posted February 26, 2009 ...eventually figured it out with a little help. Needed syntax like this: new Boolean (($F{geofence_DURATION}.intValue() >= 5) && ($F{geofence_DURATION}.intValue() < 10)) ...which is not exactly intuitive to me, but there you go. 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