Reader small image

You're reading from  Pentaho 5.0 Reporting by Example: Beginner's Guide

Product typeBook
Published inAug 2013
PublisherPackt
ISBN-139781782162247
Edition1st Edition
Tools
Right arrow
Author (1)
Right arrow

Chapter 4. Instant Gratification – Creating Your First Report with PRD

In this chapter, we will create our first report with PRD. As we perform each step in the creation of this report, we will see the PRD UI's functions in action. It is important to understand the concepts presented in the previous chapters in order to be able to put them in practice without difficulty.

In this chapter, we will cover the following:

  • We will see how to configure the report's sections: Page Header, Report Header, Details Header, Details, and Details Footer

  • We will add different insertable objects to our report, such as labels, horizontal lines, vertical lines, text fields, number fields, and images

  • We will create the following functions and explain how they are used: RowBanding, Count (Running), and Sum (Running)

  • We will see how to preview our report and the different formats that PRD lets us export to, such as PDF, HTML, and Excel/Excel 2007

Each step will be explained in detail and screenshots will be included...

Creating your first report with PRD


In this chapter, we will create a report that, at first glance, appears simple. In fact, it is simple. However, by the end of the chapter, we will have carried out the principal steps that are normally followed in creating reports.

Initially, it can be very difficult to adapt to working with a tool as complex as PRD. This is why we will explain its principal functions and characteristics gradually as we develop our examples. Understanding these things allows us to work with PRD and learn to use it at the same time. Our methodology will be to present a concept and put it in practice.

The report that we will now create is shown in the following screenshot:

Time for action – creating a new report and creating a table based on data sets


We will create a new report, and later we will create a Table type data source and configure its columns and data types. Finally, we will populate the table with the example data.

  1. Start PRD if it is not yet running.

  2. Create a new report. Remember that there are different ways to create a new report as follows:

    • Choose the New Report option in the Welcome window

    • Click on the following icon in the shortcuts bar:

    • Navigate to File | New

    • Press Ctrl + N

  3. Save the report as 01_Hello_World.prpt using the following icon:

  4. We will define Table as a data source. The Table is a static data source; it is stored with the report's metadata and remains constant. This type of data source is often used for demonstrations, examples, testing, prototyping, and so on.

  5. In the Data tab, right-click on Data Sets and choose Table.

  6. We define three columns in our data sets: Zones, Products, and Quantity.

  7. To create the table, click on the icon. By...

Time for action – configuring the Report Header and Details Header sections


In the ensuing steps, we will configure the Report Header and Details Header sections so that it looks as follows:

  1. In the Report Header section, we will add a label with the header text.

  2. To do this, we must drag-and-drop the insertable object Label (); this means that we need to drag it and release it in the work area that belongs to the Report Header section. Next, we will configure this label so it includes the text First Report: Hello World in bold face, centered, and large font size.
  3. To do so, we will select the label we just added in the work area and configure its Attributes and Style properties.

  4. In the Attributes tab, as the value of the characteristic value, we enter First Report: Hello World.

  5. In the Style tab, as the value of the bold characteristic, we enter true.

  6. In the Style tab, as the value of the font-size characteristic, we enter 20.

  7. In the Style tab, as the value of the h-align characteristic, we enter...

Time for action – configuring details


Next, we will configure Details to get the following result:

  1. We select the Data tab and drag-and-drop Zones, Products, and Quantity, placing each under the corresponding label.

    Note

    As we saw before, these objects that we just added to the report are actually the text field () and number field (). This is because PRD makes mapping the data type dragged to the work area with the required insertable object.

  2. Now we will execute the report to see the results it is giving us.

    We press the icon found in the shortcut bar. This will give us different format options to output the report.

    In this case, we choose Print Preview as follows:

  3. This will give us the following preview:

What just happened?

We added the fields Zones, Products, and Quantity to the Details section of our report. Then we executed our report in preview mode.

