Chapter 8. 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 dsClassicCars data source to the report.
    Pie chart
  3. Create a new dataset called totalSales using the following query:
    select CLASSICMODELS.EMPLOYEES.EMPLOYEENUMBER,
    CLASSICMODELS.EMPLOYEES.LASTNAME || ', ' || CLASSICMODELS.EMPLOYEES.FIRSTNAME name,
    sum(CLASSICMODELS.ORDERDETAILS.PRICEEACH) sales
    from
    CLASSICMODELS.EMPLOYEES,
    CLASSICMODELS.ORDERS,
    CLASSICMODELS.ORDERDETAILS,
    CLASSICMODELS.CUSTOMERS
    where
    CLASSICMODELS.CUSTOMERS.SALESREPEMPLOYEENUMBER = CLASSICMODELS.EMPLOYEES.EMPLOYEENUMBER
    and CLASSICMODELS.ORDERS.CUSTOMERNUMBER = CLASSICMODELS.CUSTOMERS.CUSTOMERNUMBER
    and CLASSICMODELS.ORDERDETAILS.ORDERNUMBER = CLASSICMODELS.ORDERS.ORDERNUMBER
    and CLASSICMODELS.ORDERS.ORDERDATE between ? and ?
    group by
    CLASSICMODELS.EMPLOYEES.EMPLOYEENUMBER,
    CLASSICMODELS.EMPLOYEES.LASTNAME,
    CLASSICMODELS.EMPLOYEES.FIRSTNAME
    
  4. 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.
    Pie chart
  5. Drag a chart component from the Palette to the Report Designer.
    Pie chart
  6. In the Chart dialog, select Pie chart. Change the Output format from SVG to PNG. Typically, I use 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.
    Pie chart
  7. Open the Select Data tab. Under the Select Data section, select Use Data Set and choose the totalSales dataset.
  8. 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.
    Pie chart
  9. Select the Format Chart tab. Under the Title section, enter Employee Sales Percentages as the chart title. In this editor, we change how the chart looks and feels.
    Pie chart
  10. Click Finish.
  11. 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.
    Pie chart
  12. The chart will look something like the following screenshot when previewed:
Pie chart

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....
    Pie chart with explosions
  2. Open the Format Chart... tab.
  3. Open the Value Series section.
    Pie chart with explosions
  4. Under the Slice section, change the By Distance value to 6.
  5. For Slice Outline, choose the color black from the palette.
    Pie chart with explosions
  6. Save the chart and preview it. The following screenshot shows what the chart looks like with the explosion and slice outline added.
Pie chart with explosions

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.
    Pie charts—working with percentages
  4. Under Values, remove the Value Data option.
    Pie charts—working with percentages
  5. Under Values, add Percentile Value Data.
    Pie charts—working with percentages
  6. Click the Interactivity button.
    Pie charts—working with percentages
  7. Choose Mouse Click from the Event listbox.
    Pie charts—working with percentages
  8. From the Action listbox, choose Invoke Script.
    Pie charts—working with percentages
  9. Click the Expression Editor button.
    Pie charts—working with percentages
  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:
    Pie charts—working with percentages
  11. Click OK. Now click on the<< arrows in the Series Interactivity window.
    Pie charts—working with percentages
  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.

Pie charts—working with percentages
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset