Use of Stylesheets for Report Designing using BIRT

Exclusive offer: get 50% off this eBook here
BIRT 2.6 Data Analysis and Reporting

BIRT 2.6 Data Analysis and Reporting — Save 50%

Create, Design, Format, and Deploy Reports with the world's most popular Eclipse-based Business Intelligence and Reporting Tool

$26.99    $13.50
by John Ward | July 2010 | Java Open Source

BIRT is an open source business intelligence and reporting tool built on top of the Eclipse Framework. BIRT is used by developers for building reports that can best represent data and tell a story of that data that is easy to follow. In addition, BIRT can be integrated into a product to allow that product to provide reporting capabilities. 

In this article by John Ward,author of BIRT 2.6 Data Analysis and Reporting we will look at how BIRT uses stylesheets in report designs and how styles can be grouped in a library to create themes. This will allow us to have certain sets of styles ready for use any time we develop a report so that we, as a report developer, can focus strictly on the technical aspects of the report while maintaining a consistent visual presentation.

Stylesheets

BIRT, being a web-based reporting environment, takes a page from general web development toolkits by importing stylesheets. However, BIRT stylesheets function slightly differently to regular stylesheets in a web development environment.

We are going to add on to the Customer Orders report we have been working with, and will create some styles that will be used in this report.

  1. Open Customer Order.rptDesign.
  2. Right-click on the getCustomerInformation dataset and choose Insert into Layout.
  3. Modify the table visually to look like the next figure.

    Use of Stylesheets for Report Designing using BIRT

    Create a new dataset called getCustomerOrders using the following query: //insert code 1

  4. Link the dataset parameter to rprmCustomerID.
  5. Save the dataset, right-click on it, and select Insert to layout.

    Use of Stylesheets for Report Designing using BIRT

  6. Select the first ORDERNUMBER column.

    Use of Stylesheets for Report Designing using BIRT

  7. Under the Property Editor, Select Advanced.

    Use of Stylesheets for Report Designing using BIRT

  8. In the Property Editor, go to the Suppress duplicates option, and change it to true. This will prevent the OrderNumber data item from repeating the value it displays down the page.

    Use of Stylesheets for Report Designing using BIRT

  9. In the Outline, right-click on Styles and choose New Style….

    Use of Stylesheets for Report Designing using BIRT

  10. In the Pre-Defined Style drop down, choose table-header. A predefined style is an element that is already defined in the BIRT report. When selecting a predefined style, this will affect every element of that type within a report. In this case, for every table in the report, the table header will have this style applied.

    Use of Stylesheets for Report Designing using BIRT

  11. Under the Font section, apply the following settings:
    • Font: Sans-Serif
    • Font Color: White
    • Size: Large
    • Weight: Bold
  12. Under the Background section, set the Background Color to >b>Black.
  13. Click OK.

Now, when we run the report, we can see that the header line is formatted with a black background and white font.

Use of Stylesheets for Report Designing using BIRT

Custom stylesheets

In the example we just saw, we didn't have to apply this style to any element, it was automatically applied to the header of the order details table as it was using a predefined style. This would be the case for any table that had the header row populated with something and the same is the case for any of the predefined styles in BIRT. So next, let's look at a custom defined style and apply it to our customer information table.

  1. Right-click on the Styles section under the Outline tab and create a new style.

    Use of Stylesheets for Report Designing using BIRT

  2. Under the Custom Style textbox, enter CustomerHeaderInfo.

    Use of Stylesheets for Report Designing using BIRT

  3. Under the Font section, enter the following information:
    • Font: Sans Serif
    • Color: White
    • Size: Large
    • Weight: Bold
  4. Under the Background section, set the Background Color to Gray.
  5. Under the Box section, enter 1 points for all sections.
  6. Under the Border section, enter the following information:
    • Style (All): Solid
    • Color (All): White
    • Width (All): Thin
  7. Click OK and then click Save.
  8. Select the table which contains the customer information.

    Use of Stylesheets for Report Designing using BIRT

  9. Select the first column.

    Use of Stylesheets for Report Designing using BIRT

  10. Under the Property Editor, in the list box for the Styles, select CustomerHeaderInfo.
    Use of Stylesheets for Report Designing using BIRT
  11. The preview report will look like the following screenshot:
    Use of Stylesheets for Report Designing using BIRT
  12. Right-click on the Styles section, and create a new custom style called CustomerHeaderData.

    Use of Stylesheets for Report Designing using BIRT

  13. Under Box, put in 1 points for all fields.
  14. Under Border, enter the following information:
    • Style – Top: Solid
    • Style – Bottom: Solid
    • Color (All): Gray
  15. Click OK.
  16. Select the Customer Information table.

    Use of Stylesheets for Report Designing using BIRT

  17. Select the second column.

    Use of Stylesheets for Report Designing using BIRT

  18. Right-click on the column selector and select Style | Apply Style | CustomHeaderData.
  19. The finished report should look something like the next screenshot:

    Use of Stylesheets for Report Designing using BIRT

BIRT 2.6 Data Analysis and Reporting Create, Design, Format, and Deploy Reports with the world's most popular Eclipse-based Business Intelligence and Reporting Tool
Published: July 2010
eBook Price: $26.99
Book Price: $44.99
See more
Select your format and quantity:

Editing stylesheets

So, now we have two custom styles and one predefined style defined in the report.However, we need to make a change. If we look at this preceding example, the gray lines in the data section of our header do not match the white lines of the label section. Normally such tedious visual elements are the concerns for graphic designers, but in this case this provides us with the perfect excuse to look at editing stylesheets.

