Including Charts and Graphics in Pentaho Reports (Part 2)

Exclusive offer: get 50% off this eBook here
Pentaho Reporting 3.5 for Java Developers

Pentaho Reporting 3.5 for Java Developers — Save 50%

Create advanced reports, including cross tabs, sub-reports, and charts that connect to practically any data source using open source Pentaho Reporting.

$26.99    $13.50
by Will Gorman | September 2009 | Java Open Source

Read Part One of Including Charts and Graphics in Pentaho Reports here.

Ring chart

The ring chart is identical to the pie chart, except that it renders as a ring versus a complete pie. In addition to sharing all the properties similar to the pie chart, it also defines the following rendering property Pentaho Reporting 3.5 for Java Developers  :

Options Property Group

Property name

Description

section-depth

This property defines the percentage of the radius to render the section as. The default value is set to 0.5.

Ring chart example

For this example, simply open the defined pie chart example and select the Ring chart type. Also, set the section-depth to 0.1, in order to generate the following effect:

Pentaho Reporting 3.5 for Java Developers

Multi pie chart

The multi pie chart renders a group of pie charts, based on a category dataset. This meta-chart renders individual series data as a pie chart, each broken into individual categories within the individual pie charts. The multi pie chart utilizes the common properties defined above, including the category dataset properties. In addition to the standard set of properties, it also defines the following two properties:

Options Property Group

Property name

Description

label-format

This label defines how each item within a chart is rendered. The default value is set to "{0}". The format string may also contain any of the following:

  • {0}: To render the item name
  • {1}: To render the item value
  • {2}: To render the item percentage in relation to the entire pie chart

by-row

This value defaults to True. If set to False, the series and category fields are reversed, and individual charts render series information.

Note that the horizontal, series-color, stacked and stacked-percent properties do not apply to this chart type.

Multi pie chart example

This example demonstrates the distribution of purchased item types, based on payment type. To begin, create a new report. You'll reuse the bar chart's SQL query. Now, place a new Chart element into the Report Header. Edit the chart, selecting Multi Pie Pentaho Reporting 3.5 for Java Developers  as the chart type.

To configure the dataset for this chart, select ITEMCATEGORY as the category-column. Set the value-columns property to QUANTITY and the series-by-field to PAYMENTTYPE.

Pentaho Reporting 3.5 for Java Developers

Waterfall chart

The waterfall chart displays a unique stacked bar chart that spans categories. This chart is useful when comparing categories to one another. The last category in a waterfall chart normally equals the total of all the other categories to render appropriately, but this is based on the dataset, not the chart rendering. The waterfall chart utilizes the common properties defined above, including the category dataset properties. The stacked property is not available for this chart. There are no additional properties defined for the waterfall chart.

Waterfall chart example

In this example, you'll compare by type, the quantity of items in your inventory. Normally, the last category would be used to display the total values. The chart will render the data provided with or without a summary series, so you'll just use the example SQL query from the bar chart example. Add a Chart element to the Report Header and select Waterfall Pentaho Reporting 3.5 for Java Developers as the chart type.

Set the category-column to ITEMCATEGORY, the value-columns to QUANTITY, and the series-by-value property to Quantity. Now, apply your changes and preview the results.

Pentaho Reporting 3.5 for Java Developers

Bar line chart

The bar line chart combines the bar and line charts, allowing visualization of trends with categories, along with comparisons. The bar line chart is unique in that it requires two category datasets to populate the chart. The first dataset populates the bar chart, and the second dataset populates the line chart. The bar line chart utilizes the common properties defined above, including the category dataset properties. This chart also inherits the properties from both the bar chart, as well as the line chart. This chart also has certain additional properties, which are listed in the following table:

Required Property Group

Property name

Description

bar-data-source

The name of the first dataset required by the bar line chart, which populates the bars in the chart. This value is automatically populated with the correct name.

line-data-source

