vanhuet Posted May 16, 2007 Share Posted May 16, 2007 Hi, I'm pretty new to iReports and have been searching on the internet now for a long time. I found solutions for most of my "problems", but one remains. I want to display the numbers in my report in black if they are positive. When they're negative I want them red. I already format them with patterns etc and this all works. Only thing is the color. It sounds like a really easy thing, but I've been trying for ages now with conditions at the style for the table cell. I really am lost now. Can somebody give me an example how to do this? Thanks!! Link to comment Share on other sites More sharing options...
redwine Posted May 17, 2007 Share Posted May 17, 2007 vanhuet, i saw your post and thought of having some fun by making a sample with your requirements. check out the attached .jrxml file and modify/experiment on it as much as you like. just take note of the conditional expressions for each the two fields and the variable that i used.basically i used the <style> </style> tags and the forecolor attribute to control the text color.i just used hex values for the color (#0000ff is blue and #ff0000 is red). any questions... just post it here. cool? Have fun. Edwin [file name=conditional_coloring.jrxml size=6002]http://www.jasperforge.org/components/com_joomlaboard/uploaded/files/conditional_coloring.jrxml[/file] Link to comment Share on other sites More sharing options...
vanhuet Posted May 17, 2007 Author Share Posted May 17, 2007 Thanks a million!! Geez, in fact it is really simple. Now I also see what I did wrong with the styles. Thank you very much for putting so much effort in this. :) Link to comment Share on other sites More sharing options...
redwine Posted May 18, 2007 Share Posted May 18, 2007 no problem.always happy to help someone out.B) Link to comment Share on other sites More sharing options...
mauri Posted May 18, 2007 Share Posted May 18, 2007 The script below is in language Groovy ? $P{number1} >= 0 ? $P{number1} : "<style forecolor='#ff0000'>" + $P{number1} + "</style>" If is, how make the same code in java? Link to comment Share on other sites More sharing options...
redwine Posted May 18, 2007 Share Posted May 18, 2007 mauri, I got it! :)I modified the file i previously posted and saved it as conditional_coloring_java.jrxmlIt does the same thing as the previous one but this one uses Java instead of Groovy. Code for one of the text elements:Code:$P{number2}.intValue() < 0 ? "<style forecolor='#ff0000'>" + $P{number2}.toString() + "</style>" : "<style forecolor='#0000ff'>" + $P{number2}.toString() + "</style>"I had to look up how to do it but thankfully, the Java5 API was a lot of help.:) I need to go so just look at the file.Note how the parameters are "unboxed" from an Integer to an int and "boxed" back from an int to an Integer type. Let me know if this helped or if you have any questions about what I changed.Enjoy! edwin [file name=conditional_coloring_java.jrxml size=5923]http://www.jasperforge.org/components/com_joomlaboard/uploaded/files/conditional_coloring_java.jrxml[/file] Post edited by: edwin, at: 2007/05/18 13:26Post edited by: edwin, at: 2007/05/18 13:29 Link to comment Share on other sites More sharing options...
mauri Posted May 18, 2007 Share Posted May 18, 2007 I make how below get Data from Database: $F{EMPLOYEE_SALARY}.doubleValue() > 50000?"<style forecolor='#ff0000'>" + $F{EMPLOYEE_SALARY}.toString() + "</style>" :"<style forecolor='#0000ff'>" + $F{EMPLOYEE_SALARY}.toString() + "</style>" When show the report it put how image in attached ! IReport 1.3.3 What is wrong ? Link to comment Share on other sites More sharing options...
mauri Posted May 18, 2007 Share Posted May 18, 2007 Attached Report jrxml and Image View size=400]http://www.jasperforge.org/components/com_joomlaboard/uploaded/images/Jasper2.jpg [file name=RelColor.jrxml size=4810]http://www.jasperforge.org/components/com_joomlaboard/uploaded/files/RelColor.jrxml[/file] Link to comment Share on other sites More sharing options...
redwine Posted May 19, 2007 Share Posted May 19, 2007 i'm thinking you didn't set the "Is styled text" property to true by checking that option for both your textFields. right click each of your textFields.click Properties.click the Font tab.check the "Is styled text" option. that might just be the thing to make it work.let me know how it goes. edwin Link to comment Share on other sites More sharing options...
mauri Posted May 19, 2007 Share Posted May 19, 2007 Edwin.... Very good !!! It work fine !!! Thank´s a lot Link to comment Share on other sites More sharing options...
redwine Posted May 19, 2007 Share Posted May 19, 2007 no problem my friend! :)always glad to help when i can. 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