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 9. Adding Charts

This chapter is dedicated to charts. We will talk about chart functions, good and bad practices of using charts, and how to create and configure our own charts among other topics.

By explaining each type of chart, we will be able to understand which chart to use for a particular need, and how to configure the chart so that its look and feel is what we want.

We will also see how charts allow us to show data from different perspectives and add value to our reports.

In this chapter we will perform the following operations:

  • Create a new report, create its data set, and create two parameters

  • Create and configure a pie chart

  • Create and configure a bar chart

Finally, we propose that you modify a previous report and add a chart to it to give it greater capacity for analysis.

Starting practice


In this chapter, we will create a new report and configure the data set, labels, parameters, and so on, but most importantly we will create and configure two charts. When we finish the exercises, we will have a report that looks like this:

The upper half of the preceding chart is a pie chart and the bottom is a bar chart. Both charts use the main data set of our report as its data source.

We will learn about charts in PRD and then manipulate them.

Time for action – creating a new report


We will now create a new report that we will use in this chapter's exercises. We will create a JDBC data set that connects to the Sakila database, and we will establish its SQL query. Next, we will create two parameters to choose the year and month for which we want data, and finally we will add the Message object to show the period under analysis.

  1. We will create a new report and save it with the name 11_Adding_Charts.prpt.

  2. We will create a JDBC data set and configure it as follows:

    • Connections = sakila db

    • Query Name = Ratings

    • Query =

        SELECT film.rating, SUM(payment.amount) sum_amount, count(1) count_rental
        FROM payment
        INNER JOIN rental ON rental.rental_id=payment.rental_id
        INNER JOIN inventory ON inventory.inventory_id=rental.inventory_id
        INNER JOIN film ON film.film_id=inventory.film_id
        WHERE YEAR(payment.payment_date)=${SelectYear}
        AND MONTH(payment_date) = ${SelectMonth}
        GROUP BY film.rating
  3. We will create two parameters. The first...

Charts


PRD uses JFreeChart to manage charts. JFreeChart is a Java library that lets us create many types of high-quality charts. It also allows the charts to be highly customizable. The license that JFreeChart uses is the GNU LGPL, which allows proprietary software to use this library.

Note

For more information on JFreeChart, please refer to:

Charts give life to our reports and make them more than simple flat reports, giving them another dimension. Regarding this, Thomas Morgner, the Architect of PRD, said:

"Reporting without charting is like zombies without the inevitable hunt for fresh brains. You can do it, yes, but it is sure not fun."

Earlier most reporting software were not prepared to include charts, and the software that allowed charts presented serious limitations in their configuration. As such, most reports were just lists. Later, with the advent of new technology and software growth...

Restarting practice


We have explained the basic theoretical concepts about charts; now let's continue the practice.

Time for action – creating a pie chart


We will add a pie chart to our report to display information about the movies rented. Then we will configure the type of chart we want to visualize, its data source, and other characteristics.

  1. We will create a chart to display an analysis of the percentage of movies rented by rating. Add a chart to the Report Header section, dragging-and-dropping the () Chart () object.
  2. Double-click on Chart to start configuring it.

  3. In the upper part, choose the pie chart type:

  4. In the right-hand part, configure the data source as follows:

    • value-column = count_rental (the value under analysis)

    • series-by-field = [rating] (the item to be represented as a portion of the pie)

  5. In the left-hand part, configure the following:

    • chart-title = Percentage of films rented by Rating

    • label-font = FreeSans-BOLD-14

    • label-format = {0}: {2}

    • 3-D = True

    • show-legend = False

  6. Next, click on OK to continue. If we preview it, we will see this:

What just happened?

We added a Chart object to the...

Time for action – creating a bar chart


We will add a bar chart to our report to display information about the movies rented. Then we will configure the type of chart we want to visualize, its data source, and other characteristics. We will create a chart to display an analysis of the total number of movies rented by rating.

  1. Add a Chart () object to the Report Header section under the pie chart.
  2. Double-click on this new chart to start configuring it. In the upper part, choose the bar chart type:

  3. In the right-hand part, configure the data source as follows:

    • category-column = rating (the item to be represented by the bars)

    • value-columns = [sum_amount] (the value under analysis)

    • series-by-field = [rating]

    If we do not specify the series-by-field value, the chart will show us all the bars in the same color and by default place them in Series 1. By establishing the rating value, we make each column independent from the others, and as such, each will have a different color.

  4. In the left-hand part...

Summary


We created a report from scratch, and created and configured its data set. We created and established default values for two parameters: SelectYear and SelectMonth.

We explained each type of chart, its advantages, how to use it, how not to use it, and showed an example of each one of them. We talked about the chart editor UI and differentiated its three parts: where we choose the type of chart, where we configure the data sources, and where we configure the chart's behavior.

We added a pie chart to the Report Header section and then configured it to meet our needs.

We also added a bar chart to the Report Header section and configured it according to our needs.

Finally, we showed how the inclusion of charts in our reports influences them, and we proposed that you modify a previous report by adding a ring chart.

In the next chapter, we will explain how to add subreports in our reports.

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