The name of the second dataset required by the bar line chart, which populates the lines in the chart. This value is automatically populated with the correct name.

Bar Options Property Group

Property name

Description

ctgry-tick-font

Defines the Java font that renders the Categories.

Line Options Property Group

Property name

Description

line-series-color

Defines the color in which to render each line series.

line-tick-fmt

Specifies the Java DecimalFormat string for rendering the Line Axis Labels

lines-label-font

Defines the Java font to use when rendering line labels.

line-tick-font

Defines the Java font to use when rendering the Line Axis Labels.

As part of the bar line chart, a second y-axis is defined for the lines. The property group Y2-Axis is available with similar properties as the standard y-axis.

Bar line chart example

To demonstrate the bar line chart, you'll reuse the SQL query from the area chart example. Create a new report, and add a Chart element to the Report Header. Edit the chart, and select Bar Line Pentaho Reporting 3.5 for Java Developers  as the chart type.

You'll begin by configuring the first dataset. Set the category-column to ITEMCATEGORY, the value-columns to COST, and the series-by-value property to Cost. To configure the second dataset, set the category-column to ITEMCATEGORY, the value-columns to SALEPRICE, and the series-by-value property to Sale Price. Set the x-axis-label-width to 2.0, and reduce the x-font size to 7. Also, set show-legend to True.

You're now ready to preview the bar line chart.

Pentaho Reporting 3.5 for Java Developers

Bubble chart

The bubble chart allows you to view three dimensions of data. The first two dimensions are your traditional X and Y dimensions, also known as domain and range. The third dimension is expressed by the size of the individual bubbles rendered. The bubble chart utilizes the common properties defined above, including the XY series dataset properties. The bubble chart also defines the following properties:

Options Property Group

Property name

Description

max-bubble-size

This value defines the diameter of the largest bubble to render. All other bubble sizes are relative to the maximum bubble size. The default value is 0, so this value must be set to a reasonable value for rendering of bubbles to take place. Note that this value is based on pixels, not the domain or range values.

The bubble chart defines the following additional dataset property:

Required Property Group

Property name

Description

z-value-columns

This is the data source column to use for Z value, which specifies the bubble diameter relative to the maximum bubble size.

Bubble chart example

In this example, you need to define a three dimensional SQL query to populate the chart. You'll use inventory information, and calculate Item Category Margin:

SELECT
"INVENTORY"."ITEMCATEGORY",
"INVENTORY"."ONHAND",
"INVENTORY"."ONORDER",
"INVENTORY"."COST",
"INVENTORY"."SALEPRICE",
"INVENTORY"."SALEPRICE" - "INVENTORY"."COST" MARGIN
FROM
"INVENTORY"
ORDER BY
"INVENTORY"."ITEMCATEGORY" ASC

Now that you have a SQL query to work with, add a Chart element to the Report Header and select Bubble Pentaho Reporting 3.5 for Java Developers  as the chart type. First, you'll populate the correct dataset fields. Set the series-by-field property to ITEMCATEGORY. Now, set the X, Y, and Z value columns to ONHAND, SALEPRICE, and MARGIN.

You're now ready to customize the chart rendering. Set the x-title to On Hand, the y-title to Sales Price, the max-bubble-size to 100, and the show-legend property to True. The final result should look like this:

Pentaho Reporting 3.5 for Java Developers

Pentaho Reporting 3.5 for Java Developers Create advanced reports, including cross tabs, sub-reports, and charts that connect to practically any data source using open source Pentaho Reporting.
Published: September 2009
eBook Price: $26.99
Book Price: $44.99
See more
Select your format and quantity:

Scatter chart

The scatter chart renders all items in a series as points within a chart. This chart type utilizes the common properties defined above, including the XY series dataset properties. The scatter chart also defines the following two properties:

Options Property Group

Property name

Description

dot-height

The height to render the individual points in pixels. The default value is 5.

dot-width

The width to render the individual points in pixels. The default value is 5.

