- IBM Cognos 8 Report Studio Cookbook
- Abhishek Sanghani
- 631字
- 2021-08-06 17:15:52
Showing images dynamically (Traffic Light report)
In first chapter, we created a report under the 'Running Difference' recipe. This report shows the month-on-month difference in sales quantity.
Business wants to give this report a 'dashboard' look by putting Traffic Light images (red, yellow, and green) in each row, based on whether there is rise in sales or fall.
Getting ready
We will use the "Running Difference: negative values in brackets and red" report based on the recipe in Chapter 2 for this.
Open that report in Cognos Report Studio and save a copy with a new name.
- For this recipe, we need to first create three icons or images for red, yellow, and green. They should be already available on the Cognos server under
{Cognos Installation}\webcontent\samples\images
folder. If not, then create them using any image editor software or use the images supplied with this book - Once you have the three images which you need to conditionally show on the report, place them on the Cognos server under
{Cognos Installation}\webcontent\samples\images
folder. (If the folder is not there, create one). - Change the IIS security to allow 'Anonymous Read and Browse' accesses.
- Now open the report that shows the month-on-month running differences.
- Insert a new 'image' from the insertable objects pane on the list report, as a new column.
- Now go to Condition Explorer and create a new string variable. Define the expression as:
if ([Query1].[Running Difference] > 0) then ('green') else if ([Query1].[Running Difference] < 0) then ('red') else ('yellow')
- Call this variable Traffic and define three possible values for the same (red, yellow, and green).
- Now go back to the report page. Select the image. Open its URL Source Variable dialog. Choose the variable Traffic and click OK.
- From Condition Explorer, choose 'red' condition. Now click on the image again. It will allow you to define the image URL for this condition.
- Set the URL to:
../samples/images/Red.jpg
- Similarly, define the URL for 'yellow' and 'green' conditions as
../samples/images/yellow.jpg
and../samples/images/green.jpg
respectively. - Run the report to test it.
How it works...
Cognos Report Studio allows you to put the images in the report by specifying the URL of the image. The images can be anywhere on the intranet or internet. They will be displayed properly as long as the URL is accessible from Cognos application server and gateway.
In this recipe, we are using a report which already calculates the Running Difference. Hence, we just had to define conditional variable to trap different possible conditions. The Image component allows us to define the URL for different conditions by attaching it to the Traffic variable in step 8.
There's more...
In this case, though the URL of the image changes dynamically, it is not truly 100% dynamic. There are three static URLs already defined in the report and one is picked up depending on the condition.
We can also use a data item or report expression as source of the URL value. In that case, it will be totally dynamic, and based on the values coming from database; Cognos will work out the URL of the image and display it correctly.
This is useful when the image filenames and locations are stored in the database. For example, Product Catalogue kind of reports.
This recipe works fine in HTML, PDF, and Excel formats.
We have used relative URLs for the images, so that report can be easily deployed to other environments where Cognos installation might be in a different location. However, we need to ensure that the images are copied in all environments in the folder mentioned in step 2.
- UG NX10.0從新手到高手
- Vue.js框架與Web前端開發(fā)從入門到精通
- CakePHP 1.3 Application Development Cookbook
- Mastering phpMyAdmin 3.3.x for Effective MySQL Management
- Cinema 4D電商美工與視覺設(shè)計案例教程(培訓(xùn)教材版)
- AutoCAD 2018中文版基礎(chǔ)教程
- Photoshop CC從入門到精通(全彩超值版)
- Lighttpd
- SOA Patterns with BizTalk Server 2009
- 高等院校電腦美術(shù)教材:CorelDRAW X7中文版基礎(chǔ)教程
- Choosing an Open Source CMS: Beginner's Guide
- 零基礎(chǔ)攝影后期修圖 Photoshop照片處理輕松入門
- 中文版CINEMA 4D R20 實用教程
- 邊做邊學(xué):CorelDRAW X6圖形設(shè)計案例教程(第2版)(微課版)
- Origin 2022科學(xué)繪圖與數(shù)據(jù)分析(高級應(yīng)用篇)