BIRT 2.6 Data Analysis and Reporting

BIRT 2.6 Data Analysis and Reporting

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. This book will walk the user through the basics of building reports with BIRT and introduce them to the various sections of the BIRT environment.

also read:

What This Book Covers

Chapter 1, Getting Started, is an introduction to BIRT. It gives the reader an idea of the BIRT features, community landscape, and the various websites out there that are dedicated to BIRT.
Chapter 2, Installing BIRT, guides the user through the various ways of installing BIRT.
Chapter 3, The BIRT Environment and First Report, introduces the BIRT workspace environment by walking the reader through a simple report example.
Chapter 4, Visual Report Items, presents us with various visual report items that are available for use in a report design.
Chapter 5, Working with Data, discusses how to retrieve data from databases, fl at text files, web services, and other data sources.
Chapter 6, Report Parameters, explains how to get input from the report user, along with how to apply these report parameters in filtering data.
Chapter 7, Report Projects and Libraries, looks at reusing report sections and sharing resources through libraries and report projects.
Chapter 8, Charts, Hyperlinks, and Drilldowns, shows how to build summary data using charts and linking sections of charts to reports. In addition, hyper linking used in online reports to link and show detailed data in other reports is discussed here.
Chapter 9, Scripting and Event Handling, discusses report generation through event handling, as well as how to manipulate and format data using simple JavaScript expressions. Some advanced scripting examples are provided based on common requests.
Chapter 10, Deployment, looks at how does a developer can get reports out into the world for consumption.

Charts, Hyperlinks, and Drilldowns

It has been said that a picture is worth a thousand words. In the world of reporting, we call these pictures as Charts. With the help of charts, one can present a large amount of data with relative ease, in comparison to presenting with the help of huge data outputs. Charts are useful when used with raw data to drive home points such as percentages, or when used with other charts to build dashboards.
BIRT has an exceptional charting engine. BIRT can create a number of different Chart types, including the tried and tested pie chart, bar chart, and line charts. In addition, there are several other chart types that were extras to BIRT’s commercial counterpart such as the Meter Chart and Gantt chart.
In the following sections, we are going to look at building a few different charts centered around employee sales performance. First, we will build a pie chart that will illustrate the top employees based on sales. We will then create a gauge chart that will show the progress an employee has made to meet a quota. Finally, we will create a bar chart that will show sales performance for employees across a time period.

Pie chart

In the following exercise, we are going to look at how to build a pie chart. A pie chart is a very common report type used in business to display percentages. In this example, we will create a pie chart to show what percentage an employee contributed to the total amount of sales. This will give us a visual representation of who the top employees are in terms of sales.

  1. Create a new report titled Employee_Sales_Percentage.rptDesign.
  2. From the ClassicCarsLibrary.rptDesign library, add the dsClassicCarsdata source to the report.
  3. Create a new dataset called totalSales using the following query:
  4. 	select
    		and CLASSICMODELS.ORDERS.ORDERDATE between ? and ?
    	group by
  5. Create two report parameters called startDate and endDate as date types and link them to the two report parameters. Use 2005-01-01 as the startDate’s default value, and 2005-05-01 as the endDate’s default value.
  6. Drag a chart component from the Palette to the Report Designer.
  7. In the Chart dialog, select Pie chart. Change the Output format from SVG to PNG. Typically, iuse either PNG or JPEG, as SVG is not a universally
    supported format. However, SVG does have a distinct advantage over both PNG and JPEG in that SVG images are smaller in size due to the format’s vector nature.
  8. Open the Select Data tab. Under the Select Data section, select Use Data Set and choose the totalSales dataset.
  9. We can drag the column headers from the dataset to the slice definitions. Drag the SALES column to the Slice Size Definition and the NAME column to the Category Definition. To make selecting the correct header easier, we can use the Show data preview checkbox to see what data is in each column. Without it, the preview box will show only the column names.
  10. Select the Format Chart tab. Under the Title section, enter Employee Sales
    as the chart title. In this editor, we change how the chart looks and feels.
  11. Click Finish.
  12. Resize the chart to take up report page. This can be done by dragging the corner of the chart or by entering the height and width values in the property editor.
  13. The chart will look something like the following screenshot when previewed:

So, we have built a fairly simple report so far. This report is a pie chart with a legend
that shows us the employee’s color code, with an excerpt that shows us the value of that slice.

Pie chart with explosions

While the pie chart we saw in the preceding section is nice, it would be a little easier
to view if the slices were exploded, and if the slices had an outline. Let’s take a look
at how to modify some of the chart’s properties to do this.

  1. Double-click on the chart in the report design. This will reopen the chart dialog. Another option is to right-click on the chart and choose Format Chart….
  2. Open the Format Chart… tab.
  3. Open the Value Series section.
  4. Under the Slice section, change the By Distance value to 6.
  5. For Slice Outline, choose the color black from the palette.
  6. Save the chart and preview it. The following screenshot shows what the chart
    looks like with the explosion and slice outline added.

