Expressions how to??

I have a hard time making any function.

I need something like 

(($F{b} - $F{a}) * 100) / $F{a}

... but it doensn't work for me like this.

 

 

 

 

mishomor's picture
Joined: Jan 6 2010 - 4:40pm
Last seen: 9 years 3 months ago

6 Answers:

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.

ckampshoff's picture
1528
Joined: Sep 23 2009 - 6:25am
Last seen: 3 days 7 hours ago

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 :

<span class="pln">SELECT COUNT</span><span class="pun">(</span><span class="pln">gender</span><span class="pun">)</span><span class="pln"> AS total_by_gender</span><span class="pun">,</span><span class="pln"> gender </span><span class="pun">,</span><span class="pln">account_status  FROM user_account ua</span><span class="pun">,</span><span class="pln"> user_profile up WHERE ua</span><span class="pun">.</span><span class="pln">user_profile_id</span><span class="pun">=</span><span class="pln">up</span><span class="pun">.</span><span class="pln">user_profile_id GROUP BY gender</span><span class="pun">,</span><span class="pln">account_status<br /></span>

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

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

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

highjo's picture
374
Joined: Dec 17 2009 - 9:18am
Last seen: 9 years 11 months ago

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

ckampshoff's picture
1528
Joined: Sep 23 2009 - 6:25am
Last seen: 3 days 7 hours ago
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
highjo's picture
374
Joined: Dec 17 2009 - 9:18am
Last seen: 9 years 11 months ago

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.

ckampshoff's picture
1528
Joined: Sep 23 2009 - 6:25am
Last seen: 3 days 7 hours ago
i've got it Christina! thanks you very very much
highjo's picture
374
Joined: Dec 17 2009 - 9:18am
Last seen: 9 years 11 months ago
Feedback