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 Time for action – creating a bar chartChart () 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:
    Time for action – creating a bar chart
  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, configure the following:
    • chart-title = Total rental by Rating
    • 3-D = True
    • label-font = FreeSans-BOLD-14
    • x-axis-label-rotation = 45.0
    • y-font = FreeSans-PLAIN-10
    • y-tick-font = FreeSans-PLAIN-10
    • y-tick-fmt-str = $
    • show-legend = False
  5. Next, click on OK to continue. If we preview it, we will see this:
    Time for action – creating a bar chart

What just happened?

We added a Chart object to the Report Header section. Then we edited this object, making it a bar chart and configuring its data source to analyze the total number of films rented by rating. We configured the chart's title, gave the chart a 3D effect, changed the characteristics of the source of the labels that display information about each bar, rotated the x axis labels by 45 degrees, changed the source of the y axis labels, made the y axis values begin with the dollar sign, and hid the chart's legend.

The relationship between charts and report sections

Just like any other object, the behavior of a chart depends on the section of the report where it is added.

If we place a chart in a Header section (Report Header, Details Header, and so on) or a Footer section (Report Footer, Details Footer, and so on), the chart will be shown each time these sections are shown in the report. Usually they are shown once per page. In this case, Chart will have access to all the rows in the data set.

On the other hand, if we place a chart in the Details section, the chart will be shown once for each row in the section. Usually they are shown many times per page. In this case, the chart will only have access to the data of the row under analysis.

Have a go hero

Now we propose that you modify the report you have already made and add a ring chart to show the information from another perspective. A ring chart will be displayed for each new element in the group, in this case for each new country. The report should look like this:

Have a go hero

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

  1. Create a copy of the 05_Adding_Groups.prpt report and save it with the name 12_Adding_Charts_Plus.prpt.
  2. Place a Chart object in the Group Header section:
    Have a go hero
  3. The chart will display the values of amount for each customer.

Pop quiz – charts

Q1. Which of the following statements are true?

  1. JFreeChart is a Java library with a GNU LGPL license.
  2. It is best practice to add charts to all our reports.
  3. The more charts our reports contain, the more useful they will be.
  4. If we want to easily see what percentage of the total each of our items represents, the best option to use is a bar chart.
  5. If we need a chart to analyze three sets of variables for each item, a good option to use would be a bubble chart.
  6. If we need to analyze a group of values and determine which of these do not follow normal behavior, a good option would be to use a scatter plot chart.
  7. A waterfall chart shows bars similar to a bar chart, but with the difference that the waterfall chart uses the colors green and red to express positive and negative values respectively.
..................Content has been hidden....................

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