Reverse table [message #527632] |
Thu, 15 April 2010 20:02 |
Amy Messages: 29 Registered: April 2010 |
Junior Member |
|
|
Hi,
I have a question for displaying a table on PDF report .
I used script to generate the data set from Java Object.
The data has 5 columns. And rows depends users select data in java application.
-> GG LL PP SS RR
R5 20 40 60 80 100
R6 10 30 50 70 90
R7 25 35 45 55 65
R8 22 32 33 55 66
R9....
R10.....
I need dispaly them on reverse way.
-> R5 R6 R7 R8 ...
GG 20 10
LL 40 30
PP 60 50
SS 80 70
RR 100 90
Column is row. Row is column.
The table has fix rows. Always 5 row. But for columns, is based on user's selection. If they want to see muitlple level information, we can have up to 10 columns. If less, only one column need show.
How I can build that kind of table in BIRT? Can I need to use Cross TAB?
Thanks!
[Updated on: Fri, 16 April 2010 12:05] Report message to a moderator
|
|
|
Re: Dynamically generate table [message #527831 is a reply to message #527632] |
Fri, 16 April 2010 15:23 |
|
Generally it is better to use a crosstab for this. The last place you
can make this kind of edit to the report is in the beforeFactory script.
You can add a dataset and table in the script. See the attached example.
Jason
<?xml version="1.0" encoding="UTF-8"?>
<report xmlns="http://www.eclipse.org/birt/2005/design" version="3.2.21"
id="1">
<property name="comments">Copyright (c) 2006 <<Your Company
Name here>></property>
<property name="createdBy">Eclipse BIRT Designer Version
2.5.2.v20100208 Build <2.5.2.v20100210-0630></property>
<property name="units">in</property>
<method name="beforeFactory"><![CDATA[ importPackage(
Packages.org.eclipse.birt.report.model.api );
reportDesignHandle = reportContext.getDesignHandle();
elementFactory = reportDesignHandle.getElementFactory()
dataSetHandle = elementFactory.newScriptDataSet( "Data Set" );
dataSetHandle.setDataSource( "Data Source" );
dataSetHandle.setOpen( "i=0;" );
dataSetHandle.setFetch( "if ( i < 4 ){"
+ "row[\"Month\"] = 1;"
+ "row[\"Product\"] = 'My Product';"
+ "row[\"Amount\"] = i;"
+ "i++;"
+ "return true;}" + "else return false;" );
// Set computed columns
cs1 = StructureFactory.createResultSetColumn( );
cs1.setColumnName( "Month" );//$NON-NLS-1$
cs1.setPosition( 1 );//$NON-NLS-1$
cs1.setDataType( "integer" );//$NON-NLS-1$
cs2 = StructureFactory.createResultSetColumn( );
cs2.setColumnName( "Product" );//$NON-NLS-1$
cs2.setPosition( 2 );//$NON-NLS-1$
cs2.setDataType( "string" );//$NON-NLS-1$
cs3 = StructureFactory.createResultSetColumn( );
cs3.setColumnName( "Amount" );//$NON-NLS-1$
cs3.setPosition( 3 );//$NON-NLS-1$
cs3.setDataType( "integer" );//$NON-NLS-1$
computedSet = dataSetHandle.getPropertyHandle( "resultSet" );
computedSet.addItem( cs1 );
computedSet.addItem( cs2 );
computedSet.addItem( cs3 );
reportDesignHandle.getDataSets( ).add( dataSetHandle );
table = elementFactory.newTableItem( null, 3, 1, 1, 1 );
table.setWidth( "80%" );
table.setProperty( "dataSet", "Data Set" );//$NON-NLS-1$
// Header
header = table.getHeader( ).get( 0 );
tcell = header.getCells( ).get( 0 );
label = elementFactory.newLabel( null );
label.setText( "Col1" );//$NON-NLS-1$
tcell.getContent( ).add( label );
tcell = header.getCells( ).get( 1 );
label = elementFactory.newLabel( null );
label.setText( "Col2" );//$NON-NLS-1$
tcell.getContent( ).add( label );
tcell = header.getCells( ).get( 2 );
label = elementFactory.newLabel( null );
label.setText( "Col3" );//$NON-NLS-1$
tcell.getContent( ).add( label );
computedSet = table.getColumnBindings( );
cs1 = StructureFactory.createComputedColumn( );
cs2 = StructureFactory.createComputedColumn( );
cs3 = StructureFactory.createComputedColumn( );
cs1.setName("Month");
cs1.setExpression( "dataSetRow[\"Month\"]" );
computedSet.addItem( cs1 );
cs2.setName("Product");
cs2.setExpression( "dataSetRow[\"Product\"]" );
computedSet.addItem( cs2 );
cs3.setName("Amount");
cs3.setExpression( "dataSetRow[\"Amount\"]" );
computedSet.addItem( cs3 );
detail = table.getDetail( ).get( 0 );
tcell = detail.getCells( ).get( 0 );
data = elementFactory.newDataItem( null );
data.setResultSetColumn( "Month");
tcell.getContent( ).add( data );
tcell = detail.getCells( ).get( 1 );
data = elementFactory.newDataItem( null );
data.setResultSetColumn( "Product");
tcell.getContent( ).add( data );
tcell = detail.getCells( ).get( 2 );
data = elementFactory.newDataItem( null );
data.setResultSetColumn( "Amount");
tcell.getContent( ).add( data );
reportDesignHandle.getBody( ).add( table );]]></method>
<property name="layoutPreference">auto layout</property>
<data-sources>
<script-data-source name="Data Source" id="4"/>
</data-sources>
<page-setup>
<simple-master-page name="Simple MasterPage" id="2">
<property name="topMargin">1in</property>
<property name="leftMargin">1.25in</property>
<property name="bottomMargin">1in</property>
<property name="rightMargin">1.25in</property>
<page-footer>
<text id="3">
<property name="contentType">html</property>
<text-property
name="content"><![CDATA[<value-of>new Date()</value-of>]]></text-property>
</text>
</page-footer>
</simple-master-page>
</page-setup>
</report>
Amy wrote:
> Hi,
>
> I have a question for building a table .
>
> The table has fix rows. Always 5 row. But for columns, is based on
> user's selection. If they want to see muitlple level information, we
> can have up to 10 columns. If less, only one column need show.
>
> I use script to generate the data set from Java Object.
>
> How I can build that kind of table in BIRT? How I can build dataset in
> Script if I don't know the column will be?
>
> Thanks!
|
|
|
|
Re: Dynamically generate table [message #527907 is a reply to message #527859] |
Fri, 16 April 2010 21:16 |
|
No this will not do that. Currently the only way I know to add rows is
to do a joint dataset with a scripted dataset. Using this approach is a
bit ugly.
dataset one
col1 col2
scripted dataset
col1 col2
jointdatset (full outer join)
ds1:col1 ds1:col2 ds2:col1 ds2:col2
Then you have to add computed columns to represent the final column
comput1 comput2
with expression
if( ds1:col1 != null ){
ds1:col1
}else{
ds2:col1
}
and
if( ds2:col2 != null ){
ds2:col2
}else{
ds2:col2
}
See what I mean about being ugly :>
Jason
roadblock2thesun wrote:
> Just to see if I follow you here:
>
> You create an empty scripted data source. In the beforeFactory event you
> create a scripted dataset. Is it possible to create a scripted dataset
> from a jdbc data source? I am trying to add rows to my data set at
> strategic points, but my data comes from an sql database. I am wondering
> if something along these lines will accomplish what I want.
|
|
|
|
Re: Dynamically generate table [message #528210 is a reply to message #528007] |
Mon, 19 April 2010 17:08 |
|
Amy
Do you have the data in a sample report that you could post?
Jason
Amy wrote:
> Jason,
>
> Thank you for your help!
>
> I want to try the crossbar first.
>
> I used scripted to get the dataset and I can display the data in a
> table now like this:
>
> Header: GG LL PP SS RR Level
>
> _______20 40 60 80 100 R5
>
> _______ 10 30 50 70 90 R6
>
> __ _____25 35 45 55 65 R7
>
> __ ____ 22 32 33 55 66 R8
>
> I tried to use Crosstab to reverse the table. I don't know how to set
> up the rows and summary data in crosstab.
>
> Based on the example in birt, I need select the 3 coulmns from old
> tables as the row / column / display data in in Crossbar.
>
> I choose Group for "Level" column, drag is to the crosstab row. That
> part works.
>
> I can see new CossTab row:
>
> Hearder: R5 R6 R7 R8
>
> But, how I can select group for CrossTab column, what I need select for
> summary Field?
>
> I am new to Birt. Maybe I don't fully understand how to set up the
> Croosbar.
>
> Please give me some detail setp to rever this table using CrossTab.
>
> Thank you so much!
>
>
>
>
|
|
|
|
Re: Dynamically generate table [message #528529 is a reply to message #528504] |
Tue, 20 April 2010 20:05 |
|
Amy,
This was not exactly what I was thinking, but take a look at the
attached example.
Jason
<?xml version="1.0" encoding="UTF-8"?>
<report xmlns="http://www.eclipse.org/birt/2005/design" version="3.2.21"
id="1">
<property name="createdBy">Eclipse BIRT Designer Version
2.5.2.v20100208 Build <2.5.2.v20100210-0630></property>
<list-property name="userProperties">
<structure>
<property name="name">Data Cube.sdsLevels.x</property>
<property name="type">integer</property>
<property name="isVisible">false</property>
</structure>
<structure>
<property name="name">Data Cube.sdsLevels.y</property>
<property name="type">integer</property>
<property name="isVisible">false</property>
</structure>
<structure>
<property name="name">Data
Cube.Group1.NewTabularHierarchy1.x</property>
<property name="type">integer</property>
<property name="isVisible">false</property>
</structure>
<structure>
<property name="name">Data
Cube.Group1.NewTabularHierarchy1.y</property>
<property name="type">integer</property>
<property name="isVisible">false</property>
</structure>
<structure>
<property name="name">Data Cube.sdsLevels.width</property>
<property name="type">integer</property>
<property name="isVisible">false</property>
</structure>
<structure>
<property name="name">Data Cube.sdsLevels.height</property>
<property name="type">integer</property>
<property name="isVisible">false</property>
</structure>
<structure>
<property name="name">Data Cube.Data Set.x</property>
<property name="type">integer</property>
<property name="isVisible">false</property>
</structure>
<structure>
<property name="name">Data Cube.Data Set.y</property>
<property name="type">integer</property>
<property name="isVisible">false</property>
</structure>
<structure>
<property name="name">Data Cube.Data Set.width</property>
<property name="type">integer</property>
<property name="isVisible">false</property>
</structure>
<structure>
<property name="name">Data Cube.Data Set.height</property>
<property name="type">integer</property>
<property name="isVisible">false</property>
</structure>
<structure>
<property name="name">Data
Cube.Group4.NewTabularHierarchy4.x</property>
<property name="type">integer</property>
<property name="isVisible">false</property>
</structure>
</list-property>
<property name="Data Cube.sdsLevels.x">273</property>
<property name="Data Cube.sdsLevels.y">23</property>
<property name="Data Cube.Group1.NewTabularHierarchy1.x">47</property>
<property name="Data Cube.Group1.NewTabularHierarchy1.y">89</property>
<property name="Data Cube.sdsLevels.width">150</property>
<property name="Data Cube.sdsLevels.height">200</property>
<property name="Data Cube.Data Set.x">246</property>
<property name="Data Cube.Data Set.y">14</property>
<property name="Data Cube.Data Set.width">150</property>
<property name="Data Cube.Data Set.height">200</property>
<property name="Data Cube.Group4.NewTabularHierarchy4.x">16</property>
<property name="units">in</property>
<property name="iconFile">/templates/blank_report.gif</property>
<property name="bidiLayoutOrientation">ltr</property>
<property name="imageDPI">96</property>
<data-sources>
<script-data-source name="Data Source" id="7"/>
</data-sources>
<data-sets>
<script-data-set name="Data Set" id="8">
<list-property name="resultSetHints">
<structure>
<property name="position">1</property>
<property name="name">GUAR</property>
<property name="dataType">float</property>
</structure>
<structure>
<property name="position">2</property>
<property name="name">LIAB</property>
<property name="dataType">integer</property>
</structure>
<structure>
<property name="position">3</property>
<property name="name">PREM</property>
<property name="dataType">integer</property>
</structure>
<structure>
<property name="position">4</property>
<property name="name">SUB</property>
<property name="dataType">integer</property>
</structure>
</list-property>
<list-property name="columnHints">
<structure>
<property name="columnName">GUAR</property>
</structure>
<structure>
<property name="columnName">LIAB</property>
</structure>
<structure>
<property name="columnName">PREM</property>
</structure>
<structure>
<property name="columnName">SUB</property>
</structure>
</list-property>
<structure name="cachedMetaData">
<list-property name="resultSet">
<structure>
<property name="position">1</property>
<property name="name">GUAR</property>
<property name="dataType">float</property>
</structure>
<structure>
<property name="position">2</property>
<property name="name">LIAB</property>
<property name="dataType">integer</property>
</structure>
<structure>
<property name="position">3</property>
<property name="name">PREM</property>
<property name="dataType">integer</property>
</structure>
<structure>
<property name="position">4</property>
<property name="name">SUB</property>
<property name="dataType">integer</property>
</structure>
</list-property>
</structure>
<property name="dataSource">Data Source</property>
<method name="open"><![CDATA[i = 0;
sourcedata = new Array( new Array(4),
new Array(4),
new Array(4),
new Array(4));
sourcedata[0][0] = 135.5;
sourcedata[0][1] = 145;
sourcedata[0][2] = 52;
sourcedata[0][3] = 351;
sourcedata[1][0] = 165.5;
sourcedata[1][1] = 555;
sourcedata[1][2] = 54;
sourcedata[1][3] = 352;
sourcedata[2][0] = 195.5;
sourcedata[2][1] = 777;
sourcedata[2][2] = 55;
sourcedata[2][3] = 353;
sourcedata[3][0] = 735.5;
sourcedata[3][1] = 666;
sourcedata[3][2] = 77;
sourcedata[3][3] = 355;
]]></method>
<method name="fetch"><![CDATA[if ( i < 4 )
{
row["GUAR"] = sourcedata[i][0];
row["LIAB"] = sourcedata[i][1];
row["PREM"]= sourcedata[i][2];
row["SUB"]= sourcedata[i][3];
i++;
return true;
}
return false;]]></method>
</script-data-set>
</data-sets>
<cubes>
<tabular-cube name="Data Cube" id="96">
<property name="dimensions">
<tabular-dimension name="Group" id="97">
<property
name="defaultHierarchy">NewTabularHierarchy</property>
<property name="hierarchies">
<tabular-hierarchy name="NewTabularHierarchy"
id="98">
<property name="levels">
<tabular-level name="GUAR" id="99">
<property
name="dataType">float</property>
<property
name="columnName">GUAR</property>
</tabular-level>
</property>
</tabular-hierarchy>
</property>
</tabular-dimension>
<tabular-dimension name="Group1" id="100">
<property
name="defaultHierarchy">NewTabularHierarchy1</property>
<property name="hierarchies">
<tabular-hierarchy name="NewTabularHierarchy1"
id="101">
<property name="levels">
<tabular-level name="LIAB" id="102">
<property
name="dataType">integer</property>
<property
name="columnName">LIAB</property>
</tabular-level>
</property>
</tabular-hierarchy>
</property>
</tabular-dimension>
<tabular-dimension name="Group2" id="114">
<property
name="defaultHierarchy">NewTabularHierarchy2</property>
<property name="hierarchies">
<tabular-hierarchy name="NewTabularHierarchy2"
id="115">
<property name="levels">
<tabular-level name="PREM" id="116">
<property
name="dataType">integer</property>
<property
name="columnName">PREM</property>
</tabular-level>
</property>
</tabular-hierarchy>
</property>
</tabular-dimension>
<tabular-dimension name="Group3" id="117">
<property
name="defaultHierarchy">NewTabularHierarchy3</property>
<property name="hierarchies">
<tabular-hierarchy name="NewTabularHierarchy3"
id="118">
<property name="levels">
<tabular-level name="SUB" id="119">
<property
name="dataType">integer</property>
<property
name="columnName">SUB</property>
</tabular-level>
</property>
</tabular-hierarchy>
</property>
</tabular-dimension>
</property>
<property name="dataSet">Data Set</property>
</tabular-cube>
</cubes>
<styles>
<style name="report" id="4">
<property name="fontFamily">sans-serif</property>
<property name="fontSize">10pt</property>
</style>
<style name="crosstab" id="5">
<property name="borderBottomColor">#CCCCCC</property>
<property name="borderBottomStyle">solid</property>
<property name="borderBottomWidth">1pt</property>
<property name="borderLeftColor">#CCCCCC</property>
<property name="borderLeftStyle">solid</property>
<property name="borderLeftWidth">1pt</property>
<property name="borderRightColor">#CCCCCC</property>
<property name="borderRightStyle">solid</property>
<property name="borderRightWidth">1pt</property>
<property name="borderTopColor">#CCCCCC</property>
<property name="borderTopStyle">solid</property>
<property name="borderTopWidth">1pt</property>
</style>
<style name="crosstab-cell" id="6">
<property name="borderBottomColor">#CCCCCC</property>
<property name="borderBottomStyle">solid</property>
<property name="borderBottomWidth">1pt</property>
<property name="borderLeftColor">#CCCCCC</property>
<property name="borderLeftStyle">solid</property>
<property name="borderLeftWidth">1pt</property>
<property name="borderRightColor">#CCCCCC</property>
<property name="borderRightStyle">solid</property>
<property name="borderRightWidth">1pt</property>
<property name="borderTopColor">#CCCCCC</property>
<property name="borderTopStyle">solid</property>
<property name="borderTopWidth">1pt</property>
</style>
</styles>
<page-setup>
<simple-master-page name="Simple MasterPage" id="2">
<page-footer>
<text id="3">
<property name="contentType">html</property>
<text-property
name="content"><![CDATA[<value-of>new Date()</value-of>]]></text-property>
</text>
</page-footer>
</simple-master-page>
</page-setup>
<body>
<grid id="214">
<property name="width">7.947916666666667in</property>
<column id="215">
<property name="width">2.15625in</property>
</column>
<column id="216">
<property name="width">5.791666666666667in</property>
</column>
<row id="217">
<cell id="218">
<grid id="220">
<column id="221"/>
<row id="222">
<cell id="223">
<label id="230">
<text-property
name="text">GUAR</text-property>
</label>
</cell>
</row>
<row id="224">
<cell id="225">
<label id="231">
<text-property
name="text">LIAB</text-property>
</label>
</cell>
</row>
<row id="226">
<cell id="227">
<label id="232">
<text-property
name="text">PREM</text-property>
</label>
</cell>
</row>
<row id="228">
<cell id="229">
<label id="233">
<text-property
name="text">SUB</text-property>
</label>
</cell>
</row>
</grid>
</cell>
<cell id="219">
<extended-item extensionName="Crosstab"
extensionVersion="2.5.0" id="140">
<property name="rows">
<extended-item extensionName="CrosstabView"
id="162"/>
</property>
<property name="columns">
<extended-item extensionName="CrosstabView"
id="142">
<property name="views">
<extended-item
extensionName="DimensionView" id="143">
<property
name="dimension">Group</property>
<property name="levels">
<extended-item
extensionName="LevelView" name="NewLevel View" id="144">
<property
name="level">Group/GUAR</property>
<property name="member">
<extended-item
extensionName="CrosstabCell" id="145">
<property
name="content">
<data
name="GUAR" id="146">
<property name="resultSetColumn">GUAR</property>
</data>
</property>
</extended-item>
</property>
</extended-item>
</property>
</extended-item>
<extended-item
extensionName="DimensionView" id="147">
<property
name="dimension">Group1</property>
<property name="levels">
<extended-item
extensionName="LevelView" name="NewLevel View1" id="148">
<property
name="level">Group1/LIAB</property>
<property name="member">
<extended-item
extensionName="CrosstabCell" id="149">
<property
name="content">
<data
name="LIAB" id="150">
<property name="resultSetColumn">LIAB</property>
</data>
</property>
</extended-item>
</property>
</extended-item>
</property>
</extended-item>
<extended-item
extensionName="DimensionView" id="151">
<property
name="dimension">Group2</property>
<property name="levels">
<extended-item
extensionName="LevelView" name="NewLevel View2" id="152">
<property
name="level">Group2/PREM</property>
<property name="member">
<extended-item
extensionName="CrosstabCell" id="153">
<property
name="content">
<data
name="PREM" id="154">
<property name="resultSetColumn">PREM</property>
</data>
</property>
</extended-item>
</property>
</extended-item>
</property>
</extended-item>
<extended-item
extensionName="DimensionView" id="155">
<property
name="dimension">Group3</property>
<property name="levels">
<extended-item
extensionName="LevelView" name="NewLevel View3" id="156">
<property
name="level">Group3/SUB</property>
<property name="member">
<extended-item
extensionName="CrosstabCell" id="157">
<property
name="content">
<data
name="SUB" id="158">
<property name="resultSetColumn">SUB</property>
</data>
</property>
</extended-item>
</property>
</extended-item>
</property>
</extended-item>
</property>
</extended-item>
</property>
<property name="header">
<extended-item extensionName="CrosstabCell"
id="141"/>
</property>
<property name="cube">Data Cube</property>
<list-property name="boundDataColumns">
<structure>
<property name="name">GUAR</property>
<expression
name="expression">dimension["Group"]["GUAR"]</expression >
<property name="dataType">float</property>
</structure>
<structure>
<property name="name">LIAB</property>
<expression
name="expression">dimension["Group1"]["LIAB"]</expression >
<property
name="dataType">integer</property>
</structure>
<structure>
<property name="name">PREM</property>
<expression
name="expression">dimension["Group2"]["PREM"]</expression >
<property
name="dataType">integer</property>
</structure>
<structure>
<property name="name">SUB</property>
<expression
name="expression">dimension["Group3"]["SUB"]</expression >
<property
name="dataType">integer</property>
</structure>
</list-property>
</extended-item>
</cell>
</row>
</grid>
</body>
</report>
Amy wrote:
> Jason,
>
> Here is the table data:
>
> I can display this table using my data set in report:
>
> GUAR -- LIAB -- PREM -- SUB -- PPR-- LEV
> ________________________________________
> 135.5 -- 145 ---- 52 ---- 351 --- 15--- 40
> 165.5 -- 555 ---- 54 ---- 352 --- 17--- 50
> 195.5 -- 777 ---- 55 ---- 353 --- 16--- 60
> 735.5 -- 666 ---- 77 ---- 355 --- 13--- 70
>
>
> But user want to see based on the level coverage:
> Use LEV (level) as the new table row title, display data for Guar....
>
> The result is:
> ...... | ------- 40 ------ 50 ------ 60 -- ---- 70
> ____________________________________
> GUAR | ------ 135.5 --- 165.5 --- 195.5 --- 735.5
>
> L IAB | -------- 145 ----- 555 -- ---
> 777------- 666
>
> PREM |--------- 52 --------- 54------ 55 -------77
>
> S U B | -------- 351 ------- 352 ------ 353----355
>
> P P R | --------- 15 --------17-------16-------13
>
>
>
> Thank you so much for your help!
>
> Amy
>
>
|
|
|
|
Powered by
FUDForum. Page generated in 0.04376 seconds