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

Expressions how to??


mishomor

Recommended Posts

  • Replies 6
  • Created
  • Last Reply

Top Posters In This Topic

Hi mishomor,

any error message? Where have you put this piece of code? Variable? Field? Which kind of variable or field?

What about this: new java.math.BigDecimal((($F{b}.doubleValue() - $F{a}.doubleValue()) * 100) / $F{a}.doubleValue()) ? If your variable/field is type BigDecimal.

HTH

Christina.

Link to comment
Share on other sites

Hello!
I'm trying to get myself used to jasperforge ireport before using it in a real project next week and i seem to be stacked somewhere already .i'm using ireport 3.7.0 on windows xp platform + java 1.6

It sound easy to get a field color changed based on what it contains or calculate a sum of number in a field based on conditions but in practice it's taking me too much time to accomplish. I have a query say :

SELECT COUNT(gender) AS total_by_gender, gender ,account_status  FROM user_account ua, user_profile up WHERE ua.user_profile_id=up.user_profile_id GROUP BY gender,account_status
[/code]

it gives me something like this:

    | total_by_gender | gender | account_status |      | 160             |Female  | ENABLED        |      | 26              |Female  | UNCONFERIMED   |      | 100             |Male    | ENABLED        |    | 10              |Male    | UNCONFIRMED    |    

Now i want the ENABLED Text to Look say green and UNCONFIRMED say red.For that i added a text field with this expression

$F{account_status}.equals("ENABLED") ? "<style forecolor='#ff0000'>" + $F{account_status}.toString() + "</style>" :"<style forecolor='#999999'>" + $F{account_status}.toString() + "</style>"    

[/code]

well for each of them it gives me something like the same text like <style> (i think it's printing all the condition expression) instead of colored text unconfirmed or enabled.

My second problem is that i want to do the total of all unconfirmed and all enabled. i can do normal sum expression but with condition i don't have any idea. Can anyone shed some light? thanks for reading. i hope this time i'll get a response to my post

Link to comment
Share on other sites

Hi highjo,

have you tried to use a style for the different coloured text? There you can create a style for a text field with different conditions. For each condition you can choose a different colour.

For your second problem try a variable for counting. Variable name: total_uncomfirmed, Varable calss: java.lang.Integer, Calculation Sum, Reset Type Report, Increment Type None, Variable expression: (account_status.equals("UNCONFERIMED" ?  new java.lang.Integer(1): new java.lang.Integer(0))

HTH

Christina

Link to comment
Share on other sites

hello christana!

Your suggestion for the summing helped me a lot.I could implement it using this formula $F{account_status}.equals( "UNCONFIRMED" )? new java.lang.Long($F{total_by_gender}) : new java.lang.Long(0) thanks.however i fail to get the understanding of what you were saying about the text coloring.

What do you mean by trying a style for different colored text? thanks for your reply

Link to comment
Share on other sites

Hi highjo,

I work with iReport 3.6.0 and there I can use Styles. To use a style you have to right klick on the point "Styles" in your Report Inspector. And than use Add -> Style. After that you can tell the style how the text would look like in the Properties window.You can choose a forecolor and a backcolor. This you would need to show your text in diferent color. In the first style properties window you have to put the information how the text shoiuld look normal (for example black forecolor, white backcolor). After that you have to add a conditional style. There you can use a condition like this: new Boolean($F{account_status}.equals("ENABLED")). Then you can put a different forecolor like green and as backcolor white. After this you have to say the filed with your data to use this style. To do this klick on the field in your report and choose your style in the the stylecombobox. I know this is much text and I hope it will help you.

HTH

Christina.

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