The following example will take a look at editing the column of the header information so that the lines are gray instead of white. Editing stylesheets is a fairly trivial task, where simply double-clicking existing styles brings up the style editor.

  1. In the Outline tab, under the Style section, double-click on the CustomHeaderInfo style or right-click and select Edit Style….

    Use of Stylesheets for Report Designing using BIRT

  2. Select the Border Section. Under the Top and Bottom colors, select Gray.

    Use of Stylesheets for Report Designing using BIRT

    That was easy enough. Let's take a look at the report as it stands:

    Use of Stylesheets for Report Designing using BIRT

There is a gap of a few pixels between the label column and the data column.The following steps show how to get rid of that gap:

  1. Select CustomHeaderInfo and open it for editing.
  2. Select Border. Change the Left and Right line style to No Line Style.

    Use of Stylesheets for Report Designing using BIRT

  3. Repeat steps 1 to 3 for CustomHeaderData.

    Use of Stylesheets for Report Designing using BIRT

Alternating row colors using Highlights

So far the report we are designing is coming along nicely. However, the details section leaves a little to be desired visually. It is hard to distinguish lines from each other, and it would be nice to have the first line of a new order be of a different color to distinguish it from the previous order. Well, we are in luck. BIRT provides a nice capability called Highlight that allows us to change formatting options based on a particular condition. What follows is a frequently requested report feature. We will add in an alternating row color to simulate the old fashioned "green bar" type reports.

Highlighting can be applied in one of two ways. It can be applied either to an element directly or in a style. There really is no difference in editing a style between the two. I will cover both methods.

First, let's look at applying the alternating row color through a style:

  1. Create a new style called detailAlternatingRowColor. A single word must be used, else an error will be thrown.

    Use of Stylesheets for Report Designing using BIRT

  2. Select Highlights from the list of categories. Select Add….

    Use of Stylesheets for Report Designing using BIRT

  3. Use the following condition: row.__rownum % 2. This is an expression that will select every other row.
  4. Set the operand to Equals to. This defines what type of comparison is used between the expression and what it expects as its final value.
  5. Set the value to 0. This defines what the expression's final value will cause this highlight to trigger.
  6. Set the Background color to Silver.

    Use of Stylesheets for Report Designing using BIRT

  7. Click OK and exit out of the Style Editor.
  8. Select the Detail row for the getCustomerOrders table either from the Visual Designer or from the Outline.

    Use of Stylesheets for Report Designing using BIRT

  9. In the Property Editor, select General.
  10. In the Style list box, select detailAlternatingRowColor.
    Use of Stylesheets for Report Designing using BIRT

Now, when we run the report, we can see the detail row has the alternating colors we were looking for. We can easily apply this to any of the detail rows in our report.

Now let's move to the next method—applying Highlighting property directly to an element.

  1. Select the Detail row of the customer information table and remove the detailAlternatingRowColor style applied in the last two steps of the previous method.
  2. With the Detail row selected, use the Property Editor and select the Highlight tab.

    Use of Stylesheets for Report Designing using BIRT

  3. Click the Add… button.
  4. Set the Condition as row.__rownum % 2.
  5. Set the comparison operator to Equal to.
  6. Set the value to 0.
  7. Set the Background color to Silver.

    Use of Stylesheets for Report Designing using BIRT

  8. Click OK.
  9. Preview the report.
    Use of Stylesheets for Report Designing using BIRT

Just like with the previous example, we have an alternating row color in the detailssection. The only difference is where this is applied. In the first example it is applied as a style, whereas in the second it is applied to the detail row directly.

Summary

In this article we have demonstrated the various ways a report developer can format their report using basic formatting, styles and stylesheets,

BIRT 2.6 Data Analysis and Reporting Create, Design, Format, and Deploy Reports with the world's most popular Eclipse-based Business Intelligence and Reporting Tool
Published: July 2010
eBook Price: $26.99
Book Price: $44.99
See more
Select your format and quantity:

About the Author :


Books From Packt


JasperReports 3.6 Development Cookbook
JasperReports 3.6 Development Cookbook

Liferay Portal 6 Enterprise Intranets
Liferay Portal 6 Enterprise Intranets

Microsoft Dynamics NAV 2009 Application Design
Microsoft Dynamics NAV 2009 Application Design

Drupal E-commerce with Ubercart 2.x
Drupal E-commerce with Ubercart 2.x

Pentaho 3.2 Data Integration: Beginner's Guide
Pentaho 3.2 Data Integration: Beginner's Guide

IBM Cognos 8 Report Studio Cookbook
IBM Cognos 8 Report Studio Cookbook

Oracle Siebel CRM 8 Installation and Management
Oracle Siebel CRM 8 Installation and Management

Oracle SOA Suite 11g R1 Developer's Guide
Oracle SOA Suite 11g R1 Developer's Guide


Your rating: None Average: 4 (1 vote)
Style vs detail row highlight by
If you leave the style set on the detail row and also set the row highlighting the row highlighting suppresses the use of the style highlighting. I tried changing the style to give the odd rows (row.__rownum % 2 equals 1) a different color from the even ones being set by the row highlighting and discovered that when the detail row highlight is used the style highlight appears to have no effect.
Test by webdevelopment@packtpub.com
Testing.....

Post new comment

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
d
N
F
c
7
N
Enter the code without spaces and pay attention to upper/lower case.
Code Download and Errata
Packt Anytime, Anywhere
Register Books
Print Upgrades
eBook Downloads
Video Support
Contact Us
Awards Voting Nominations Previous Winners
Judges Open Source CMS Hall Of Fame CMS Most Promising Open Source Project Open Source E-Commerce Applications Open Source JavaScript Library Open Source Graphics Software
Resources
Open Source CMS Hall Of Fame CMS Most Promising Open Source Project Open Source E-Commerce Applications Open Source JavaScript Library Open Source Graphics Software