The second half of the report


So far we have completed the first part of the guide, more precisely the creation of our first report. We have created a data set type Table and configured the Report Header, Details Header, and Details sections.

Now, we will move on to the second part of the report. We will add functions, configure the Details Footer section, and give final touches to the design.

Time for action – adding functions


We will add a function to color the rows in an alternating manner, differentiating between the even and odd rows, just as they appear in the finished report.

  1. In the Data tab, we right-click on Functions, and in the drop-down menu, we select the Add Functions... option.

  2. Now we will see the following window:

  3. This window contains all of the functions that we can create in PRD grouped into categories. In this case, we choose the Row Banding function in the Report category and click on OK to create it:

  4. Next, we configure its name, background color, and the name of the element/object that the function will be applied to:

    • Function Name = RowBanding

    • Active Banding Color = #ccff66

    • Apply Element(s) Named = oddEvenRowBanding

    • Now that the function has been defined, we can apply it

  5. In the Structure tab, navigate to Master Report | Group | Details Body | Details:

  6. In this tab, we configure the following:

    • Attributes.name = oddEvenRowBanding

    This will apply the oddEvenRowBanding...

Time for action – adding more details


Next, we will add two vertical lines in the Details section and add an image in the Page Header section:

  1. We add another detail in the Details section.

    We add two vertical lines () to separate our report's columns. It should look as follows:
  2. Establish the following characteristics for both lines:

    • Style.stroke = solid, 1.0

    • Style.text-color = #0099333; to finish this example, we add an image in the Page Header section

  3. In the Page Header section, place the Image object (). Right-click on this object, and in the drop-down menu, choose the Edit Content... option.
  4. We need to indicate our image's path and choose how we want the image connected to our report:

    • Link To: This option only stores the image's path. The image is obtained when the report is executed.

    • Embed In Report: This option stores the image as a resource with the report's metadata.

      Note

      The advantage of Link To is that the size of the report is smaller. Also, the image can be changed, maintaining...

Output types


We will now see some examples of the main output types of PRD.

Time for action – exporting in different formats


Next, we will see how to present the report we just created by exporting it to different formats:

  1. Press on the icon found in the shortcut bar. In this case, we choose PDF:
  2. Now press on the icon and choose HTML:
  3. Press on the icon and choose Excel (or Excel 2007).

What just happened?

We exported our report to different formats, that is, to PDF, HTML, and Excel/Excel 2007.

Have a go hero

Now that we have made our first report, it is time for you to put into practice what we have been learning. We propose that you make some small modifications to the 01_Hello_World.prpt report so that it looks as follows:

The steps you should perform, broadly speaking, are as follows:

  1. Save the report with the name 01_Hello_World_Plus.prpt.

  2. Edit the ZoneProductQty data set, adding the Type column with its corresponding values.

  3. Create a function that returns the average of the quantities sold, that is, that calculates it based on the Quantity field.

Pop Quiz – data...

Summary


In this chapter, we created our first report by following a series of steps that we listed and explained in detail.

We created a Table type data set and configured its data manually. We defined three columns: Zones, Products, and Quantity. We specified the type of data that each would contain (String, Integer, and so on). Then we populated the table with the example data.

We configured the Report Header and Details Header report sections, adding labels and a horizontal line. Also, we configured the characteristics of these insertable objects.

In the Details section, we added the fields from the table we created initially.

We created and added various functions to the report. We created and added RowBanding to alternately color the data in the Details section, and in the Details Footer section, we added Count (Running) and Sum (Running) to count and sum up respectively.

To add a personal touch, in the Page Header section we added an image of our liking.

We saw how useful the preview option...

lock icon
The rest of the chapter is locked
You have been reading a chapter from
Pentaho 5.0 Reporting by Example: Beginner's Guide
Published in: Aug 2013Publisher: PacktISBN-13: 9781782162247
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
undefined
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime