Pentaho技术白皮书中文版(四)--创建 dashboards

这篇文档描述了如何使用 Pentaho BI 套件创建 dashboards。它描述了 Pentaho Demo 服务器提供的sample dashboard。

sample dashboard 以 JSP 和 PHP 形式提供。两个 dashboards 均使用相同的内容,提供相同的功能。JSP 实例显示了如何在 Pentaho UI 组件中使用 Java API,PHP 实例显示了如何在 Pentaho UI 组件中使用 Web 服务。

Java API 实例可用于 JSPs,Servlets,或 Java 应用。Web 服务实例可用于可发布 web 服务调用的任何技术,例如 PHP,IBM Domino 等。

1. Sample Dashboard

This page last changed on Mar 01, 2007 by wgorman.

Sample Dashboard 位于这个 URL (假设你将 Pentaho demo 安装于你本机的 8080 端口) 。http://localhost:8080/pentaho/jsp/SampleDashboard

sample dashboard 首先显示了一张饼图,其显示了四个区域中每个的 headcount costs。

关于如何定义饼图的更多信息请参考下面的 ‘Headcount Spending by Region Pie Chart’。

关于如何获得饼图的数据的更多信息请参考下面的 ‘Headcount Spending by Region Action Sequence’。

当用户点击饼图上的一个切片时,出现了另一张图表,对于选中的区域的每个部门,显示了 headcount budget 和 actual cost 间的不同。

饼图如何被定义的更多信息请参考下面的 ‘Headcount Variance Pie Chart’。

如何获取饼图的数据的更多信息请参考下面的 ‘Headcount Variance Action Sequence’。

当用户点击一个部门的 bar 时,dashboard 在图表下,显示了一个 dial 和一个数据表。dial 基于当前时间(因此它随着时间改变) 显示了一个值,表显示了选中部门内的 positions 的详细信息。

如何定义 dial 的更多信息请参考下面的 ‘动态 Dial’。

如何定义嵌入式报表的更多信息请参考下面的 ‘嵌入式报表’。

当用户点击表中的一个 position 的名字时,dashboard drills 到另一个页面,并传送 region,department 和 position 作为参数。

这一页的源代码请参考附录 8:Drill JSP

2. 体系结构

This page last changed on Dec 04, 2006 by mdamour.

3. 内容定义

This page last changed on Dec 04, 2006 by mdamour.

动态 Dial

This page last changed on Dec 05, 2006 by mdamour.

这个 dial 的定义在 pentaho-demo/pentaho-solutions/samples/dashboard/sampledial.widget.xml

这个 XML 文件定义了:

 

设置

描述

widget/dial/units

units of dial value

$

widget/dial/plot-background/text

dial area 的 re-image 背景

/samples/portal/dial_03 .gif

widget/dial/tick-interval

gap between ticks

5

widget/dial/tick-color

ticks 的颜色

#808080

widget/dial/needle-color

Needle 的颜色

#808080

widget/dial/chart-background/texture-image

Background chart image

/samples/portal/dial_03 .gif

widget/dial/interval/label

Interval name

'under'

widget/dial/interval/minimum

Interval lower limit

-15

widget/dial/interval/maximum

Interval upper limit

0

widget/dial/interval/color

Interval background color

#FFFFFF

widget/dial/interval/text-color

Interval text and tick color

#40BB40

widget/dial/interval/stroke-width

Interval line thickness

5

 

注意在文件中定义了两个 intervals:一个覆盖了从 -15 到 0 的范围,另一个是 0 到 +15。

除了在 widget XML 文件中定义的这些设置,caller 还指定了这些设置:

 

设置

描述

title

dial 的标题

'My Dial'

value

Dial 上显示的值

Varies over time from -10 to +15

image-width

dial image 的宽度

105

image-height

dial image 的高度

105

 

在 sample dashboard 中,基于当前时间,页面为 dial 创建了一个值。

嵌入式报表

This page last changed on Jan 30, 2007 by wgorman.

报表模版的定义在:pentaho-demo/pentaho-solutions/samples/dashboard/jsp/embedded_report.xml

报表模版被报表引擎(JFreeReport) 用于布局嵌入式报表。你可使用 Pentaho Report Wizard 设计一个报表定义。

你创建的是 HTML 的一个片段,而不是一个完整的 HTML 页面。你需要编辑报表定义 XML 文件以在 report/configuration 的报表配置区域添加一个属性。

="org.jfree.report.modules .output .table.html.BodyFragment">true

为将报表内容中的一个 drill link 添加进一个 URL,你需要编辑报表定义,并添加一个 URL 表达式,例如 sample dashboard 中的这个。

="URLCreateExpression"

class="org. jfree.report.function.TextFormatExpression">

name="pattern">SampleDrill? region={ 0} &position={ 1} & department={ 2}

="field[ 0] ">REGION

POSITIONTITLE DEPARTMENT

Headcount Spending By Region Pie Chart

This page last changed on Jan 30, 2007 by wgorman.

这张饼图的定义在: pentaho-demo/pentaho-solutions/samples/dashboard/regions.widget.xml

这个 XML 文件定义了:

设置

描述

chart/title

图的标题

Headcount Spending by Region

chart/title-position

图的标题的位置(上,下,左或右)

top

chart/title-font/font-family

标题字体的名字

Ariel

chart/title-font/size

标题字体的大小

20

chart/title-font/is-bold

标题字体是粗体么?

false

chart/title-font/is-italic

标题字体是斜体么?

false

chart/is-3D

饼图是 3D 的么?

false

chart/border-visible

Does chart have a border?

false

chart/include-legend

Does chart have a legend?

false

chart/data/data-solution

solution for action sequence providing data for this chart

samples

chart/data/data-path

action sequence 的路径

dashboard

chart/data/data-action

action sequence 的名字

regions_headcount_data.xaction

chart/data/data-output

action sequence 输出

rule-result

chart/data/data-name

包含 pie slice 名称的数据列

REGION

chart/data/data-value

包含 pie slice 值的数据列

ACTUAL

chart/data/data-orientation

direction in which to process data to get pie slices (rows/columns)

rows

 

除了 widget XML 中定义的这些设置,调用者还可指定这些设置:

 

设置

描述

drill-url

用于生成 drill 路径的一个 URL 模版。URL 可有包含在 ‘{‘ and ‘}’中的可替换参数。

SampleDashboard?region={REGION}

inner-param

在 URL 中包含将被替换的值的数据列

 

REGION

chart 组件从这个文件中读取所有的设置,然后执行指定的 action sequence 为图表获取数据。sample dashboard 中的 action sequences 仅使用一个单一的组件生成数据,但是 BI 组件的任何序列可用来执行复杂的(例如 scripting 或 in-line ETL) 或远程的(例如 Web 服务) 任务。

Headcount Variance Bar Chart

This page last changed on Jan 30, 2007 by wgorman.

这个 bar chart 的定义在:

pentaho-demo/pentaho-solutions/samples/dashboard/departments.widget.xml

这个 XML 文件定义了:

 

 

设置

描述

 

chart/type

图的类型(BarChart, LineChart, AreaChart)

BarChart

 

chart/title

图的标题

Headcount Variance

 

chart/title-position

图的标题的位置(上,下,左,右)

top

 

chart/title-font/font-family

标题字体的名字

Ariel

 

chart/title-font/size

标题字体的大小

20

 

chart/title-font/is-bold

图的标题是粗体么?

false

 

chart/title-font/is-italic

图的标题是斜体么?

false

 

chart/is-3D

图是 3D 的么?

false

 

chart/border-visible

Does chart have a border?

false

 

chart/include-legend

Does chart have a legend?

false

 

chart/chart-background

chart image 的背景。你可定义gradients, textures,images 或flat colors

type=color #FFFFFF

 

chart/plot-background

plot area 的背景

type=color #EEEEEE

 

chart/orientation

chart 的方向(垂直或水平)

horizontal

 

chart/is-stacked

Is chart stacked?

false

 

chart/color-palette/color

color to use for first series

#336699

 

chart/color-palette/color

color to use for second series

#99CCFF

 

chart/data/data-solution

solution for action sequence providing data for this chart

Samples

 

chart/data/data-path

action sequence 的路径

dashboard

 

chart/data/data-action

action sequence 的名字

regions_headcount_data.xaction

chart/data/data-output

action sequence 的输出

rule-result

 

chart/data/data-name

包含 pie slice names 的数据列

REGION

 

chart/data/data-value

包含 pie slice values 的数据列

ACTUAL

 

chart/data/data-orientation

direction in which to process data to get pie slices (rows/columns)

rows

 

             

 

除了在 widget XML 文件中定义的这些设置,caller 还指定了这些设置:

设置

描述

drill-url

一个 URL 模版用于生成 drill 路径。URL 可有包含在 ‘{‘ and ‘)’ 中的可替换的参数

SampleDashboard?region=Central&

inner-param

data column containing values to be replaced in URL

DEPARTMENT

REGION

在查询中用来选择数据的过滤器

Dynamically set e.g. 'Eastern'

image-width

chart image 的宽度