Pie charts—working with percentages

Things are starting to look better. But let’s say we want to change the chart to display
percentages instead of numbers and add a little interactivity to the chart to display the sales numbers when a section is clicked on.

  1. Double-click on the chart to edit it.
  2. Select the Value Series section.
  3. Click on the Labels button.
  4. Under Values, remove the Value Data option.
  5. Under Values, add Percentile Value Data.
  6. Click the Interactivity button.
  7. Choose Mouse Click from the Event listbox.
  8. From the Action listbox, choose Invoke Script.
  9. Click the Expression Editor button.
  10. Using the editor, click on the Variables | Chart Data Point | Value Data option to insert the valueData variable into the editor. Surround it with an alert() method call. It should look like the next screenshot:
  11. Click OK. Now click on the << arrows in the Series Interactivity window.
  12. Click Finish in the Chart Editor.

When we preview the report, the chart pops up, formatted in the manner we want. If we click on one of the pie slices, an alert window will pop up showing the value for that series.

Gauge chart

With the next chart, the guage chart, we will expand on the interactivity a bit and demonstrate how drill-downs work. In addition to viewing the static chart, we want the user to be able to click on the chart and have it pull up an external report with the details for a particular user. This is called a drilldown.

The following meter chart will demonstrate an employees sales vs. a target amount per month, let’s say 3000, on a 5000 dollar scale. This will be broken out and grouped monthly in the query statement. When the user clicks on the chart, it will bring them to the detail report we created last chapter for Employee sales.

  1. Create a new report titled Employee_Sales_Guage.rptDesign.
  2. From the library, drag over the dsClassicCars data source.
  3. Create a new dataset called employeeSales using the following query:
  4. 	select
    		rtrim(char(year(CLASSICMODELS.ORDERS.ORDERDATE))) || '-' ||
    		rtrim(char(month(CLASSICMODELS.ORDERS.ORDERDATE))) orderDate
    		and CLASSICMODELS.ORDERS.ORDERDATE between ? and ?
    	group by
  5. Link the two dataset parameters to the report parameters, startDate and endDate respectively.
  6. Drag the employeeSales dataset to the report designer.
  7. Delete the last two columns from the table.
  8. Create a group called GroupByEmployee in the table and set it to group on the EMPLOYEENUMBER.

  9. Create another group below GroupByEmployee and call it groupByDate. Set it to group on the ORDERDATE field.
  10. Merge all of the cells in the orderDate details row into one large cell. Be sure to delete any data items that are still present such as the NAME and EMPLOYEENUMBER items.
  11. In the new large cell, create a chart element.
  12. Select Meter as the type, and select SuperImpose Meter as the chart type. If we need to know which type of chart we are picking, hover the mouse over the chart for a second and its description will pop up. Set the Output Format
    to PNG.
  13. In the Select Data tab, create another dial by selecting the Meter Value Definition drop-down list and selecting <New Series..>.
  14. For the expression for Dial 1, select row[“SALES”] by either dragging the column over from the Data Preview pane or by using the Expression Editor.
  15. The value for Dial 2 should be set to 3000.
  16. As Category Definition, use row[“NAME”] by either dragging the column over from the Data Preview section or using the Expression Editor.
  17. In the Format Chart tab, under the Value Series section, click the Scale button.
  18. Enter 0 for the Min value and 5000 for the Max value. We have now set up the scale.
  19. On the Edit Chart tab, under the Legend section, uncheck the Visible checkbox.
  20. Select Chart Area.
  21. Click the Interactivity button.
  22. Select Mouse Click from the Event listbox and select Hyperlink from the Action listbox.
  23. Click the Add Button.
  24. In the Name field, insert NewHyperlink.
  25. Click the Edit Base URL… button.
  26. Select Drill-through as the hyperlink type.
  27. For the Report Design, navigate and select the report Employee Sales Details Report.rptDesign. This report was created in the preceding chapter.
  28. Select the startDate and endDate parameters under the Parameters drop down, which selects the parameters in the target report. Under Values, enter params[“startDate”].value and params[“endDate”].value, or whatever names that have been used used for the current report’s startDate and endDate parameters.
  29. Under Step 2, select Target Bookmark. From the drop-down list, select row[“EmployeeNumber”].
  30. Under Step 4, select New Window.
  31. We can skip Step 5 as we are sticking to our default output format, which is HTML. We could have the target report open in any format that we have an emitter registered for. Emitters are plugins for BIRT that produce output in different formats such as HTML, PDF, Microsoft Excel, or Microsoft Word.
  32. Click OK to exit the dialog and save the report.
  33. Delete the table header.
  34. Delete the EMPLOYEENUMBER data element.
  35. Drag the EMPLOYEENUMBER column from the Data Explorer, next to the OrderDate report item.
  36. Now run the report. When we click on any of the charts, a detailed report will open and the control will automatically jump to the employees section, as specified in the Bookmark in the target report.