Scatter chart example

For this example, you'll reuse the SQL query defined in your bubble chart example, as well as the default rendering properties configured. Simply select the Scatter chart type in the chart editor Pentaho Reporting 3.5 for Java Developers  . The chart below shows Sales Price and On Hand values:

Pentaho Reporting 3.5 for Java Developers

XY Area, XY Bar and XY Line charts

The XY Area, XY Bar, and XY Line charts graph an XY series dataset as an area, bar, or a simple line chart. These chart types utilize the common properties defined above, including the XY series dataset properties. The XY Bar chart also uses the property show-bar-borders, which is defined earlier in the bar chart. The XY Area and XY Line charts share the properties line-style, line-size, and show-markers, defined earlier in the line chart.

In addition to the standard XY Series Dataset, XY charts may use a Time Series Dataset to render data. To use the TimeSeriesCollector, you can select it in the Primary DataSource drop-down list. The Time Series Dataset is similar to the Category Dataset, but instead of a category it defines a category-time-column. The field selected for the category-time-column must be of the type java.util.Date. Also defined is the time-period-type, which defines at what interval of time should the results be grouped together. Valid values for this property include Millisecond, Second, Minute, Hour, Day, Week, Month, Quarter, and Year.

XY charts example

In this example, you'll reuse the SQL query defined in the bubble chart example, as well as the default rendering properties configured for each of the individual charts, XY Area Pentaho Reporting 3.5 for Java Developers  , XY Bar Pentaho Reporting 3.5 for Java Developers  , and XY Line Chart Pentaho Reporting 3.5 for Java Developers  . You'll also reuse the X and Y dataset configuration specified for the scatter chart.

Pentaho Reporting 3.5 for Java Developers

Extended XY Line chart

The Extended XY Line chart allows the rendering of three additional chart types—StepChart, StepAreaChart, and DifferenceChart. The Step chart types display an XY series dataset as a set of steps, and the Difference Chart renders two XY series and highlights the differences between the two. The Extended XY Line chart utilizes the common properties defined above, including the XY series dataset properties. The Extended XY Line chart also defines the following property:

Options Property Group

Property name

Description

ext-chart-type

The type of chart to render. Valid values are StepChart, StepAreaChart, and DifferenceChart.

Extended XY Line chart example

In this example, you'll reuse the SQL query defined in the bubble chart example, as well as the default rendering properties configured for each of the individual charts. Select Extended XY Line Pentaho Reporting 3.5 for Java Developers  as the chart type and specify StepChart, StepAreaChart and DifferenceChart as the Chart Type to see the different renderings:

Pentaho Reporting 3.5 for Java Developers

You've now worked with all the major chart types within Pentaho Reporting. Under the covers, charts are simply dynamic images that are generated and included in your reports. You'll now learn more about including images within reports.

Radar chart

The Radar chart renders a web-like chart that displays a categorical dataset. The Radar chart utilizes the common properties defined above, including the category series common properties. The Radar chart also defines the following properties:

Options Property Group

Property name

Description

thickness-primary-series

This value determines the line thickness of the web.

head-size

This value determines the size rendered for each data point. The value is a percentage of the entire chart.

radar-web-filled

If true, fills the web with the series color. This also shades the grid.

gridline-interval

The interval between gridlines in the radar chart. This value may be a fixed value length or percent. To enter a percent value, use the "%" sign at the end of the number.

Radar chart example

In this example, reuse the SQL query and dataset sections from your area chart example. The result should look like this:

Pentaho Reporting 3.5 for Java Developers

Including static images in your report

To include static images in your report, select the image report element Pentaho Reporting 3.5 for Java Developers  from the report designer palette and place it in your report. Double-click on the element, or right-click on the element and select Edit Content to select the static image. This brings up a resource dialog, where you can browse to the specific file location. You may Link to or Embed the image in the PRPT file. The image report element uses Pentaho Reporting's ResourceManager API to load the image. The ResourceManager interface is located in the org.pentaho.reporting.libraries.resourceloader package.