450

image-height

chart image 的高度

300

REGION 参数被传送进 action sequence 用作一个查询查询过滤器。

4. Action Sequences

This page last changed on Dec 04, 2006 by mdamour.

嵌入式报表 Action Sequence

This page last changed on Dec 04, 2006 by mdamour.

这个报表的定义在: pentaho-demo/pentaho-solutions/samples/dashboard/jsp/embedded_report.xaction

你可以在 Eclipse IDE 中使用 Pentaho Design Studio 编辑这个文件。这个 action sequence 包含一个 JFree Report 组件,其从 sample 数据库获取数据,使用一个报表模版生成一个HTML 片段。

action sequence 带有参数 ‘region’ 和 ‘department’,其用作查询中的过滤器。报表组件执行这个查询:

select QUADRANT _ACTUALS . REGION, QUADRANT _ACTUALS . DEPARTMENT, QUADRANT _ACTUALS . POSITIONTITLE,

QUADRANT _ACTUALS . ACTUAL, QUADRANT _ACTUALS . BUDGET,QUADRANT _ACTUALS.VARIANCE

from QUADRANT _ACTUALS

where QUADRANT _ACTUALS.REGION = '{region}'

and QUADRANT _ACTUALS.DEPARTMENT = '{department}'

order by QUADRANT _ACTUALS.REGION, QUADRANT_ACTUALS. DEPARTMENT

使用一个报表模板:pentaho-demo/pentaho-solutions/samples/dashboard/jsp/embedded_report.xml (参考上面的嵌入式报表)

报表组件在一个名为 ‘report’ 的输出中返回 HTML,action sequence 将这个输出转向到 response 的 output stream。

Headcount Spending by Region Action Sequence

This page last changed on Dec 04, 2006 by mdamour.

这个 action sequence 的定义在: pentaho-demo/pentaho-solutions/samples/dashboard/regions_headcount_data .xaction

你可以在 Eclipse IDE 中使用 Pentaho Design Studio 以编辑这个文件。

这个 action sequence 包含一个 SQL Query Rule,其从 Pentaho demo 服务器提供的 sample 数据库获取一些数据。action sequence 不带任何参数。

SQL Query Rule 执行这个查询:

select REGION, sum(ACTUAL) as ACTUAL

from quadrant _actuals

group by REGION order by ACTUAL

并在一个名为 ‘rule-result’ 的输出中返回数据。这个数据用于生成 ‘Headcount Spending By Region’ 饼图。

Headcount Variance Action Sequence

This page last changed on Dec 04, 2006 by mdamour.

这个 action sequence 的定义在:pentaho-demo/pentaho-solutions/samples/dashboard/department_variance_data .xaction

你可以在 Eclipse IDE 中使用 Pentaho Design Studio 以编辑这个文件。

这个 action sequence 包含一个 SQL Query Rule,其从 Pentaho demo 服务器提供的 sample 数据库获取一些数据。

action sequence 带有一个参数 REGION,其在查询中用作过滤器,SQL Query Rule 执行这个查询:

select department, sum(variance) from quadrant _actuals

where region='{ REGION}'

group by department

在名为 ‘rule-result’ 的输出中返回数据。这个数据用于生成 ‘Headcount Variance By Region’ 饼图。

5. 定制 PCI JSP Dashboard

This page last changed on Feb 01, 2007 by wgorman.

实例 1: 将饼图变成柱状图

这个实例描述了在 SampleDashboard solution 中,将一个饼图转换成一个柱状图所需要进行的修改。为了修改,必须同时更新 widget xml 和 SampleDashboard.jsp 中的 java 代码。

步骤 1: 更新 SampleDashboard. jsp 文件

不要调用 ChartHelper.doPieChart(),而是对 ChartHelper.doChart() 进行 java调用。方法标识是一样的, 包括 widget xml 的位置,可定制参数,输出要写进的 string buffer,user session,存储消息的 messages 对象,和一个 logger 对象(如果可用)。

修改 widget.xml 指向我们的新 _regions.widget.xml 文件,其在下一步被创建。

柱状图稍不同于饼图,当涉及到它们的 templated inner param 时。用 "{SERIES}" 替换 "drill-url" 参数的 "{REGIONS}" 部分,其允许图表适当生成 outgoing 链接。

步骤 2: 创建 new_regions .widget.xml 文件

饼图和柱状图  xml 文件包含用于定制的不同参数集合。不需要检查所有参数,将departments .widget.xml 复制到新的 _regions.widget.xml文件,其是一个预存在的柱状图实例。

注意 chart-type 元素,以及各种用于定制柱状图的 style 元素。将 title 元素修改回 "Headcount Spending by Region",data -> data-action 元素修改回 "regions_headcount_data.xaction"。现在我们就有一个配置好的柱状图了。

注意:你必须在 admin 工具中刷新 solution repository,使得对于 widget 的修改生效。

实例 2: Swapping Regions  Departments

这个实例描述了在 dashboard 中 swapping regions with departments。

步骤 1: 更新 SampleDashboard.jsp 文件

如果你从上面的实例 1 开始操作的,从实例中删除对于 JSP 的修改。

替换这段代码:

String title = "Select a region";

if( department != null ) {

title = "This is headcount spending for " + region + ", " + department;

}

else if ( region != null ) {

title = "This is headcount spending for " + region;

}

用这段代码:

String title = "Select a department";

if( region != null ) {

title = "This is headcount spending for " + department + ", " + region;

}

else if ( department != null ) {

title = "This is headcount spending for " + department;

}

为将 region pie chart 改成 departments:

用 "Select a Department By Clicking on Pie Chart" 替换 "Select a Region By Clicking on Pie Chart"。

用 "SampleDashboard?department= {DEPARTMENT}" 替换 "SampleDashboard?region ={REGION}"。

替换这行:

parameters.setParameter( "inner-param", "REGION");

用:

parameters.setParameter( "inner-param", "DEPARTMENT");

用 "new_departments.widget.xml" 替换 "regions.widget.xml"。

为将 department bar chart 改变成 regions:

替换这行:

