Pentaho Reporting 3.5 for Java Developers

November 21, 2009

Java

«»

Common dataset properties

The following properties are common across all chart datasets:

Common category series dataset properties

The following properties are common across all charts that utilize category series
dataset for populating the chart:

Common XY series dataset properties

The following properties are common across all charts that utilize the XY series
dataset for populating a chart:

Now that you’ve reviewed the common set of properties for all charts, you’ll
begin to explore the individual charts, including going through their configurable
properties, as well as providing a quick example.

Area chart

The area chart displays a category dataset as a line, with the area underneath the line
filled in. Multiple areas may appear depending on the number of series provided.
The area chart is useful for visualizing the differences between two or more sets of
data. It utilizes the common properties defined in the previous tables, including the
category series common properties. The area chart defines no additional properties.

Area chart example

This example will demonstrate the area chart’s capabilities. First, you’ll need a rich
enough dataset to demonstrate this and all the other charts in this chapter. You’ll
reuse the ElectroBarn HSQLDB data source configured in Chapter 3. To begin,
launch Pentaho Report Designer and create a new report.

Now, select the Data tab. Right-click on the Data Sets tree element, and select the
JDBC data source. If ElectroBarn is not already configured as a connection type, click
the Connections add image button and fill in the following values, customizing the
database location for your particular environment:

Click the Test button to verify your connection, and then click OK when you
are done.

You need to define a SQL statement to populate your chart. You’ll define a
simple query that takes a look at the inventory data. Add a new query with the
following SQL code:


	SELECT
		"INVENTORY"."ITEMCATEGORY",
		"INVENTORY"."SALEPRICE",
		"INVENTORY"."COST"
	FROM
		"INVENTORY"
	ORDER BY
		"INVENTORY"."ITEMCATEGORY" ASC

Click OK. You’re now ready to add a chart to your empty report. For this example,
select the Chart report element from the palette and drag it into the Report
Header
. Double-click on the chart, or right-click on the chart and select Chart….
Once the Edit Chart dialog appears, select the Area Chart .

In the Primary DataSource tab, select the ITEMCATEGORY data field as your
category-column. For your value-columns, select SALEPRICE and COST. Enter the
strings Sale Price and Cost as the series–by-value values. When rendering an
area chart, the order of value columns is important. If a larger value is rendered after
a smaller value, the smaller value will not appear on the chart.

Once you configured the data for the chart, you can also make some customizations
to the rendering. Set horizontal to True, as well as specifying the bg-color as yellow.
Finally, set the show-legend property to True. Click the OK button and then
preview your report to see the results!

Bar chart

The bar chart displays individual bars broken out into individual categories and
series. Bar charts are useful for comparing relative sizes of data across categories.
The bar chart utilizes the common properties defined earlier, including the category
series common properties.

The bar chart defines the following additional rendering properties:

Bar chart example

You’ll now build an example bar chart. Create a new report with the ElectroBarn
data source, and use the following SQL query, which investigates purchase quantity
and payment type:


	SELECT
		"INVENTORY"."ITEMCATEGORY",
		"PURCHASES"."PAYMENTTYPE",
		"PURCHASEITEMS"."QUANTITY"
	FROM
		"PURCHASES" INNER JOIN "PURCHASEITEMS" ON
			"PURCHASES"."PURCHASEID" = "PURCHASEITEMS"."PURCHASEID"
		INNER JOIN "INVENTORY" ON "PURCHASEITEMS"."ITEMID" =
			"INVENTORY"."ITEMID"
	ORDER BY
		"INVENTORY"."ITEMCATEGORY" ASC,
		"PURCHASES"."PAYMENTTYPE" ASC

Place a Chart element in the Report Header of the report, selecting bar as its type.
To begin, configure the dataset properties for your bar chart. Set category-column to
ITEMCATEGORY, value-columns to QUANTITY, and series-by-field to PAYMENTTYPE. By
setting the series-by-field property, the chart will create a series for each PAYMENTTYPE
in the dataset.

Now, you’ll customize the look of your chart. First, set the X-Axis show-labels
property to True and text-format to {2}. This will display the value of each bar at
the top of the bar. Then set max-label-width to 2.0, so that you can easily see all the
category names in the chart. Finally, set the show-legend to True, in order to see what
types of payments map to which bar color. You’re now ready to preview your chart!

Line chart

The line chart displays connected lines between categories for each series provided.
This chart is useful for visualizing trends. The line chart utilizes the common
properties defined in the previous tables, including the category series common
properties. The line chart defines the following additional rendering properties:

Note that the stacked and stacked-percent properties do not apply to the line
chart type.

Line chart example

In this example, reuse the SQL query and dataset sections from your area chart
example. Select the Line chart type, and customize the chart with show-markers
set to True as well as line-size set to 4.0. The result should look like this:

email

«»

Comments

comments