Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Formatting field data color based on condition

I'm new to JasperReports. I'm designing report using iReport. My requirement is I have two values (Fields) x,y to compare. If x < y then the data color for y should be changed to 'black' & if greater then data color of y should be changed to 'red'.

Please advice me as to how to proceed on this & where to validate.

like image 404
Chandu Avatar asked Mar 29 '10 06:03

Chandu


1 Answers

I know this is an old question, but in I am assuming Jasper Reports has changed. You can now accomplish this with Conditional Styles.

In iReport you create a new Style and give it a name. You can put any default settings, such as font, color, text size, etc. in the style. Then you right click the Stlye and select Add Conditional Style. Then on the field or fields you want to apply it to you set the style to one you created.

So in your example I would set the Forecolor in the main stlye to be black, set the Condition Expression in the Conditional Style to be

$F{y} > $F{x}

and the Forecolor in the conditional Stlye to red. Then in the detail section where you have the y field placed set the style to the one we created.

like image 57
Jacob Schoen Avatar answered Oct 05 '22 20:10

Jacob Schoen