Including dynamic images in your report

To add dynamic images to your report, use the content-field report element Pentaho Reporting 3.5 for Java Developers  . The content field accepts different types of image inputs for rendering. The first approach is dynamically changing the image location within your dataset. If you have a field that contains a URL or file system location to your image, the content-field element will render the specified image.

The second approach is to populate the content-field with an object of type java.awt.Image for rendering. This approach would require a custom-implemented TableModel, or a custom function that returns an Image object.

The third approach is to populate the content-field with an object that contains the following method, which is determined through Java introspection:

void draw(Graphics2D g2, Rectangle2D area);

In addition to this API, Pentaho Reporting also defines an extended org.pentaho.reporting.engine.classic.core.util.ReportDrawable API with the following methods, for more detailed access into the report rendering process:

  • void draw(Graphics2D g2, Rectangle2D area);
  • void setConfiguration(Configuration config);
  • void setStyleSheet(StyleSheet style);
  • void setResourceBundleFactory(ResourceBundleFactory bundleFactory);
  • ImageMap getImageMap(final Rectangle2D bounds);

A custom TableModel implementation or custom function would also be required to make this object available to the Reporting engine.

Summary

In this article, you learned how to incorporate many chart types into your reports in many different ways. You learned how to configure a chart's dataset as well as customizing how each chart type looks in a report. You learned how to populate a category series dataset, as well as an XY series dataset, and make that data available to the various types of charts that render in your report. You also learned how to include static and dynamic images, as well as graphics, in your reports.

 

If you have read this article you may be interested to view :

Pentaho Reporting 3.5 for Java Developers Create advanced reports, including cross tabs, sub-reports, and charts that connect to practically any data source using open source Pentaho Reporting.
Published: September 2009
eBook Price: $26.99
Book Price: $44.99
See more
Select your format and quantity:

About the Author :


Will Gorman

Will Gorman is an Engineering Team Lead at Pentaho. He works on a variety of Pentaho's products, including Reporting, Analysis, Dashboards, Metadata, and the BI Server. Will started his career at GE Research, and earned his Masters degree in Computer Science at Rensselaer Polytechnic Institute in Troy New York. Over the years, Will has given many talks, including topics at local Java User Groups. He has published technical papers in journals such as Neurology, and is the author of multiple patents. Will is originally from Cincinnati and now lives in Orlando, Florida, the headquarters of Pentaho.

Books From Packt

Flex 3 with Java
Flex 3 with Java

Spring Web Flow 2 Web Development
Spring Web Flow 2 Web Development

LWUIT 1.1 for Java ME Developers
LWUIT 1.1 for Java ME Developers

JasperReports 3.5 for Java Developers
JasperReports 3.5 for Java Developers

Solr 1.4 Enterprise Search Server
Solr 1.4 Enterprise Search Server

Asterisk 1.4 – the Professional’s Guide
Asterisk 1.4 – the Professional’s Guide

ASP.NET 3.5 CMS Development
ASP.NET 3.5 CMS Development

Drools JBoss Rules 5.0 Developer's Guide
Drools JBoss Rules 5.0 Developer's Guide

 

No votes yet

Post new comment

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
W
d
A
f
i
Z
Enter the code without spaces and pay attention to upper/lower case.
Code Download and Errata
Packt Anytime, Anywhere
Register Books
Print Upgrades
eBook Downloads
Video Support
Contact Us
Awards Voting Nominations Previous Winners
Judges Open Source CMS Hall Of Fame CMS Most Promising Open Source Project Open Source E-Commerce Applications Open Source JavaScript Library Open Source Graphics Software
Resources
Open Source CMS Hall Of Fame CMS Most Promising Open Source Project Open Source E-Commerce Applications Open Source JavaScript Library Open Source Graphics Software