Of course, this example can be heavily modified to simplify things. The charts could be consolidated into single chart, with more needles for each month instead of separate charts for each month, by moving the chart into the EmployeeNumber group’s header or footer row and adding a group by date in the chart editors dialog under the Select Data tab. It is also possible to make the needles interactive and to filter down to a specific user and date range by modifying the bookmarks in the target report, but I will leave that up to the reader to discover. The following is a modified version of the the report that has created different series in the chart itself for the date groupings.

Bar chart

In the earlier section, we saw some of the power that charting can have with reports,by adding both the graphical representation of data and the interactivity for users to see the details of that data in a separate report. We also saw how to pass data through to the target report by using the expression. In this report, the hyperlink will take us to an internal bookmark, which means it will jump us to a location inside the same report containing the details for our report. We will also look at aggregating values inside the chart so that we can provide a simple query that just retrieves the necessary details and lets BIRT handle the tricky stuff for us.

  1. Create a new report called EmployeeSalesPerformanceReport.rptDesign.
  2. Use the dsClassicCars data source in the library.
  3. Create a new dataset called employeeSales, using the following query:
  4. 	select
    		and CLASSICMODELS.ORDERS.ORDERDATE between ? and ?
  5. Map the dataset parameters to report parameters startDate and endDate.
  6. Drag a table element over from the palette.
  7. Set Number of columns to 3 and Number of details to 1, and map the
    dataset element to the employeeSales dataset.
  8. In the header row, insert a new row.
  9. In the top most header, merge all the cells into one large cell.
  10. Insert a chart element into the large cell.
  11. Select Bar chart as the type.
  12. Select the stacked Bar Chart as the subtype.
  13. Set the Output Format to PNG.
  14. Go to the Select Data tab.
  15. For the series value, drag in the PRICEEACH column.
  16. For the Category (x) Series, use the following expression:
  17. 	(row["ORDERDATE"].getYear() + 1900).toString() + '-' +
    	(row["ORDERDATE"].getMonth() + 1).toString()

    This may not make much sense now, but we will explain it further in the next chapter.

  18. For the Optional Y Series Grouping, drag in the NAME column.
  19. In the Inherit Data From Container drop-down list, select Inherit Columns only. This will set up the chart to ignore any grouping at the table level and let the chart engine do its down grouping.
  20. Next to the Category (x) Series expression editor button , there is a button to
    edit group and sorting. Click that button.
  21. Select Ascending from the Data Sorting drop down.
  22. In the Grouping checkbox, check the Enable option.
  23. Keep the other values at their defaults and click OK.
  24. Click Finish and save the report.
  25. Select the table, and create a group on EMPLOYEENUMBER.
  26. Create a grouping on OrderDate.
  27. For the detail row, drag over the PRODUCTNAME into the second column and PRICEEACH into the third column.
  28. From the Palette, drag over an Aggregation element into the groupFooter
    for the OrderDate grouping.
  29. Create the aggregation on the PRICEEACH field for the salesDateGroup.
  30. Add in any formatting that might spruce up the look of our report.
  31. Select the OrderDate groupings header row . Select the Bookmark tab under the property editor. Use the following expression for the bookmark:
  32. 	row["EMPLOYEENUMBER"] + row["ORDERDATE"]

  33. Double-click on the chart to enter the Chart Editor.
  34. Select the Format Chart tab.
  35. In the Edit Chart window, select the Value (Y) Series section and click the
    Interactivity button.
  36. In the Event drop-down list select Mouse Click, whereas in the Action
    listbox select Hyperlink.
  37. Click the Add button.
  38. Enter ChartHyperlink for the Name.
  39. Click the Edit base URL… button.
  40. In the hyperlink dialog box, select Internal Bookmark as the type.
  41. Select the following from the drop down:
  42. 	row["EMPLOYEENUMBER"] + row["ORDERDATE"]
  43. Click OK to save the report. Now run it.

Now, when we click on any of the different colored sections of the bar chart, it will bring us to the details section within our own report.


In this chapter, we have seen how to create several different chart types. We have seen how we can create interactivity within a single report and how to drill down into a separate report using charts and passing through parameters. We have seen how to aggregate data within a chart to serve as a summary for the more detailed data. We have opened the dialog to edit properties of charts and seen how a few of the properties affect the look and feel of charts as well as the behavior.
In the next chapter, we are going to explore the basic of scripting in BIRT reports.
Throughout this book we have been using a basic type of script called an expression. We will explore this in following chapters and expand into event handling as well.

Leave a Reply

Your email address will not be published. Required fields are marked *

Pin It on Pinterest

Share This

Share this post with your friends!