'How can I embed images into a Birt report to show an image depending on if the column result equals 1 or 0?

How can I embed images into a Birt report to show images depending on if the result equals 1 or 0?

I’ve tried following the guide from:

http://birtworld.blogspot.com/2010/09/birt-image-report-item.html

I am not able to show an image (checkbox) when the column value equals 1 and another image (unchecked box) when the column value equals 0.

I’ve tried using the following expression:

if( row["acceptsplititem"] == 1 ){
"checked-50x49.jpg";
}else if( row["acceptsplititem"] == 0 ){
"unchecked-50x49.jpg";
}

I’ve tried adding both images (checked and unchecked) by dragging the image report item and selecting from image file in shared resources, then editing the URL of the image via: Properties > Advanced > URL

if( row["acceptsplititem"] == 1 ){
"checked-50x49.jpg";
}else if( row["acceptsplititem"] == 0 ){
"unchecked-50x49.jpg";
}

I’ve also tried a suggestion from a previous question/answer on stackoverflow:

Embedding an image in BIRT

But this doesn’t display either image.

Adding an image using Dynamic text

Embedding an image

Please help and advise where I am making a mistake

Thanks in advance,

Stuart



Solution 1:[1]

I've found that by inserting an image then selecting visibility from the Property Editor you can then tick Hide Element and enter an expression:

row["preferred"]==0 

This would hide the element (Tick Box) if the result is 0 Place another image (Crossed Box) on the same row with expression:

row["preferred"]==1 

This will hide the image if the result is 1

Solution 2:[2]

This is an expression, so you should NOT use a semicolon afteer the string literals. Furthermore, the value might be different from 0 or 1 (e.g. null), so you should also add yet another image filename for the "else" part.

In order to check that your images can be displayed at all, you should also use a constant expression as the very first step:

Constant expression:

"check-50x49.jpg"

This should show the "checked" image.

Next, the expression depending on the value (assuming you also have an image file "other.jpg":

if( row["acceptsplititem"] == 1 ) {
    "checked-50x49.jpg"
} else if( row["acceptsplititem"] == 0 ) {
  "unchecked-50x49.jpg"
} else {
  "unknown.jpg"
}

Or - slightly more verbose:

var fname = "unknown.jpg";
if( row["acceptsplititem"] == 1 ) {
    fname = "checked-50x49.jpg";
} else if( row["acceptsplititem"] == 0 ) {
    fname = "unchecked-50x49.jpg";
}
fname

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 TheOx
Solution 2 hvb