if( region != null ) {

用:

if( department != null ) {

用 "Select a Region By Clicking on Bar Chart" 替换 "Select a Department By Clicking on Bar Chart "。

替换这行:

parameters. setParameter ( "drill-url", "SampleDashboard? region="+region+"&department={ SERIES}" );

用:

parameters. setParameter ( "drill-url",

"SampleDashboard? department="+department+"®ion={ SERIES} " );

替换这行:

parameters.setParameter( "REGION", region );

用:

parameters.setParameter( "DEPARTMENT", department );

替换这行:

parameters.setParameter( "outer-params", "REGION" );

用:

parameters. setParameter ( "outer-params", "DEPARTMENT" );

替换这行:

parameters.setParameter( "inner-param", "DEPARTMENT");

用:

parameters.setParameter( "inner-param", "REGION");

用 "new_regions.widget.xml" 替换 "departments.widget.xml"。

替换包含这句的两行:

if( department != null ) {

用:

if( region != null ) {

步骤 2: 创建 new_departments.widget.xml 文件

复制 regions.widget.xml 文件成新的 _departments.widget.xml。

用 "Headcount Spending by Department" 替换 "Headcount Spending by Region"。

用 "departments_headcount_data.xaction" 替换 "regions_headcount_data .xaction"。

替换这句:

REGION< / data-name>

用:

DEPARTMENT< / data-name>

步骤 3: 创建 departments_headcou nt_data.xaction 文件

复制 regions _headcount _data.xaction 文件成 departments _headcount _data.xaction。

用 "Return actual headcount costs total for each department" 替换 "Return actual headcount costs total for each region"。

替换 SQL 查询:

select REGION, sum(ACTUAL) as ACTUAL from QUADRANT _ACTUALS group by REGION order by ACTUAL

用:

select DEPARTMENT, sum(ACTUAL) as ACTUAL from QUADRANT _ACTUALS group by DEPARTMENT order by ACTUAL

步骤 4: 创建 new_regions.widget.xml 文件

将文件 departments.widget.xml 复制成新的 _regions.widget.xml 文件。替换这句:

department _variance _data. xaction

用:

region _variance _data. xaction

步骤 5: 创建 region_variance_data.xaction 文件

复制 department _variance _data.xaction 文件成 region _variance _data.xaction。

用 "Return variance between headcount actual and budget for every region in specified department" 替换 "Return variance between headcount actual and budget for every department inspecified region"。

替换:

REGION

用:

DEPARTMENT< /request> 

用 "Define an input called 'DEPARTMENT'." 替换 "Define an input called 'REGION'."。

替换

用:

替换 SQL 查询:

select department, sum(variance) from QUADRANT _ACTUALS where region in ( {PREPARE:REGION} )

group by department

用:

select region, sum(variance) from QUADRANT _ACTUALS where department in ( {PREPARE:DEPARTMENT} ) group by region

附录01 Dashboard JSP

This page last changed on Jan 30, 2007 by wgorman.

这是 JSP Sample Dashboard 的源代码:

<%@ page language="java"

import="java.util.ArrayList,

java.util.Date,

java.io.ByteArrayOutputStream,

org.pentaho.core.ui.SimpleUrlFactory,

org.pentaho.messages.Messages,

org.pentaho.core.system.PentahoSystem,

org.pentaho.ui.component.DashboardWidgetComponent,

org. pentaho.core. solution. HttpRequestParameterProvider, org.pentaho.core.solution.HttpSessionParameterProvider,

org.pentaho.core.session.IPentahoSession,

org.pentaho.core.util.UIUtil,

org.pentaho.util.VersionHelper,

org.pentaho.messages.util.LocaleHelper,

org.pentaho.core.solution.ActionResource,

org.pentaho.core.solution.IActionResource,

org.pentaho .core. solution. SimpleParameterProvider, org.pentaho.ui.ChartHelper,

java. io .*"

%><%

/*

*    Copyright 2006 Pentaho Corporation. All rights reserved.

*    This software was developed by Pentaho Corporation and is provided under the terms

*    of the Mozilla Public License, Version 1.1, or any later version. You may not use

*    this file except in compliance with the license. If you need a copy of the license,

*    please go to http://www.mozilla.org/MPL/MPL-1.1.txt. The Original Code is the Pentaho

*    BI Platform. The Initial Developer is Pentaho Corporation.

*

*    Software distributed under the Mozilla Public License is distributed on an "AS IS"

*    basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. Please refer to

*    the license for the specific language governing your rights and limitations.

*

*    Created Feb 16, 2006

*    @author James Dixon

*/

/*

*    This JSP is an example of how to use Pentaho components to build a dashboard.

*    The script in this file controls the layout and content generation of the dashboard.

*    See the document 'Dashboard Builder Guide' for more details

*/

// set the character encoding e.g. UFT-8

response. setCharacterEncoding (LocaleHelper.getSystemEncoding ());

// get the current Pentaho session or create a new one if needed

IPentahoSession userSession = UIUtil.getPentahoSession( request );

%>

Pentaho Sample Dashboard - JSP

<%

// See if we have a 'department' parameter String department = request.getParameter ("department"); // See if we have a 'region' parameter

String region = request.getParameter("region");

// Create the title for the top of the page

String title = "Select a region"; if( department != null ) {

title = "This is headcount spending for " + region + ", " + department;

}

else if ( region != null ) {

title = "This is headcount spending for " + region;

}

%>

<%= title %>

Select a Region By Clicking on the Pie Chart

<%

// Make a pie chart showing the regions // create the parameres for the pie chart

SimpleParameterProvider parameters = new SimpleParameterProvider();

// define the click url template

parameters.setParameter( "drill-url", "SampleDashboard?region={ REGION} " );

// define the slices of the pie chart

parameters. setParameter ( "inner-param", "REGION"); //$NON-NLS-1$ //$NON-NLS-2$

// set the width and the height

parameters. setParameter ( "image-width", "450") ; //$NON-NLS-1$ //$NON-NLS-2$ parameters.setParameter( "image-height", "300"); //$NON-NLS-1$ //$NON-NLS-2$ StringBuffer content = new StringBuffer();

ArrayList messages = new ArrayList();

// call the chart helper to generate the pie chart image and to get the HTML

content

// use the chart definition in 'samples/dashboard/regions.widget.xml' ChartHelper.doPieChart ( "samples", "dashboard", "regions .widget.xml", parameters, content, userSession, messages, null );

%>

<%= content.toString() %>

<%

if( region != null ) {

// if the user has clicked on a slice of the pie chart we should have a

region to work with

%>

Select a Department By Clicking on the Bar Chart

<%

// Make a bar chart showing the department

// create the parameres for the bar chart

parameters = new SimpleParameterProvider();

// define the click url template

parameters. setParameter ( "drill-url",

"SampleDashboard? region="+region+"& department={ SERIES} " );

parameters.setParameter( "REGION", region );

parameters.setParameter( "outer-params", "REGION" );

// define the category axis of the bar chart

parameters. setParameter ( "inner-param", "DEPARTMENT"); //$NON-NLS-1$

// $NON-NLS-2 $

// set the width and the height

parameters. setParameter ( "image-width", "450") ; //$NON-NLS-1$ //$NON-NLS-2$ parameters.setParameter( "image-height", "300"); //$NON-NLS-1$ //$NON-NLS-2$ content = new StringBuffer();

messages = new ArrayList();

// call the chart helper to generate the pie chart image and to get the

HTML content

// use the chart definition in 'samples/dashboard/regions.widget.xml'

ChartHelper.doChart ( "samples", "dashboard", "departments .widget.xml", parameters, content, userSession, messages, null );

%>


<%= content.toString() %>

<%

}

%> 

size="1"/>

="top">="font-family:Arial; font-weight :bold">

<%

if( department != null ) {

// if the user has clicked on a bar of the bar chart we should have a region and department to work with

// create a dial and supply a value we create from the current time

Date now = new Date();

int seconds = now.getSeconds();

// create a value from -15 to +15

int dialValue = -15+seconds/2;

// create the parameres for the bar chart

parameters = new SimpleParameterProvider();

// set the value displayed on the dial

parameters. setParameter ( "value", ""+dialValue );

// set the title for the dial

parameters.setParameter( "title", "My Dial" );

// set the width and the height

parameters. setParameter ( "image-width", "105") ; //$NON-NLS-1$ //$NON-NLS-2$ parameters.setParameter( "image-height", "105"); //$NON-NLS-1$ //$NON-NLS-2$ content = new StringBuffer();

messages = new ArrayList();

// call the chart helper to generate the pie chart image and to get the

HTML content

// use the chart definition in 'samples/dashboard/regions.widget.xml'

ChartHelper.doDial ( "samples", "dashboard", "sampledial.widget .xml", parameters, content, userSession, messages, null );

%>

The value of this dial is based on the current time

<%= content.toString() %>

<%

}

%>

<%

if( department != null ) {

// if the user has clicked on a bar of the bar chart we should have a region and department to work with

// run a report and embed the content into this page

// create the parameres for the report

parameters = new SimpleParameterProvider();

// pass the region and department to the report parameters.setParameter( "region", region );

parameters.setParameter( "department", department ); // create an output stream for the report content

ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); messages = new ArrayList();

// run the action sequence 'samples/dashboard/jsp/report.xaction'

ChartHelper.doAction ( "samples", "dashboard/jsp", "embedded_report .xaction",

"SampleDashboard", parameters, outputStream , userSession, messages, null ); // write the report content into this page

%>

Click on a position title to drill to another page 

<% out.write( outputStream.toString() ); %>

<%

}

%>

附录02 Pie Chart 定义

This page last changed on Jan 30, 2007 by wgorman.

 Headcount Spending by Region  none  

Ariel< /font-family> 20

false

false

450

300

  fal s e< / is-3D>

false #bbbbff

false

 samples dashboard

regions_headcount_data.xaction

 rule-result POSITIONTITLE

ACTUAL< /data-value>

 columns

附录03 Region 数据

This page last changed on Jan 30, 2007 by wgorman.

1< /vers ion>

Regions and departments debug

James Dixon

Return the actual headcount costs total for each region

list< / type>

 

  SQLLookupRule< / component-name> rule

SampleData

select REGION, sum(ACTUAL)

from quadrant _actuals

group by REGION order by ACTUAL]]>

附录04 Department Bar Chart 定义

This page last changed on Jan 30, 2007 by wgorman.

 BarChart

Headcount Variance

TOP  

Ariel< /font-family>

20

false false

#FF80FF

#FFFF00< /plot-background-color>

Ho ri z ontal< / orientation> 

fal s e< / is-3D>

false

true #000000

 true 

#336699 #99CCFF #999933 #666699 #CC9933 #006666 #3399FF #993300 #CCCC99 #666666 #FFCC66 #6699CC#663366

 samples

dashboard department_variance_data.xaction

 rule-result

 rows< /data-orientation>

附录05 Department Variance 数据

This page last changed on Jan 30, 2007 by wgorman.

这个 action sequence 指定一个 SQL 查询,获取一个指定区域的每个部门的 headcount 的真实值和预算的差值。

action sequence 定义于:

~/pentaho-demo/pentaho-solutions/samples/dashboard/department_variance_dial .xaction.

使用 Pentaho BI Studio

="1 .0" encoding="UTF-8"?> 

1< /vers ion>

Regions and departments debug

James Dixon

Return the variance between headcount actual and budget for every

department in the specified region just testing. . .

>

REGION 

list< / type>

="string"/>

SQLLookupRule rule 

SampleData

附录06 Dial 定义

This page last changed on Jan 30, 2007 by wgorman.

Gauge 1

$

="texture"> /samples/portal/dial_03.gif 

5 #9 999bb #808080

#808080 "texture">

/samples/portal/dial_03.gif 

-1 5

0

#ffffff

#40bb40

5

0

15

#ffffff

#bb4040 5 

附录07 嵌入式报表模板

This page last changed on Jan 30, 2007 by wgorman.

1< /vers ion>

JFreeReport HTML Example debug

James Dixon 

This is an example of an HTML report produced by JFreeReport.

It shows the actual headcount cost, budgeted headcount

cost, and variance for every position in the specified

department and region ] ] >

