Search code examples
jasper-reportsireport

How do I make a dynamic image in iReport?


I have an image in my report. In the image expression, I want to do something like this:

if ($F{num} >= 10) {
    "C:\\Users\\zoudi\\workspace\\bfms\\red.jpg"
}
else if ($F{num} > 0) {
    "C:\\Users\\zoudi\\workspace\\bfms\\red.jpg"
}
else {}

Obviously, this syntax is not correct. What is the correct way to go about creating a dynamic image like this? Thanks!


Solution

  • If you're using Groovy, try:

     ($F{num} >= 10) ? "C:\\Users\\zoudi\\workspace\\bfms\\red.jpg" : 
         ($F{num} > 0) ? "C:\\Users\\zoudi\\workspace\\bfms\\blue.jpg" :
               "C:\\Users\\zoudi\\workspace\\bfms\\yellow.jpg"