Pentaho 简明教程
Pentaho - Chart Report
chart ,也称为 graph ,是数据的图形表示形式。Pentaho Reporting Designer 提供了多种图表类型。您可以使用 Pentaho Reporting Designer 调色板中提供的 “chart-element” 选项设计图表。
A chart, also called a graph, is a graphical representation of data. Pentaho Reporting Designer offers a wide variety of chart types. You can design a chart using the “chart-element” option available in the palette of Pentaho Reporting Designer.
创建图表需要三个要求:
There are three requirements to create a chart −
-
A data-collector to extract the charting-data from the data sources.
-
A chart-expression to produce a chart from the collected data.
-
A report element to display the resulting chart object.
现在让我们举一个示例,尝试理解在 Pentaho 中创建图表的过程。
Let us now take an example and try to understand the process of creating charts in Pentaho.
下表包含有关三个汽车品牌特征的数据。我们将使用条形图描述这些数据。
The following table contains data regarding the features of three car brands. We will depict this data using a bar chart.
Car |
Speed |
User Rating |
Mileage |
Safety |
Fiat |
1 |
3 |
5 |
5 |
Audi |
5 |
6 |
10 |
4 |
Ford |
4 |
2 |
3 |
6 |
首先,根据给定的表数据创建一个名为 car 的表。我们使用 MySQL 数据库作为数据源。将该(数据源)添加到 Pentaho Reporting Designer。我们在 “Pentaho - Data Sources and Queries”(Pentaho - 数据源和查询)一章中已经讨论了如何向 Pentaho Reporting Designer 添加数据源和查询。
First of all, create a table named car based on the given table data. We are using MySQL database as the data source. Add that (data source) to the Pentaho Reporting Designer. We have already discussed how to add a data source and a query to the Pentaho Reporting Designer in the chapter "Pentaho – Data Sources and Queries".
Steps to Create a Chart in Pentaho
现在,按照给定的步骤基于给定场景创建图表。
Now, follow the steps given below to create a chart based on the given scenario.
Step 1 - Add a Query
查询将从表 car 中检索所有记录。因此,查询应该如下所示:
The query will retrieve all the records from the table car. Therefore the query should be as follows −
Select
car.id,
car.name,
car.speed,
car.user_rating,
car.millage,
car.safety
From
car
LIMIT
3
以下屏幕截图显示了如何将给定的查询添加到数据源中。
The following screenshot shows how to add the given query to the data source.

Step 2 - Add an Image to the Page Header
这是一个可选步骤,但很重要,因为图像在提升报表美观方面起着重要作用。
This is an optional step, however it is important because images play an important role in improving the aesthetics of a report.
查看以下屏幕截图。我们在此处重点介绍了以下五项活动:
Take a look at the following screenshot. We have highlighted the following five activities here −
-
After adding a query, you will find the query fields on the Structure pane. From the Structure pane, select the respective fields, drag and drop into the Details tab of the report workspace.
-
The Details tab presents only the field values. Add those respective heading Labels to the Report Header tab by selecting the label field from the palette.
-
Add an image taken from the palette and place it on the Page Header Tab. Add another label in the Page Header for Report Heading and use a suitable heading, for example CAR – CHART, for effective presentation. Double-click on the image element – you will find a dialogue box called Edit Content.
-
You have two options to insert an image. Either link the image URL to the report or embed the image into the report. We chose to embed the image by selecting the option “Embed in Report”.
-
Download some sample car image from the internet to put into the Page Header. Click on the button to locate the sample car image with the location URL. Click the OK button to confirm.

Step 3 - Add Chart into Report Footer
通过点击在左侧调色板中选择并将其拖到报表中来添加图表。它在以下屏幕截图中标记为“1”。双击报表页脚中的柱状图元素。
Add the chart by clicking select and dragging it from the left-side palette to the Report. It is marked as "1" in the following screenshot. Double-click on the Bar chart element on the Report Footer.

