Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Archived » BIRT » Setting grouping interval in beforeGeneration
Setting grouping interval in beforeGeneration [message #667215] Wed, 27 April 2011 13:37 Go to next message
Mike Wulkan is currently offline Mike WulkanFriend
Messages: 147
Registered: July 2009
Senior Member
Hi,

I currently have this code in my reports "beforeFactory" script:

chart1 = this.getReportElement( "CPU Details1" );
catg = chart1.getCategory().getGrouping();
catg.setEnabled( true );
catg.setGroupInterval(params["Time Buckets"].value);

I would like to move this functionality to the chart, so I replaced the above code with this code in the charts beforeGeneration script:

xAxis = chart.getPrimaryBaseAxes()[0];
catg = xAxis.getSeriesDefinitions().get(0).getGrouping();
catg.setEnabled( true );
catg.setGroupingInterval(icsc.getExternalContext().getScript able().getParameterValue( "Time Buckets"));

... but as you can guess, it doesn't work. No errors generated but it doesn't do the grouping as expected.

As background, I am moving the code so that I can change the grouping interval based on a calculation from the dataset rather than just a parameter setting but I haven't got to that point yet.
Re: Setting grouping interval in beforeGeneration [message #667252 is a reply to message #667215] Wed, 27 April 2011 15:48 Go to previous messageGo to next message
Jason Weathersby is currently offline Jason WeathersbyFriend
Messages: 9167
Registered: July 2009
Senior Member

Mike,

Try moving it to beforeRender instead of beforeFactory and then in your
tables set a persistentGlobalVariable that you use to set the interval.

Jason


On 4/27/2011 9:37 AM, Mike Wulkan wrote:
> Hi,
>
> I currently have this code in my reports "beforeFactory" script:
>
> chart1 = this.getReportElement( "CPU Details1" );
> catg = chart1.getCategory().getGrouping();
> catg.setEnabled( true );
> catg.setGroupInterval(params["Time Buckets"].value);
>
> I would like to move this functionality to the chart, so I replaced the
> above code with this code in the charts beforeGeneration script:
>
> xAxis = chart.getPrimaryBaseAxes()[0];
> catg = xAxis.getSeriesDefinitions().get(0).getGrouping();
> catg.setEnabled( true );
> catg.setGroupingInterval(icsc.getExternalContext().getScript
> able().getParameterValue( "Time Buckets"));
>
> ... but as you can guess, it doesn't work. No errors generated but it
> doesn't do the grouping as expected.
> As background, I am moving the code so that I can change the grouping
> interval based on a calculation from the dataset rather than just a
> parameter setting but I haven't got to that point yet.
Re: Setting grouping interval in beforeGeneration [message #667254 is a reply to message #667252] Wed, 27 April 2011 16:22 Go to previous messageGo to next message
Mike Wulkan is currently offline Mike WulkanFriend
Messages: 147
Registered: July 2009
Senior Member
I did as you suggested and put the following code:

chart1 = this.getReportElement( "CPU Details1" );
catg = chart1.getCategory().getGrouping();
catg.setEnabled( true );
catg.setGroupInterval(params["Time Buckets"].value);

in beforeRender and removed it from the beforeFactory. I also removed the other attempt from the chart beforeGeneration method.

Doesn't work...again no errors to be seen but the grouping doesn't work. When I put the same code back in beforeGeneration it works fine. I take it that beforeGeneration is called before I'll have a chance to compute the desired group value from any tables in the report which is why you suggested moving the code to beforeRender.

Any other suggestions?

Thanks,
Mike
Re: Setting grouping interval in beforeGeneration [message #667263 is a reply to message #667252] Wed, 27 April 2011 17:00 Go to previous messageGo to next message
Jason Weathersby is currently offline Jason WeathersbyFriend
Messages: 9167
Registered: July 2009
Senior Member

Mike,

I did so more testing on this and moving to the onRender is not going to
work. The grouping for charts generates at runtime of the report not
the render time. So it is to late when the chart scripts run to change
that value. You could always swap out the entire dataset for a chart in
the chart scripts but this is probably not want you want to do.

Jason

On 4/27/2011 11:48 AM, Jason Weathersby wrote:
> Mike,
>
> Try moving it to beforeRender instead of beforeFactory and then in your
> tables set a persistentGlobalVariable that you use to set the interval.
>
> Jason
>
>
> On 4/27/2011 9:37 AM, Mike Wulkan wrote:
>> Hi,
>>
>> I currently have this code in my reports "beforeFactory" script:
>>
>> chart1 = this.getReportElement( "CPU Details1" );
>> catg = chart1.getCategory().getGrouping();
>> catg.setEnabled( true );
>> catg.setGroupInterval(params["Time Buckets"].value);
>>
>> I would like to move this functionality to the chart, so I replaced the
>> above code with this code in the charts beforeGeneration script:
>>
>> xAxis = chart.getPrimaryBaseAxes()[0];
>> catg = xAxis.getSeriesDefinitions().get(0).getGrouping();
>> catg.setEnabled( true );
>> catg.setGroupingInterval(icsc.getExternalContext().getScript
>> able().getParameterValue( "Time Buckets"));
>>
>> ... but as you can guess, it doesn't work. No errors generated but it
>> doesn't do the grouping as expected.
>> As background, I am moving the code so that I can change the grouping
>> interval based on a calculation from the dataset rather than just a
>> parameter setting but I haven't got to that point yet.
>
Re: Setting grouping interval in beforeGeneration [message #667267 is a reply to message #667263] Wed, 27 April 2011 18:14 Go to previous messageGo to next message
Mike Wulkan is currently offline Mike WulkanFriend
Messages: 147
Registered: July 2009
Senior Member
If I could compute the required value in a computed column of the dataset, could I access this value in the beforeFactory report method?
If so how?

Let me explain a bit as to why I am trying to do what I'm doing and perhaps there is a better way to achieve my goal.

The data I am displaying can consist of enormously different amounts of data points (x axis is a time range). Sometimes it can be say 10 to 100; but sometimes it may be thousands. If there are relatively few data points then a small grouping interval is fine and in fact shows the most detail. But for larger time ranges we want to set the group interval such that the charts are impossibly busy by averaging the group intervals (ie., smoothing the chart).

I currently have the grouping interval set as a parameter to the report. The problem with this is that the user doesn't know in advance what the appropriate smoothing interval should be. The application on the other hand, can compute a reasonable smoothing interval based on the number of data points in the selected dataset. This is the value I'd like to compute that is data dependent. Then I'd like to set this value for all of the charts in the reports.

Thanks,
Mike
Re: Setting grouping interval in beforeGeneration [message #667287 is a reply to message #667267] Wed, 27 April 2011 21:12 Go to previous messageGo to next message
Jason Weathersby is currently offline Jason WeathersbyFriend
Messages: 9167
Registered: July 2009
Senior Member

Mike,

I only know of two options to handle this. One is to call the data
engine directly in the beforeFactory. While this is possible the data
engine is subject to change as it is not a public api currently. I am
attaching an example of this. The other options is to do an autoforward
from one report to the next. To do this just add a text element with
script similar to the following:

<script type="text/javascript">


function forward() {
var temp = new String(location.href);
//alert( temp );
var detailReport = "<VALUE-OF>params["reportForward"].value</VALUE-OF>";
var TargetURL = temp.replace(/forwarddetail.rptdesign/, detailReport);

//alert( TargetURL );
location.replace(TargetURL);

return false;
}
forward();
</script>

You could append a parameter value to the url that contains the rowcount
that you calculate in a table first.

Jason

<?xml version="1.0" encoding="UTF-8"?>
<report xmlns="http://www.eclipse.org/birt/2005/design" version="3.2.22"
id="1">
<property name="createdBy">Eclipse BIRT Designer Version
2.6.1.v20100902 Build &lt;2.6.1.v20100915-1750></property>
<property name="units">in</property>
<method name="beforeFactory"><![CDATA[importPackage(
Packages.org.eclipse.birt.report.model.api );
importPackage(Packages.java.lang);
importPackage(Packages.java.util);
importPackage(Packages.org.eclipse.birt.data.engine.api);
importPackage(Packages.org.eclipse.birt.report.model.api);
importPackage(Packages.org.eclipse.birt.data.engine.api.quer ydefn);
importPackage(Packages.org.eclipse.birt.data.engine.core);


var myconfig =
reportContext.getReportRunnable().getReportEngine().getConfi g();
var de = DataEngine.newDataEngine( myconfig, null );

var dsrc = reportContext.getDesignHandle().findDataSource("Data Source");
var dset = reportContext.getDesignHandle().findDataSet("Data Set");

var odaDataSource = new OdaDataSourceDesign( "Test Data Source" );
odaDataSource.setExtensionID( "org.eclipse.birt.report.data.oda.jdbc" );
odaDataSource.addPublicProperty( "odaURL",
dsrc.getProperty("odaURL").toString() );
odaDataSource.addPublicProperty( "odaDriverClass",
dsrc.getProperty("odaDriverClass").toString());
odaDataSource.addPublicProperty( "odaUser",
dsrc.getProperty("odaUser").toString() );
odaDataSource.addPublicProperty( "odaPassword", "" );


var odaDataSet = new OdaDataSetDesign( "Test Data Set" );
odaDataSet.setDataSource( odaDataSource.getName( ) );
odaDataSet.setExtensionID(
"org.eclipse.birt.report.data.oda.jdbc.JdbcSelectDataSet" );
odaDataSet.setQueryText( dset.getQueryText() );


de.defineDataSource( odaDataSource );
de.defineDataSet( odaDataSet );

queryDefinition = new QueryDefinition( );
queryDefinition.setDataSetName( odaDataSet.getName() );
queryDefinition.setAutoBinding(true);


var pq = de.prepare( queryDefinition );

var qr = pq.execute( null );

rowcount=0;
var ri = qr.getResultIterator( );
while ( ri.next( ) )
{
rowcount++
}

ri.close( );
qr.close( );
de.shutdown( );

]]></method>
<property name="iconFile">/templates/blank_report.gif</property>
<property name="bidiLayoutOrientation">ltr</property>
<property name="imageDPI">96</property>
<data-sources>
<oda-data-source
extensionID="org.eclipse.birt.report.data.oda.jdbc" name="Data Source"
id="7">
<list-property name="privateDriverProperties">
<ex-property>
<name>contentBidiFormatStr</name>
<value>ILYNN</value>
</ex-property>
<ex-property>
<name>metadataBidiFormatStr</name>
<value>ILYNN</value>
</ex-property>
</list-property>
<property
name="odaDriverClass">org.eclipse.birt.report.data.oda.sampledb.Driver </property>
<property name="odaURL">jdbc:classicmodels:sampledb</property>
<property name="odaUser">ClassicModels</property>
</oda-data-source>
</data-sources>
<data-sets>
<oda-data-set
extensionID="org.eclipse.birt.report.data.oda.jdbc.JdbcSelectDataSet "
name="Data Set" id="8">
<list-property name="columnHints">
<structure>
<property name="columnName">ORDERNUMBER</property>
<text-property
name="displayName">ORDERNUMBER</text-property>
<text-property
name="heading">ORDERNUMBER</text-property>
</structure>
<structure>
<property name="columnName">PRODUCTCODE</property>
<text-property
name="displayName">PRODUCTCODE</text-property>
<text-property
name="heading">PRODUCTCODE</text-property>
</structure>
<structure>
<property name="columnName">QUANTITYORDERED</property>
<text-property
name="displayName">QUANTITYORDERED</text-property>
<text-property
name="heading">QUANTITYORDERED</text-property>
</structure>
<structure>
<property name="columnName">PRICEEACH</property>
<text-property
name="displayName">PRICEEACH</text-property>
<text-property name="heading">PRICEEACH</text-property>
</structure>
<structure>
<property name="columnName">ORDERLINENUMBER</property>
<text-property
name="displayName">ORDERLINENUMBER</text-property>
<text-property
name="heading">ORDERLINENUMBER</text-property>
</structure>
</list-property>
<structure name="cachedMetaData">
<list-property name="resultSet">
<structure>
<property name="position">1</property>
<property name="name">ORDERNUMBER</property>
<property name="dataType">integer</property>
</structure>
<structure>
<property name="position">2</property>
<property name="name">PRODUCTCODE</property>
<property name="dataType">string</property>
</structure>
<structure>
<property name="position">3</property>
<property name="name">QUANTITYORDERED</property>
<property name="dataType">integer</property>
</structure>
<structure>
<property name="position">4</property>
<property name="name">PRICEEACH</property>
<property name="dataType">float</property>
</structure>
<structure>
<property name="position">5</property>
<property name="name">ORDERLINENUMBER</property>
<property name="dataType">integer</property>
</structure>
</list-property>
</structure>
<property name="dataSource">Data Source</property>
<list-property name="resultSet">
<structure>
<property name="position">1</property>
<property name="name">ORDERNUMBER</property>
<property name="nativeName">ORDERNUMBER</property>
<property name="dataType">integer</property>
<property name="nativeDataType">4</property>
</structure>
<structure>
<property name="position">2</property>
<property name="name">PRODUCTCODE</property>
<property name="nativeName">PRODUCTCODE</property>
<property name="dataType">string</property>
<property name="nativeDataType">12</property>
</structure>
<structure>
<property name="position">3</property>
<property name="name">QUANTITYORDERED</property>
<property name="nativeName">QUANTITYORDERED</property>
<property name="dataType">integer</property>
<property name="nativeDataType">4</property>
</structure>
<structure>
<property name="position">4</property>
<property name="name">PRICEEACH</property>
<property name="nativeName">PRICEEACH</property>
<property name="dataType">float</property>
<property name="nativeDataType">8</property>
</structure>
<structure>
<property name="position">5</property>
<property name="name">ORDERLINENUMBER</property>
<property name="nativeName">ORDERLINENUMBER</property>
<property name="dataType">integer</property>
<property name="nativeDataType">5</property>
</structure>
</list-property>
<xml-property name="queryText"><![CDATA[select *
from orderdetails where ordernumber = 10101]]></xml-property>
<xml-property name="designerValues"><![CDATA[<?xml
version="1.0" encoding="UTF-8"?>
<model:DesignValues
xmlns:design="http://www.eclipse.org/datatools/connectivity/oda/design"
xmlns:model="http://www.eclipse.org/birt/report/model/adapter/odaModel">
<Version>1.0</Version>
<design:ResultSets derivedMetaData="true">
<design:resultSetDefinitions>
<design:resultSetColumns>
<design:resultColumnDefinitions>
<design:attributes>
<design:name>ORDERNUMBER</design:name>
<design:position>1</design:position>
<design:nativeDataTypeCode>4</design:nativeDataTypeCode>
<design:precision>10</design:precision>
<design:scale>0</design:scale>
<design:nullability>Nullable</design:nullability>
<design:uiHints>
<design:displayName>ORDERNUMBER</design:displayName>
</design:uiHints>
</design:attributes>
<design:usageHints>
<design:label>ORDERNUMBER</design:label>
<design:formattingHints>
<design:displaySize>11</design:displaySize>
</design:formattingHints>
</design:usageHints>
</design:resultColumnDefinitions>
<design:resultColumnDefinitions>
<design:attributes>
<design:name>PRODUCTCODE</design:name>
<design:position>2</design:position>
<design:nativeDataTypeCode>12</design:nativeDataTypeCode>
<design:precision>15</design:precision>
<design:scale>0</design:scale>
<design:nullability>Nullable</design:nullability>
<design:uiHints>
<design:displayName>PRODUCTCODE</design:displayName>
</design:uiHints>
</design:attributes>
<design:usageHints>
<design:label>PRODUCTCODE</design:label>
<design:formattingHints>
<design:displaySize>15</design:displaySize>
</design:formattingHints>
</design:usageHints>
</design:resultColumnDefinitions>
<design:resultColumnDefinitions>
<design:attributes>
<design:name>QUANTITYORDERED</design:name>
<design:position>3</design:position>
<design:nativeDataTypeCode>4</design:nativeDataTypeCode>
<design:precision>10</design:precision>
<design:scale>0</design:scale>
<design:nullability>Nullable</design:nullability>
<design:uiHints>
<design:displayName>QUANTITYORDERED</design:displayName>
</design:uiHints>
</design:attributes>
<design:usageHints>
<design:label>QUANTITYORDERED</design:label>
<design:formattingHints>
<design:displaySize>11</design:displaySize>
</design:formattingHints>
</design:usageHints>
</design:resultColumnDefinitions>
<design:resultColumnDefinitions>
<design:attributes>
<design:name>PRICEEACH</design:name>
<design:position>4</design:position>
<design:nativeDataTypeCode>8</design:nativeDataTypeCode>
<design:precision>15</design:precision>
<design:scale>0</design:scale>
<design:nullability>Nullable</design:nullability>
<design:uiHints>
<design:displayName>PRICEEACH</design:displayName>
</design:uiHints>
</design:attributes>
<design:usageHints>
<design:label>PRICEEACH</design:label>
<design:formattingHints>
<design:displaySize>22</design:displaySize>
</design:formattingHints>
</design:usageHints>
</design:resultColumnDefinitions>
<design:resultColumnDefinitions>
<design:attributes>
<design:name>ORDERLINENUMBER</design:name>
<design:position>5</design:position>
<design:nativeDataTypeCode>5</design:nativeDataTypeCode>
<design:precision>5</design:precision>
<design:scale>0</design:scale>
<design:nullability>Nullable</design:nullability>
<design:uiHints>
<design:displayName>ORDERLINENUMBER</design:displayName>
</design:uiHints>
</design:attributes>
<design:usageHints>
<design:label>ORDERLINENUMBER</design:label>
<design:formattingHints>
<design:displaySize>6</design:displaySize>
</design:formattingHints>
</design:usageHints>
</design:resultColumnDefinitions>
</design:resultSetColumns>
<design:criteria/>
</design:resultSetDefinitions>
</design:ResultSets>
</model:DesignValues>
]]></xml-property>
</oda-data-set>
</data-sets>
<styles>
<style name="report" id="4">
<property name="fontFamily">sans-serif</property>
<property name="fontSize">10pt</property>
</style>
<style name="crosstab-cell" 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" 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>
<data id="9">
<list-property name="boundDataColumns">
<structure>
<property name="name">Column Binding</property>
<expression name="expression"
type="javascript">rowcount</expression>
<property name="dataType">string</property>
</structure>
</list-property>
<property name="resultSetColumn">Column Binding</property>
</data>
</body>
</report>


On 4/27/2011 2:14 PM, Mike Wulkan wrote:
> If I could compute the required value in a computed column of the
> dataset, could I access this value in the beforeFactory report method?
> If so how?
>
> Let me explain a bit as to why I am trying to do what I'm doing and
> perhaps there is a better way to achieve my goal.
>
> The data I am displaying can consist of enormously different amounts of
> data points (x axis is a time range). Sometimes it can be say 10 to 100;
> but sometimes it may be thousands. If there are relatively few data
> points then a small grouping interval is fine and in fact shows the most
> detail. But for larger time ranges we want to set the group interval
> such that the charts are impossibly busy by averaging the group
> intervals (ie., smoothing the chart).
> I currently have the grouping interval set as a parameter to the report.
> The problem with this is that the user doesn't know in advance what the
> appropriate smoothing interval should be. The application on the other
> hand, can compute a reasonable smoothing interval based on the number of
> data points in the selected dataset. This is the value I'd like to
> compute that is data dependent. Then I'd like to set this value for all
> of the charts in the reports.
>
> Thanks,
> Mike
Re: Setting grouping interval in beforeGeneration [message #667386 is a reply to message #667215] Thu, 28 April 2011 13:17 Go to previous messageGo to next message
Mike Wulkan is currently offline Mike WulkanFriend
Messages: 147
Registered: July 2009
Senior Member
Thanks Jason,

Your response gave me the approach that would work for my purposes. My report has an initial page that does not contain charts that require the smoothing interval. It is the drill down charts that make use of this value. Thus I computed the value in a table on the initial page and set the parameter value to in the onCreate method. This way the parameter is set correctly for all the drill down charts. This is just a slightly simpler variant of your autoforward approach in that I don't actually need to autoforward.

I also used a special parameter value of 0 to indicate as to whether the report should compute the value or not. If the user sets the smoothing interval parameter on the initial page to something other than 0, the report respects the choice and simply uses that.

Thanks,
Mike
Re: Setting grouping interval in beforeGeneration [message #667396 is a reply to message #667386] Thu, 28 April 2011 13:56 Go to previous message
Jason Weathersby is currently offline Jason WeathersbyFriend
Messages: 9167
Registered: July 2009
Senior Member

Glad you got it working.

Jason

On 4/28/2011 9:17 AM, Mike Wulkan wrote:
> Thanks Jason,
>
> Your response gave me the approach that would work for my purposes. My
> report has an initial page that does not contain charts that require the
> smoothing interval. It is the drill down charts that make use of this
> value. Thus I computed the value in a table on the initial page and set
> the parameter value to in the onCreate method. This way the parameter is
> set correctly for all the drill down charts. This is just a slightly
> simpler variant of your autoforward approach in that I don't actually
> need to autoforward.
>
> I also used a special parameter value of 0 to indicate as to whether the
> report should compute the value or not. If the user sets the smoothing
> interval parameter on the initial page to something other than 0, the
> report respects the choice and simply uses that.
>
> Thanks,
> Mike
Previous Topic:Convert report from 2.1 to 2.6
Next Topic:showing calendar for a date parameter
Goto Forum:
  


Current Time: Fri Mar 29 08:03:08 GMT 2024

Powered by FUDForum. Page generated in 0.04904 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top