/style/icons/jfree1 .png

region


department

 

content

 

 

embedded_report.xml

text/xml

 

 

="string"/>

 JFreeReportComponent< /component -name> report

false

SampleData

sql

html< / output-type>

附录08 Drill JSP

This page last changed on Jan 30, 2007 by wgorman.

<%@ page language="java"

import="java.util.ArrayList,

java.util.Date,

java.io.ByteArrayOutput Stream,

org.pentaho.core.ui.SimpleUrlFactory,

org.pentaho.messages.Messages,

org.pentaho.core.system.PentahoSystem,

org.pentaho.ui.component.DashboardWidgetComponent,

org. pentaho .core. solution. HttpRequestParameterProvider, org. pentaho.core.solution.HttpSessionParameterProvider,org. pentaho.core.session.IPentahoSession,

org.pentaho.core.util.UIUtil,

org.pentaho.util.VersionHelper,

org.pentaho.messages.util.LocaleHelper,

org.pentaho.core.solution.ActionResource,

org.pentaho.core.solution.IActionResource,

org.pentaho .core. solution. SimpleParameterProvider, org. pentaho.ui.ChartHelper,

java. io .*"

%><%

/*

*    Copyright 2006 Pentaho Corporation. All rights reserved.

*    This software was developed by Pentaho Corporation and is provided under the terms

*    of the Mozilla Public License, Version 1.1, or any later version. You may not use

*    this file except in compliance with the license. If you need a copy of the license,

*    please go to http://www.mozilla.org/MPL/MPL-1.1.txt. The Original Code is the Pentaho

*    BI Platform. The Initial Developer is Pentaho Corporation.

*

*    Software distributed under the Mozilla Public License is distributed on an "AS IS"

*    basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. Please refer to

*    the license for the specific language governing your rights and limitations.

*

*    Created Feb 16, 2006

*    @author James Dixon

*/

/*

This JSP page is part of the Pentaho samples that show how JSP can be

used to present and control content that is generated by the Pentaho BI Platform.

This JSP page is the page that is used after a user clicks on a link in the embedded report that is displayed in SampleDashboard.jsp.

The region, department, and job position title are passed in as parameters on the URL The url is formatted in the report definition file: ~/pentaho-demo/pentaho-solutions/samples/dashboard/j sp/embedded _report .xml

The url is set in the last function that is defined in the file. The important line is the "pattern"

class="org. jfree.report . function.TextFormatExpression">

name="pattern">SampleDrill? region={ 0} &position={ 1} & department={ 2}

="field[ 0] ">REGION

POSITIONTITLE

="field[ 2] ">DEPARTMENT

 

You can change the url template to point to wherever you need it to

*/

String region = request.getParameter("region");

String department = request.getParameter("department"); String position = request.getParameter ("position");

%>

Pentaho Regional Report - JSP Sample

="font-family:Arial">Drill Destination

The selected region is '<%= region %>'

The selected department is '<%= department %>'

The selected position is '<%= position %>'

附录09 Steel Wheels JSP

This page last changed on Jan 30, 2007 by wgorman.

*    <%@ page language="java"

import="java.util .ArrayList,

java .util .Date,

java. io. ByteArrayOutput Stream,

org. pentaho . core. ui . SimpleUrlFactory,

org.pentaho .messages .Messages,

org. pentaho . core. system. PentahoSystem,

org. pentaho . ui.component. DashboardWidgetComponent,

org. pentaho .core. solution. HttpRequestParameterProvider, org. pentaho .core. solution. HttpSessionParameterProvider, org. pentaho .core. session. IPentahoSession,

org. pentaho .core. util . UIUtil,

org. pentaho . util .VersionHelper,

org. pentaho .mes sages. util . LocaleHelper,

org. pentaho .core. solution .ActionResource,

org. pentaho .core. solution. IActionResource,

org. pentaho .core. solution. SimpleParameterProvider, org. pentaho . ui. ChartHelper,

java. io .*"

%><%

/*

*    Copyright 2006 Pentaho Corporation. All rights reserved.

*    This software was developed by Pentaho Corporation and is provided under the terms

*    of the Mozilla Public License, Version 1.1, or any later version. You may not use

*    this file except in compliance with the license. If you need a copy of the license,

*    please go to http://www.mozilla.org/MPL/MPL-1.1.txt. The Original Code is the Pentaho

*    BI Platform. The Initial Developer is Pentaho Corporation.

*

*    Software distributed under the Mozilla Public License is distributed on an "AS IS"

*    basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. Please refer to

*    the license for the specific language governing your rights and limitations.

*

*    Created Feb 16, 2006

*    @author James Dixon modified by Kurtis Cruzada

*/

/*

*    This JSP is an example of how to use Pentaho components to build a dashboard.

*    The script in this file controls the layout and content generation of the dashboard.

*    See the document 'Dashboard Builder Guide' for more details

*/

// set the character encoding e.g. UFT-8

response. setCharacterEncoding (LocaleHelper.getSystemEncoding ());

*    // create a new Pentaho session

IPentahoSession userSession = UIUtil.getPentahoSession( request );

%>

*    

Pentaho Sample Dashboard - JSP

<%

// See if we have a 'territory' parameter

String territory = request.getParameter("territory"); // See if we have a 'productline' parameter

String productline = request.getParameter ("productline");

// Create the title for the top of the page

String title = "Revenue Analysis";

if( productline != null ) {

title = "Sales for " + territory + ", " + productline;

}

else if ( territory != null ) {

title = "Sales for " + territory;

%>

="75%">="/sw-style/active/logo.png" border="0" />  ="right" style="font-family:Arial; font-weight:bold"

background="/sw-style/active/banner.png" valign="top" width="25%"><%= title %>

="right" valign="top" width="25%">

<%

// Make a pie chart showing the territories // create the parameres for the pie chart

SimpleParameterProvider parameters = new SimpleParameterProvider();

// define the click url template

parameters.setParameter( "drill-url", "SWDashboard?territory={ TERRITORY} " );

// define the slices of the pie chart

parameters. setParameter ( "inner-param", "TERRITORY"); //$NON-NLS-1$ //$NON-NLS-2$

// set the width and the height

parameters. setParameter ( "image-width", "350") ; //$NON-NLS-1$ //$NON-NLS-2$ parameters.setParameter( "image-height", "200"); //$NON-NLS-1$ //$NON-NLS-2$ StringBuffer content = new StringBuffer();

ArrayList messages = new ArrayList();

// call the chart helper to generate the pie chart image and to get the HTML

content

// use the chart definition in 'samples/dashboard/territory.widget.xml' ChartHelper.doPieChart ( "samples/steel-wheels", "dashboards", "territory.widget.xml",

parameters, content, userSession, messages, null ); %>

<%= content.toString() %>

(Click

on a Territory)

="top" align="center">

<%

if( territory == null ) {

// if the user has clicked on a slice of the pie chart we should have a

territory to work with

%>

<%

// Make a bar chart showing the department

// create the parameres for the bar chart

parameters = new SimpleParameterProvider();

// define the click url template

parameters. setParameter ( "drill-url",

"SWDashboard? territory="+territory+"&productline={ SERIES} " );

parameters.setParameter( "TERRITORY", territory );

parameters. setParameter ( "outer-params", "TERRITORY" );

// define the category axis of the bar chart

parameters. setParameter ( "inner-param", "TERRITORY"); //$NON-NLS-1$

//$NON-NLS-2$

parameters. setParameter ( "inner-param", "PRODUCTLINE"); //$NON-NLS-1$

//$NON-NLS-2$

// set the width and the height

parameters. setParameter ( "image-width", "550") ; //$NON-NLS-1$ //$NON-NLS-2$ parameters.setParameter( "image-height", "200"); //$NON-NLS-1$ //$NON-NLS-2$ content = new StringBuffer();

messages = new ArrayList();

// call the chart helper to generate the pie chart image and to get the

HTML content

// use the chart definition in 'samples/dashboard/productline.widget.xml'

ChartHelper.doChart ( "samples/steel-wheels", "dashboards", "productline_all.widget.xml", parameters, content, userSession, messages, null );

%>

<%= content.toString() %>

(Click on a Product Line)

<%

}

%>

<%

if( territory != null ) {

// if the user has clicked on a slice of the pie chart we should have a

territory to work with

%>

<%

// Make a bar chart showing the department

// create the parameres for the bar chart

parameters = new SimpleParameterProvider();

// define the click url template

parameters. setParameter ( "drill-url",

"SWDashboard? territory="+territory+"&productline={ SERIES} " );

parameters.setParameter( "TERRITORY", territory );

parameters. setParameter ( "outer-params", "TERRITORY" );

// define the category axis of the bar chart

parameters. setParameter ( "inner-param", "TERRITORY"); //$NON-NLS-1$

//$NON-NLS-2$

parameters. setParameter ( "inner-param", "PRODUCTLINE"); //$NON-NLS-1$

//$NON-NLS-2$

// set the width and the height

parameters. setParameter ( "image-width", "550") ; //$NON-NLS-1$ //$NON-NLS-2$ parameters.setParameter( "image-height", "200"); //$NON-NLS-1$ //$NON-NLS-2$ content = new StringBuffer();

messages = new ArrayList();

// call the chart helper to generate the pie chart image and to get the

HTML content

// use the chart definition in 'samples/dashboard/productline.widget.xml'

ChartHelper.doChart ( "samples/steel-wheels", "dashboards", "productline.widget.xml", parameters, content, userSession, messages, null );

%>

<%= content.toString() %>

 (Click on a Product Line)

<%

}

%>

248) ;">

<%

if( productline != null ) {

// if the user has clicked on a bar of the bar chart we should have a territory and productline to work with

// create a dial and supply a value we create from the current

time

// create the parameters for the line chart parameters = new SimpleParameterProvider();parameters.setParameter( "TERRITORY", territory ); parameters. setParameter ( "outer-params", "TERRITORY" );parameters.setParameter( "PRODUCTLINE", productline ); parameters. setParameter ( "outer-params", "PRODUCTLINE" );

// define the category axis of the bar chart parameters.setParameter( "inner-param", "PRODUCTLINE");

//$NON-NLS-1$ //$NON-NLS-2$

// set the width and the height

parameters.setParameter( "image-width", "550"); //$NON-NLS-1$

//$NON-NLS-2$

parameters. setParameter ( "image-height", "200"); //$NON-NLS-1$

//$NON-NLS-2$

content = new StringBuffer();

messages = new ArrayList();

// call the chart helper to generate the pie chart image and to

get the HTML content

// use the chart definition in

'samples/dashboard/regions. widget. xml'

ChartHelper.doChart ( "samples/steel-wheels", "dashboards", "SalesOvertime.widget.xml", parameters, content, userSession, messages, null );

%>

<%= content.toString() %>

<%

}

%>

<%

if( productline == null ) {

// if the user has clicked on a bar of the bar chart we should have a territory and productline to work with

// create a dial and supply a value we create from the current

time

// create the parameters for the line chart parameters = new SimpleParameterProvider();parameters.setParameter( "TERRITORY", territory ); parameters. setParameter ( "outer-params", "TERRITORY" ); // define the category axis of the bar chart parameters.setParameter( "inner-param", "PRODUCTLINE");

//$NON-NLS-1$ //$NON-NLS-2$

//$NON-NLS-2$ //$NON-NLS-2$

get the HTML content  // set the width and the height

parameters.setParameter( "image-width", "550"); //$NON-NLS-1$

parameters. setParameter ( "image-height", "200"); //$NON-NLS-1$

content = new StringBuffer();

messages = new ArrayList();

// call the chart helper to generate the pie chart image and to

// use the chart definition in

'samples/dashboard/regions. widget. xml'

ChartHelper.doChart ( "samples/steel-wheels", "dashboards", "SalesOvertime_All.widget.xml", parameters, content, userSession, messages, null ); %>

 <%= content.toString() %>

}

附录10 Steel Wheels Territory Chart

This page last changed on Jan 30, 2007 by wgorman.

 Territory

 top

 

Ariel< /font-family> 14

true

false

350 200

  fal s e< / is-3D>

 false

 false

 samples/steel-wheels dashboards

Sales _by _Territory. xaction

 swresult

TERRITORY< /data-name> SOLD_PRICE< /data-value>

 columns

附录11 Steel Wheels Product Line All Chart

This page last changed on Jan 30, 2007 by wgorman.

 BarChart

Product Line

 TOP

Ariel< /font-family>

14

true

false

1 .1  < /domain-title>

="color"> #FFFFFF< /chart-background> #EEEEEE 

horizontal

  false< / is-3D>

 false

 false

#000000

 true

#336699 #99CCFF #999933 #666699 #CC9933 #006666 #3399FF #993300 #CCCC99 #666666 #FFCC66 #6699CC#663366

 samples/steel-wheels dashboards

Sales_by_Productline_all . xaction

 swresult

 rows< /data-orientation>

附录12 Steel Wheels Product Line Widget

This page last changed on Jan 30, 2007 by wgorman.

 BarChart

Product Line

 TOP

Ariel< /font-family>

14

true

false

1 .1  < /domain-title>

="color"> #FFFFFF< /chart-background> #EEEEEE

horizontal< /orientation>

  false< / is-3D>

 false

 false

#000000

 true

#336699 #99CCFF #999933 #666699 #CC9933 #006666 #3399FF #993300 #CCCC99 #666666 #FFCC66 #6699CC#663366

 samples/steel-wheels dashboards

Sales_by_Productline.xaction

 swresult

 rows< /data-orientation>

附录13 Steel Wheels Sales Overtime Widget

This page last changed on Jan 30, 2007 by wgorman.

 LineChart

Sales Trends

 TOP

Ariel< /font-family>

14

true

false

1 .1  < /domain-title>

="color"> #FFFFFF< /chart-background> #EEEEEE

 vertical

  false< / is-3D>

 false

 false

#000000

 false

#336699 #99CCFF #999933 #666699 #CC9933 #006666 #3399FF #993300 #CCCC99 #666666 #FFCC66 #6699CC#663366

 samples/steel-wheels dashboards

sales _overtime .xaction

 swresult

 columns

附录14 Steel Wheels Sales Overtime All Widget

This page last changed on Jan 30, 2007 by wgorman.

 LineChart

Sales Trends

 TOP

Ariel< /font-family>

14

true

false

1.1  < /domain-title>

="color"> #FFFFFF< /chart-background> #EEEEEE

 vertical

  false< / is-3D>

 false

 false

#000000

 false

#336699 #99CCFF #999933 #666699 #CC9933 #006666 #3399FF #993300 #CCCC99 #666666 #FFCC66 #6699CC#663366

 samples/steel-wheels dashboards

sales _overtime _all .xaction

 swresult

 columns

附录15 Steel Wheels Sales By Territory XAction

This page last changed on Jan 30, 2007 by wgorman.

="1 .0" encoding="UTF-8"?> 

Sales _by _Territory.xaction 05. SALES BY TERRITORY  1

ERROR< /logging-level> 

>Kurtis Cruzada

List of Territories sorted by Sales. Select date range (Jan 2003 through May

2005). Includes chart. slsbyter.png

/>

list

 

 ="result-set"/>

org .pentaho . locale .portlet

 

SimpleFilterPanelPortlet

 

filters

samples/simpleDashboard/simple-dashboard. filterpanel .xml

 

...

这个 XML fragment 描述了 ActionPortlet 类实现的一个 portlet,其可视化显示由 JFree_ChartComponent.xaction Action Sequence 创建。

...

SimplePieChartPortlet

org. pentaho . ui . portlet . ActionPortlet

text/html

VIEW

org .pentaho . locale .portlet

  SimplePieChartPortlet

 

action

samples/simpleDashboard/JFree_ChartComponent .xaction

 

...

修改 portlet-instances.xml 文件定义 portlet 实例

portlet-instances.xml 文件描述了 portlet 名字(在 portlet.xml)文件和一个 portlet 实例名间的映射。在 portal 中,你可有一个 portlet 的多个实例,每个实例有自己的首选项。这个实例仅仅从 portlet 定义 '1inherits'1 它的首选项。实例名用于 add portlet instances to portal pages

portlet 实例定义文件的更多信息请参考 JBoss Portal 服务器文档。

...

 overwrite

SimpleFilterPanelPortletInstance< /instance-id> SimpleFilterPanelPortlet< /portlet-ref>

overwrite

 SimplePieChartPortletInstance SimplePieChartPortlet

  ...

修改 pentaho-portal-object.xml 文件 to place portlet instances in a page in portal.

在 portal 上添加一个新的页面,通过在  根元素上添加一个  元素,然后在 元素中添加  元素。

为每个 portlet 添加一个窗口,通过在  元素上添加相应的  元素。为每个窗口添加一个 portlet,通过在  元素上添加  元素,指定 portlet 实例的名字(如portlet-instances.xml 文件所定义)作为元素的文本。(TODO 中详细介绍了元素)

portal 实例定义文件的更多信息请参考每行的注释,以及 JBoss Portal server documentation

...

pentaho

overwrite

Simple Dashboard

order< /name>

90

res ourceKey< /name>

 SimpleDashboard

PentahoPortalNavigationWindow< /window-name>

PentahoPortalNavigationInstance

navigation< /region>

0

theme. windowRendererId< /name>

emptyRenderer< /value> 

theme. decorationRendererId

emptyRenderer< /value> 

theme .portletRendererId

emptyRenderer< /value> 

SimpleFilterPanelPortletWindow< /window-name> SimpleFilterPanelPortletInstance< /instance-ref>

left

0

SimplePieChartPort letWindow< /window-name> SimplePieChartPortletInstance

left

1

User< /role-name> view

...

portlet.properties 文件中,为 Portlet  Portal Page Titles,添加 Localized Strings 