Step 4 - Add Chart Properties
在双击图表元素后,你将发现一个对话盒,其中你必须提供收集到的详细信息和图表表达式详细信息。
After double-clicking on the chart element, you will find a dialogue box where you have to provide the data collected details and chart expression details.
看看以下的屏幕截图。选项卡 Primary Data Source 包含两个标记 −
Take a look at the following screenshot. The tab Primary Data Source contains two markers −
-
Marker “1” is a dropdown list where you have to select the Category Set Data Collector.
-
Marker “2” is also a dropdown list of the category-column where you have to select the name field.

主数据源中有三个部分: Common 、 Series 和 Group 。在此,我们不需要在组部分中添加任何内容,因为我们在查询中未使用任何组。
There are three sections in the Primary Data Source − Common, Series, and Group. Here, we don’t require to add anything on the Groups section because we are not using any Groups in our query.
Common − 此部分中有两个字段 − category-column 和 value-column 。我们在上面的部分中,已经用 name 字段填充了类别列值。第二个是 value-column 。
Common − There are two fields in this section − category-column and value-column. We already filled the category-column value with the name field in the above section. The second one is value-column.
点击空值,你将找到一个对话框,如下面的屏幕截图所示。其中标记了两个活动(1 和 2)。
Click on the empty value; you will find a dialogue box as shown in the following screenshot. There are two activities (1 and 2) marked in it.
-
Click the (+) button to add the value fields in the column.
-
By clicking on the empty value, you will find a dropdown list from where you need to select the speed field.

重复上述两个活动来将用户评分、里程和安全字段添加到列中。在添加所有这些字段之后,屏幕将显示如所示。点击确定来确认。
Repeat the above two activities to add user_rating, mileage, and safety fields into the column. After adding all these fields, the screen will appear as shown below. Click OK to confirm.

主数据源部分中的下一列是序列部分。
The next column in the Primary Data source section is the Series section.
Series − 在序列字段中,点击按值分类选项。你将找到一个对话框,如下面的屏幕截图所示。其中有两个标记(1 和 2)。
Series − In the Series field, click the series-by-value option. You will find a dialogue box as shown in the following screenshot. There are two markers (1 and 2) in it.
-
Click the (+) button to add a new field in the column.
-
By double-clicking on it, you can edit that field.
针对诸如速度、用户评级、里程和安全等字段名称,重复这两项活动。
Repeat these two activities for adding field names such as Speed, User Rating, Mileage, and Safety.
这些是用户自定义名称,用于报告图表中的特定部分中显示。但此处需要按照 Common 部分中值列字段中指定的相同顺序。按照如下方式在所有字段添加后单击 OK 。
These are the user-defined names to present in the particular section of report chart. But here you have follow the same order that you have given on the Value-column fields in the Common section. Click OK after adding all the fields as shown below.

添加所有部分后,将会获得如以下屏幕截图中所示的 Edit Chart 对话框。 Bar Chart 窗格包含用于更改图表格式的不同属性。
After adding all the sections, you will get the Edit Chart dialogue box as shown in the following screenshot. The Bar Chart pane contains different properties which are used for changing the chart format.
在条形图的 General 部分中,我们已经将 3-D 值更改为 true (标记为“1”)。单击“确定”以确认图表属性。
In the General section of the Bar Chart, we have changed the 3-D value as true (marked as "1"). Click OK to confirm the chart properties.

单击格式化工具栏上的“预览”按钮,以查看报告预览。它将显示如下面的屏幕截图所示 −
Click on the Preview button on the Formatting Toolbar to see a preview of the report. It will appear as shown in the following screenshot −

可以通过使用不同类型的数据模型以及向图表属性提供不同的值,在报告中实现不同类型的图表。Pentaho 几乎在报告设计器中提供了 18 种类型的图表。
You can implement different types of charts in your report by using different types of data models and by providing different values to the chart properties. Pentaho provides almost 18 types of charts in the report designer.