Adding a chart to a report

In this recipe, we will guide you through the steps required to fetch data from a MongoDB instance and render a Pentaho chart into the report. Similar to the previous recipe, we will be using a Pentaho Data Integration transformation to get order summary data to populate the chart. This data will consist of total order values grouped by country.

Getting ready

To get ready for this recipe, you will have to make sure your MongoDB instance is running.

How to do it…

  1. In Report Designer, go to File | New.
  2. Click on the Data tab in the top-right corner of Report Designer.
  3. Right-click on the Data item in the list and select Pentaho Data Integration.
  4. To add a new data source, click on the plus button in the top-left corner of the pop-up window.
  5. Set the Name property of the query to Orders.
  6. Click on the Browse button to open the Select transformation dialog.
  7. Browse your file system and select the chapter5-getorders-summary.ktr transformation, as done in the previous recipe. (This file is provided as source code along with this book.)
  8. Select the OUT step in the list of steps available in this transformation.
  9. Click on Preview.
  10. Click on OK.

You will notice that the Orders data is broken down into countries this time. We have used a simple Group By step in the transformation to do this.

Now that we have our data, we can use it to populate a simple bar chart in the Pentaho Report:

  1. Drag a chart component from the Pentaho Report Designer toolbar to the left of the Report Header band:
    How to do it…
  2. Align the chart component to fit the width of the report. You will have to resize the anchors to do this:
    How to do it…
  3. Double-click on the chart component that you placed into the Report Header band. This will open Chart Properties.
  4. Make sure you are looking at the Primary Data Source tab.
    1. Set category-column to country.
    2. Set value-columns to totalPrice.
    3. Set auto-generated-series to true.

    The following screenshot appears:

    How to do it…
  5. Click on OK.
  6. Click on Preview to see the report.

If everything goes well, you will be looking at a simple chart in the Report Header band. Before we finish up, we can set a couple of common options to make the chart look a little more pleasing to the eye:

  1. Double-click on the Chart Component
  2. You should see a large list of various options on the left-hand side panel.
  3. Set Chart Title to Orders by Country.
  4. Set X Axis Label Rotation to 90.

    The following screenshot shows the final output chart:

    How to do it…

How it works…

Rendering a chart to a report is similar to adding tabular data to a report. The only real difference is that all the report data is rendered in a single chart component, so we place our chart into the Report Header band. The report header band is only executed once per report. If we were to place the chart into the Details band, then we would be seeing the same chart for every row in the database.

Reporting charts have many options. Feel free to open the chart component and play around with the other options available to you.

..................Content has been hidden....................

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