之前的 XML 片段中的注释标识了文本串,其是引用了本地化属性文件(又名 resource bundles)中的文本串的键值。portlet.xml 文件标识了包含这些属性文件的包(org.pentaho.locale.portlet)。你可能需要在适当的本地化文件中,为你的键值添加 key/text-string 映射。

...

SimpleDashboard=SimPAL DashBORED

...

SimpleFilterPanelPortlet.javax.portlet. title=Simple Filter Panel Portlet SimplePieChartPortlet.javax.portlet .title=Simple Pie Chart Portlet

...

 

 Repository 中创建一个 Filter Panel 定义文件

在这个实例中,在 samples/simpleDashboard/simple-dashboard. filterpanel.xml 中指定 filter panel。

CustomerNamesFilter

 Customer

customernumber< /name>

list

samples simpleDashboard getCustomerNames .xaction

 customerNamesList  customername customernumber

每个 filter panel 定义文件定义了一个 filter panel 的 filters。每个 filter 对应于用户接口上的一个控件(UI) (例如 comboboxes,lists,radio buttons等) 这些控件用于 "filter" 平台返回的数据。

创建一个 filter 定义,通过在 filter panel 定义文件的根节点(如 )上添加一个  元素,然后在  元素上添加适当的子元素。在 filter panel 上可指定 4 种不同的 filter 类型。每种类型使用一个不同的机制,用于获取它的 LOV。通过在   元素上添加一个或多个不同的子元素来指定获取 LOV 的机制。

除了  元素的一套不同子元素,还有一套所有  元素共同拥有的元素。

List of Values (LOV)

A List of Values (LOV) 是描述 items 的列表的一个术语,每个 item 有一个名字和一个值。一个实例可能跨越了一年中的数月,第一个 item 的名字是 Jan,其值是 0,第二个 item 的名字是 Feb,其值是 等等。

在一个用户接口中,当一个用户需要从很多 items 中选择一个时,为用户显示 LOV 中的每个 item 的名字, 当用户作出一个选择时,将选中的 item 的值传送到服务器。

 

公有元素

(* 必需元素)

Ø          title 元素的文本,其在 HTML form 中显示为 filter 的 label。</p> <p style="color:rgb(0,0,0)">Ø         <name> * 用于设置表单中的 HTML 控件的 name 和 id 属性。例如,如果这个 filter 是用于生成一个列表(在 HTML 中也叫做 <select> 元素),<select> 元素的 id 和 name 属性将被设置成 <name> 元素的文本。</p> <p style="color:rgb(0,0,0)">Ø         <type> 在 filter panel 中放置的 HTML 控件的类型。如果没有这个元素,或其值不能识别,生成一个 <select> 控件(又叫做复选框)。被识别的值有:</p> <p style="color:rgb(0,0,0)">o      radio: 创建一套 radio buttons</p> <p style="color:rgb(0,0,0)">o      list: 创建一个列表框</p> <p style="color:rgb(0,0,0)">o      list-multi: 创建一个具有多个选择的选择列表</p> <p style="color:rgb(0,0,0)">o      check-multi: 创建一套复选框,所有可见</p> <p style="color:rgb(0,0,0)">o      check-multi-scroll: 在一个可滚动的面板里创建一套检查框</p> <p style="color:rgb(0,0,0)">o      check-multi-scroll-2-column: 在一个可滚动的面板里创建 2 列检查框</p> <p style="color:rgb(0,0,0)">o         check-multi-scroll-3-column: 在一个可滚动的面板里创建 3 列检查框</p> <p style="color:rgb(0,0,0)">o         check-multi-scroll-4-column: 在一个可滚动的面板里创建 4 列检查框</p> <p style="color:rgb(0,0,0)">Ø         <data-display> * LOV 中的列名,其用于提供 UI 显示文本。例如如果 filter panel 的类型是 list,这列的值用于提供列表框中的文本。</p> <p style="color:rgb(0,0,0)">Ø         <data-value> * LOV 中的列名,其用于提供和 UI 显示文本相关的值。这些是当表单提交到服务器时,要发送的值。</p> <p style="color:rgb(0,0,0)"><strong><span style="color:black">Elements Unique to Each Filter Type</span></strong></p> <p style="color:rgb(0,0,0)"><span style="color:black">filter panel </span><span style="color:black">中的每个</span><span style="color:black"> </span>filter <span style="color:black">可从以下</span><span style="color:black"> </span>4 <span style="color:black">种源获取它的</span><span style="color:black"> </span>list-of-values (LOV)<span style="color:black">:</span></p> <p style="color:rgb(0,0,0)">1.       session scoped 参数</p> <p style="color:rgb(0,0,0)">2.       全局参数</p> <p style="color:rgb(0,0,0)">3.       action sequence 输出</p> <p style="color:rgb(0,0,0)">4.       <filter> 元素的 body 中定义的 static list</p> <p style="color:rgb(0,0,0)"><strong><span style="color:black">Session Scoped </span></strong><strong><span style="color:black">参数</span></strong></p> <p style="color:rgb(0,0,0)">为配置 filter panel,从一个 session scoped 参数中获取它的 LOV,添加 <session-attribute> 作为 <filter> 元素的 child。元素的文本是一个 session scoped 参数的名字,其包含LOV。这个参数必须是以下类型之一:list,result-set(TODO 其他是什么?)。</p> <p style="color:rgb(0,0,0)"><strong><span style="color:black">Global Scoped </span></strong><strong><span style="color:black">参数</span></strong></p> <p style="color:rgb(0,0,0)">为配置 filter panel,从全局参数中获取它的 LOV,添加 <global-attribute> 作为 <filter> 元素的 child。元素的文本是包含 LOV 的全局参数的名字。这个参数必须是以下类型之一:list,result-set(TODO 其他是什么?)。</p> <p style="color:rgb(0,0,0)"><strong><span style="color:black">Action Sequence </span></strong><strong><span style="color:black">输出</span></strong></p> <p style="color:rgb(0,0,0)">为配置 filter panel,从一个 Action Sequence 中获取它的 LOV,添加元素 <data-solution>,<data-path>,<data-action> 和 <data-output> 作为 <filter> 元素的 children。每个元素的文本应该是:</p> <p style="color:rgb(0,0,0)">Ø         <data-solution>: solution-repository 中的 solution 的名字,其包含 Action Sequence 定义文件。 例如,在 PCI solution-repository 的目录中叫做 pentaho-solutions。solution 自身包含在solution-repository 目录中。例如,PCI 自带的 solutions 叫:samples,admin 和 test solutions。</p> <p style="color:rgb(0,0,0)">Ø         <data-path>: 从 solution 到 Action Sequence 定义文件的路径。</p> <p style="color:rgb(0,0,0)">Ø         <data-action>: Action Sequence 定义文件的名字。</p> <p style="color:rgb(0,0,0)">Ø         <data-output>: 如果这个元素存在,它的文本应该是 Action Sequence 将 LOV 放置其中的Action Sequence 输出参数的名字。如果这个元素不存在,filter panel 将在名为 resultset的Action Sequence 的输出参数中寻找 LOV。</p> <p style="color:rgb(0,0,0)"><strong><span style="color:black">Static List</span></strong></p> <p style="color:rgb(0,0,0)">配置 filter panel,从 filter panel 定义文件中的 static list 获取它的 LOV。</p> <table border="1"> <tbody> <tr> <td valign="top"> <p><strong><span style="color:black">Static LOV </span><span style="color:black">还不可用</span></strong></p> <p><span style="color:black">用一个</span><span style="color:black"> </span>static list <span style="color:black">初始化一个</span><span style="color:black"> </span>LOV <span style="color:black">将在下一个版本中可用。</span></p> </td> </tr> </tbody> </table> <p style="color:rgb(0,0,0)"> </p> <p style="color:rgb(0,0,0)"><strong><span style="color:black">创建</span><span style="color:black"> </span>Action Sequences <span style="color:black">为</span><span style="color:black"> </span><span style="color:black">Filter Panel's Controls </span><span style="color:black">提供</span><span style="color:black">list-of-values (LOV) </span><span style="color:black">数据</span></strong></p> <p style="color:rgb(0,0,0)">在这个实例中,在 samples/simpleDashboard/getCustomerNames.xaction 中创建了 action sequence。这个 Action Sequence 包含一个单独的 Action,其运行一个 SQL 查询,获取客户名和至少发了一个订单的客户的数量。注意列名 (customername, customernumber) 映射到 filter panel 定义文件中的 <data-display> 和 <data-value> 元素。也注意到 action sequence中的 Result Set Name (customerNamesList) 映射到 <data-output> 元素。Result Set 的值显示在 filter panel's form 的 list 控件中。</p> <p style="color:rgb(0,0,0)"></p> <p style="color:rgb(0,0,0)"><strong><span style="color:black">创建和页面中的其他</span><span style="color:black"> </span>Portlets <span style="color:black">相关的</span><span style="color:black"> </span>Action Sequences</strong></p> <p style="color:rgb(0,0,0)">在这个简单的实例中,在页面中仅有一个 portlet,SimplePieChartPortlet portlet (使用类 ActionPortlet 实现)。</p> <p style="color:rgb(0,0,0)">你想起 SimplePieChartPortlet 的优先选择,指定应该运行samples/simpleDashboard/JFree_ChartComponent.xaction Action Sequence。这个 Action Sequence 响应 filter panel 所放置的session 参数的改变,提供了商业数据的视图。</p> <p style="color:rgb(0,0,0)">这个 Action Sequence 包含:</p> <p style="color:rgb(0,0,0)">1.       一个 Relational action,其获取要在 pie chart 上显示的数据。</p> <p style="color:rgb(0,0,0)">2.       一个 Pie Chart action,其使用数据在服务器上创建一个 pie chart image。</p> <p style="color:rgb(0,0,0)">3.       一个 Message Template,其创建一个 HTML fragment 将 pie chart image 放进 portlet 中。</p> <p style="color:rgb(0,0,0)">Relational action 在 SimpleData 数据库上运行一个查询,确定一个特定顾客最优先购买的 5 种产品。在这个实例中,我正使用一个 pie chart。通常,对于一个 pie chart,你需要 2 列数据。第一列确定 pie slice 的 label,第二列确定 pie slice 的相对数量。行数确定了 slices 的数量。</p> <p style="color:rgb(0,0,0)">在这个实例中,第一列包含购买的产品,第二列包含购买的产品的数量。</p> <p style="color:rgb(0,0,0)"></p> <p style="color:rgb(0,0,0)">注意查询中的 customernumber 来自 session scoped 输入 customernumber。这个值由 filter panel 放进了session 中。</p> <p style="color:rgb(0,0,0)"></p> <p style="color:rgb(0,0,0)">Pie Chart action 在服务器上生成一个.png 文件,其包含 pie chart image。注意 chart-filename 和 base-url 输出。这些输出由 Pie Chart action 自动创建。chart-filename 中有包含 pie chart image 的文件的名字。base-url 包含 pie chart image 文件的 portal 相关的 URL。Message Template action 继续执行,创建引用服务器上的 chart image 的 HTML <img> tag。</p> <table border="1"> <tbody> <tr> <td valign="top"> <p><strong><span style="color:black">Pie Chart </span></strong><strong><span style="color:black">的默认行为在</span><span style="color:black"> </span>Portlet <span style="color:black">中不生效</span></strong></p> <p><span style="color:black">Pie Chart </span><span style="color:black">action </span><span style="color:black">的缺省行为就是生成一个包含</span><span style="color:black"> </span><span style="color:black">chart image</span><span style="color:black"> </span><span style="color:black">的完整</span><span style="color:black"> </span>HTML <span style="color:black">页面。</span><span style="color:black">这对一个</span><span style="color:black"> </span>JSP <span style="color:black">或</span><span style="color:black"> </span>Servlet <span style="color:black">是适当的。然而,</span><span style="color:black">portlet </span><span style="color:black">中的</span><span style="color:black"> </span>HTML <span style="color:black">包含一个</span><span style="color:black"> </span>HTML fragment<span style="color:black">,而不是完整的</span><span style="color:black"> </span>HTML <span style="color:black">页面。</span></p> <p><span style="color:black">可以修改默认行为,通过为</span><span style="color:black"> </span><span style="color:black">Pie Chart </span><span style="color:black">action </span><span style="color:black">指定输出。幸运的,</span><span style="color:black">Pie Chart </span><span style="color:black">action </span><span style="color:black">提供了</span><span style="color:black"> </span><span style="color:black">chart-filename </span><span style="color:black">和</span><span style="color:black">base-url </span><span style="color:black">输出。通过为</span><span style="color:black"> </span><span style="color:black">Pie Chart </span><span style="color:black">action</span><span style="color:black"> </span><span style="color:black">指定这些输出,它们将对</span><span style="color:black"> </span><span style="color:black">Action </span><span style="color:black">Sequence </span><span style="color:black">中剩下的</span><span style="color:black"> </span>actions <span style="color:black">可用。</span></p> </td> </tr> </tbody> </table> <p style="color:rgb(0,0,0)"></p> <p style="color:rgb(0,0,0)">Message Template action 创建一个 HTML <img> 元素,其引用服务器上的 chart's image 文件。Message Template 能构造一个具有有效 src 属性的 HTML <img> 元素,通过合并 Pie Chartaction 的 base-url 和 chart-filename 输入以引用服务器上生成的图像文件。这个 action 的输出(imgtag) 是一个 HTML fragment,其被添加到 Action Sequence 的输出。</p> <p style="color:rgb(0,0,0)">Action Sequence 的输出(例如 HTML fragment) 由 ActionPortlet 捕获。ActionPortlet 将这个 HTML fragment 传送到 Portal,以和页面上其他 portlets 生成的 HTML fragments 进行聚合。然后聚合后的 HTML 内容被发送回浏览器,以显示 portal dashboard。</p> <p style="color:rgb(0,0,0)"></p> <p style="color:rgb(0,0,0)">为了方便,我已经包含了 JFree_ChartComponent Action Sequence 的 XML。</p> <p style="color:rgb(0,0,0)"><span style="color:black"><?xml version="1 .0" encoding="UTF-8"?> </span><span style="color:black"><action-sequence></span></p> <p style="color:rgb(0,0,0)"><span style="color:black"><name>JFree_ChartComponent . xaction</name> </span><span style="color:black"><title>Simple Chart

