官术网_书友最值得收藏!

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.

Tip

Please note that you will need administrator rights on the Cognos server to complete this recipe. If the server is installed on your personal machine, you will have these rights by default.

  1. 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
  2. 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).
  3. Change the IIS security to allow 'Anonymous Read and Browse' accesses.
  4. Now open the report that shows the month-on-month running differences.
    Getting ready
  5. Insert a new 'image' from the insertable objects pane on the list report, as a new column.
  6. 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')
  7. Call this variable Traffic and define three possible values for the same (red, yellow, and green).
    Getting ready
  8. Now go back to the report page. Select the image. Open its URL Source Variable dialog. Choose the variable Traffic and click OK.
    Getting ready
  9. From Condition Explorer, choose 'red' condition. Now click on the image again. It will allow you to define the image URL for this condition.
  10. Set the URL to: ../samples/images/Red.jpg
    Getting ready
  11. Similarly, define the URL for 'yellow' and 'green' conditions as ../samples/images/yellow.jpg and ../samples/images/green.jpg respectively.
  12. Run the report to test it.
    Getting ready

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.

More info

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.

主站蜘蛛池模板: 旬邑县| 乌恰县| 禄丰县| 山丹县| 湛江市| 景德镇市| 扶沟县| 盘山县| 益阳市| 东乡族自治县| 德格县| 枞阳县| 阳东县| 灵台县| 长汀县| 新干县| 额尔古纳市| 同德县| 娄烦县| 浦北县| 九寨沟县| 噶尔县| 鹤峰县| 秭归县| 顺平县| 富川| 天柱县| 盐城市| 韶关市| 兴文县| 和政县| 玉环县| 皋兰县| 辰溪县| 赤城县| 洞头县| 绿春县| 武安市| 休宁县| 惠州市| 衡水市|