1

DEBUG< /logging-level> 

Steven Barkdull

Creates a chart image based on a SQL query

You R going to need it. rule

.png 

type

customernumber

content 

SQLLookupRule< /component-name>

Query For Chart Data

sql

true< /live> SampleData

select top 5 products.productname, count( orderfact.productcode) as Amount

from orderfact inner join products on orderfact.productcode = products.productcode and orderfact.customernumber = { PREPARE:customernumber}

group by orderfact.productcode, products.productname] ] > 

ChartComponent< /component -name> Create The Chart

 ="result-set" mapping=" chartData" />

="string"/>

false

400

600

Top 5 Models Sold by Customer

  PieChart< /chart-type>

TOP

</span></p> <p style="color:rgb(0,0,0)"><span style="color:black"><title-font></span></p> <p style="color:rgb(0,0,0)"><span style="color:black"><font-family>Serif</font-family></span></p> <p style="color:rgb(0,0,0)"><span style="color:black"><size>36</size></span></p> <p style="color:rgb(0,0,0)"><span style="color:black"><is-bold>false</is-bold></span></p> <p style="color:rgb(0,0,0)"><span style="color:black"><is-italic>false</is-italic></span></p> <p style="color:rgb(0,0,0)"><span style="color:black"></title-font></span></p> <p style="color:rgb(0,0,0)"><span style="color:black"><range-title>US Dollars</range-title></span></p> <p style="color:rgb(0,0,0)"><span style="color:black"><chart-background type="color">#FFFFFF</chart-background> <plot-background-color>#FF000 0</plot-background-color></span><span style="color:black"><orientation>Horizontal</orientation></span></p> <p style="color:rgb(0,0,0)"><span style="color:black"><is-3D>false</is-3D></span></p> <p style="color:rgb(0,0,0)"><span style="color:black"><is-stacked>false</is-stacked></span></p> <p style="color:rgb(0,0,0)"><span style="color:black"><category-label-rotation> 0</category-label-rotation> </span><span style="color:black"><border-visible>false</border-vis ible></span></p> <p style="color:rgb(0,0,0)"><span style="color:black"><border-paint>#33 99FF</border-paint></span></p> <p style="color:rgb(0,0,0)"><span style="color:black"><include-legend>true< /include-legend></span></p> <p style="color:rgb(0,0,0)"><span style="color:black"></chart-attributes></span></p> <p style="color:rgb(0,0,0)"><span style="color:black"></component-definition></span></p> <p style="color:rgb(0,0,0)"><span style="color:black"></action-definition></span></p> <p style="color:rgb(0,0,0)"><span style="color:black"><action-definition></span></p> <p style="color:rgb(0,0,0)"><span style="color:black"><component -name>TemplateComponent< /component-name> </span><span style="color:black"><action-type>Message Template</action-type> </span><span style="color:black"><action-inputs></span></p> <p style="color:rgb(0,0,0)"><span style="color:black"><base-url type="string"/></span></p> <p style="color:rgb(0,0,0)"><span style="color:black"><chart-filename type<sup>=</sup>"string"/></span></p> <p style="color:rgb(0,0,0)"><span style="color:black"></action-inputs></span></p> <p style="color:rgb(0,0,0)"><span style="color:black"><action-outputs></span></p> <p style="color:rgb(0,0,0)"><span style="color:black"><output-message type<sup>=</sup>"string" mapping<sup>=</sup>"imgtag"/> </span><span style="color:black"></action-outputs></span></p> <p style="color:rgb(0,0,0)"><span style="color:black"><component-definition></span></p> <p style="color:rgb(0,0,0)"><span style="color:black"><template><![ CDATA[ <img src="{ base-url} /get Image? image={ chart-f ilename}"</span></p> <p style="color:rgb(0,0,0)"><span style="color:black">/>]] ></template></span></p> <p style="color:rgb(0,0,0)"><span style="color:black"></component-definition></span></p> <p style="color:rgb(0,0,0)"><span style="color:black"></action-definition></span></p> <p style="color:rgb(0,0,0)"><span style="color:black"></actions> </span><span style="color:black"></action-sequence></span></p> <p style="color:rgb(0,0,0)"><strong><span style="color:black">创建一个</span><span style="color:black"> </span>JNDI <span style="color:black">可访问的</span><span style="color:black"> </span>Datasource <span style="color:black">为</span><span style="color:black"> </span>Action Sequences <span style="color:black">提供数据</span></strong></p> <p style="color:rgb(0,0,0)">在 PCI 中,指定 datasources,通过在 PCI 的 server/default/deploy 文件夹下添加一个 XML 文件。文件的名字必须以 "-ds.xml" 结束。</p> <p style="color:rgb(0,0,0)">这个实例使用 SampleData JNDI 名字来引用它的 datasource。SampleData 的配置文件叫sampledata-ds.xml,如下所示:</p> <p style="color:rgb(0,0,0)"><span style="color:black"><?xml version<sup>=</sup>"1 .0" encoding<sup>=</sup>"UTF-8"?> </span><span style="color:black"><datasources></span></p> <p style="color:rgb(0,0,0)"><span style="color:black"><local-tx-datasource></span></p> <p style="color:rgb(0,0,0)"><span style="color:black"><j ndi-name> SampleData</j ndi-name></span></p> <p style="color:rgb(0,0,0)"><span style="color:black"><connection-url>j dbc : hsqldb : hsql: //localhost: 9001/sampledata</connection-url> </span><span style="color:black"><driver-class>org . hsqldb. j dbcDriver</driver-class></span></p> <p style="color:rgb(0,0,0)"><span style="color:black"><user-name>pentaho_user</user-name> </span><span style="color:black"><pas sword>password< /pas sword> <check-valid-connection-sql></span></p> <p style="color:rgb(0,0,0)"><span style="color:black">select count(*) from INFORMATION _SCHEMA. SYSTEM_SEQUENCES</span></p> <p style="color:rgb(0,0,0)"><span style="color:black"></check-valid-connection-sql> </span><span style="color:black"></ local-tx-datasource></span></p> <p style="color:rgb(0,0,0)"><span style="color:black"></datasources></span></p> <p style="color:rgb(0,0,0)"><u><span style="color:blue">配置</span><span style="color:blue"> </span>JNDI Datasources for use in Pentaho BI Platform</u>有在 PCI 中创建 JNDI datasources 的更多信息。</p> <table border="0"> <tbody> <tr> <td valign="top"> <p><strong><span style="color:black">使用一个</span><span style="color:black"> </span>System Action <span style="color:black">改善</span><span style="color:black"> </span><span style="color:black">Filter Panel </span><span style="color:black">的性能</span></strong></p> </td> </tr> </tbody> </table> <p style="color:rgb(0,0,0)">filter panel 的当前配置每次从数据库获取 list-of-values (LOV)。filter panel 在 portal 页面中呈现。对于很少改变的 LOV,以这个频率获取数据,将会在数据库服务器上引发不必要的负载。</p> <p style="color:rgb(0,0,0)">通过以下方式,我们可减少负载:</p> <p style="color:rgb(0,0,0)">1.       配置一个 <u><span style="color:blue">System Action </span></u>当平台启动时,一次从数据库获取值的列表,将之放进一个全局参数中。然后这个全局参数可用作任何 Action Sequence 的输入。</p> <p style="color:rgb(0,0,0)">2.       修改 filter panel 的定义从全局参数获取 LOV,而不是运行 getCustomerNames Action Sequence 访问 LOV。</p> <p style="color:rgb(0,0,0)">3.       修改 getCustomerNames Action Sequence 确保它关闭了数据库连接,将查询的结果存储在一个disconnected result set 中。</p> <p style="color:rgb(0,0,0)"><strong><span style="color:black">配置</span></strong><strong><span style="color:black"> </span>System Action</strong></p> <p style="color:rgb(0,0,0)">简单的说,一个 <u><span style="color:blue">System Action </span></u>是一个 Action Sequence,其被配置运行于系统启动时,或 session 启动时。System Actions 在 repository 的系统配置文件中进行配置,通常称作pentaho.xml。配置 System Actions 的详细信息请参考文章 <u><span style="color:blue">System Actions</span><span style="color:blue">。</span></u></p> <p style="color:rgb(0,0,0)">在系统配置文件中添加以下 xml fragment 将导致在系统启动时,运行getCustomerNames.xaction,那个 action sequence 的输出作为全局参数,可用于 portlets。</p> <p style="color:rgb(0,0,0)"><span style="color:black"><pentaho-system></span></p> <p style="color:rgb(0,0,0)"><span style="color:black">...</span></p> <p style="color:rgb(0,0,0)"><span style="color:black"><system-actions></span></p> <p style="color:rgb(0,0,0)"><span style="color:black">...</span></p> <p style="color:rgb(0,0,0)"><span style="color:black"><org.pentaho.ui.portlet.PentahoPortletSession scope<sup>=</sup>"global"></span></p> <p style="color:rgb(0,0,0)"><span style="color:black">samples/simpleDashboardUsingSystemAction/getCustomerNames.xaction </org.pentaho.ui.portlet. PentahoPortletSession></span></p> <p style="color:rgb(0,0,0)"><span style="color:black">... </span><span style="color:black"></system-actions></span></p> <p style="color:rgb(0,0,0)"><span style="color:black">...</span></p> <p style="color:rgb(0,0,0)"><span style="color:black"></pentaho-system></span></p> <p style="color:rgb(0,0,0)"> </p> <p style="color:rgb(0,0,0)"><strong><span style="color:black">修改</span></strong><strong><span style="color:black"> </span>Filter Panel</strong></p> <p style="color:rgb(0,0,0)">修改 filter panel 的定义:删除节点 <data-solution>,<data-path>,<data-action> 和 <data-output>,用节点 <global-attribute> 替换它们。<global-attribute> 节点的文本应该和最初的 filter panel 配置文件中的 <data-output> 节点的文本一样(例如 getCustomerNames Action Sequence 输出的名字)。</p> <table border="1"> <tbody> <tr> <td valign="top"> <p><strong><span style="color:black">在平台的</span><span style="color:black"> </span>Pre-1.6 <span style="color:black">版本中配置</span><span style="color:black"> </span>Filter Panel</strong></p> <p><span style="color:black">在平台的</span><span style="color:black"> </span>pre-1.6 <span style="color:black">版本中,不是使用</span><span style="color:black"> </span><span style="color:black"><global-attribute> </span><span style="color:black">元素来标识输入的名字,而是使用</span><span style="color:black"> </span><span style="color:black"><session-attribute> </span><span style="color:black">元素。</span></p> </td> </tr> </tbody> </table> <p style="color:rgb(0,0,0)"><span style="color:black"><filters></span></p> <p style="color:rgb(0,0,0)"><span style="color:black"><name>CustomerNamesFilter</name></span></p> <p style="color:rgb(0,0,0)"><span style="color:black"><filter></span></p> <p style="color:rgb(0,0,0)"><span style="color:black"><!-- Title text displayed in the filter panel --></span></p> <p style="color:rgb(0,0,0)"><span style="color:black"><title>Customer

customernumber< /name>

list

 customerNamesList

customername

 customernumber

 

修改 getCustomerNames Action Sequence 确保它关闭了它的数据库连接

在 Relational action 中,默认选中 Keep Connection Open 复选框。你需要取消选中这个复选框。

"Keep Connections Open" 是什么意思?

如果没有选中 Keep Connections Open,当一个 Relational action 运行一个数据库查询时,它立即将查询的结果存储进一个 light-weight java 对象中,并关闭到数据库的连接。这个 light-weight java 对象可被存储为请求中的一个参数,session  global scope。这使得对象可用于 action sequence 中的其他 actions,以及在其他时间运行的其他action sequences。然而结果经常很大,使得将内容复制进一个 light-weight java 对象很昂贵。同时将这两个对象临时保存在内存中也很昂贵。在这种情况下,选中 "Keep Connections Open" 就很有意义。这将导致 result-set 到数据库的连接处于 open 状态。result-set 对这个 action sequence 中的其他 actions 可用。不会对 light-weight java 对象作一个副本。在所有情况下,执行完 action sequence,就会关闭到数据库的连接。这就暗示选中了 "Keep Connections Open" 之后创建的 result set不会是 session  global scope,因为当前 action sequence 执行完后,就会关闭 result set 的连接,使之不可用。

你需要重启你的服务器,使得这些改变生效。

测试 Portal-based Dashboard 实例文件

portlet.xml

portlet-instances.xml

pentaho-portal-object.xml

simple-dashboard.filterpanel.xml

JFree ChartComponent.xaction

getCustomerNames.xaction

alternate simple-dashboard.filterpanel.xml  pentaho.xml


你可能感兴趣的:(技术)