Hello,<br />
<br />
I have seen that it is possible to group a chart's X Axis data dynamically by using a parameter ( see <a class='bbc_url' href='
http://www.birt-exchange.org/org/forum/index.php/topic/10981-setting-different-intervals-an-x-axis/page__hl__setGroupingUnit__fromsearch__1'>http://www.birt-exchange.org/org/forum/index.php/topic/10981-setting-different-intervals-an-x-axis/page__hl__setGroupingUnit__fromsearch__1</a> )<br />
<br />
I'd like to go further and define grouping according to a value fetched from a dataset (something similar to SELECT strftime("%S", MAX(date)) - strftime("%S", MIN(date)) AS "interval" FROM mytable ). <br />
<br />
In the dataset's onFetch script I do this :<br />
<pre class='_prettyXprint _lang-auto _linenums:0'>reportContext.setPersistentGlobalVariable("interval", Number(row["interval"]).toString());</pre> (I get errors when trying to pass it row["interval"] directly, which is a Float)<br />
To make sure the data is fetched, I have a hidden table in my report containing row["interval"] .<br />
<br />
and then beforeFactory has this code :<br />
<pre class='_prettyXprint _lang-auto _linenums:0'>importPackage( Packages. org.eclipse.birt.chart.model);
importPackage( Packages. org.eclipse.birt.chart.model.attribute);
importPackage( Packages.org.eclipse.birt.chart.model.attribute.impl );
rptDesignHandle = reportContext.getReportRunnable().designHandle.getDesignHandle();
chart = rptDesignHandle.findElement("TimeChart");
item = chart.getReportItem();
cm = item.getProperty("chart.instance");
importPackage(Packages.java.io);
out = new PrintWriter(new FileWriter("/tmp/birtreport.log", true) );
out.println('before factory');
var interval = Number(reportContext.getPersistentGlobalVariable("interval"));
out.println(interval);
xAxis = cm.getBaseAxes()[0];
if ( xAxis.getType() == AxisType.DATE_TIME_LITERAL)
{
xGrouping = xAxis.getSeriesDefinitions().get(0).getGrouping();
out.println(xGrouping.getGroupingUnit());
if( interval <= 30 ){
out.println("seconds");
xGrouping.setGroupingUnit(GroupingUnitType.SECONDS_LITERAL);
xGrouping.setGroupingInterval(1);
xAxis.setFormatSpecifier( JavaDateFormatSpecifierImpl.create("HH:mm:ss") );
}else if(30 < interval && interval <= 480) {
out.println("20 seconds");
xGrouping.setGroupingUnit(GroupingUnitType.SECONDS_LITERAL);
xGrouping.setGroupingInterval(20);
xAxis.setFormatSpecifier( JavaDateFormatSpecifierImpl.create("HH:mm:ss") );
}else if(480 < interval && interval <= 1800) {
out.println("minutes");
xGrouping.setGroupingUnit(GroupingUnitType.MINUTES_LITERAL);
xGrouping.setGroupingInterval(1);
xAxis.setFormatSpecifier( JavaDateFormatSpecifierImpl.create("dd MMM yyyy HH:mm") );
}else if(1800 < interval && interval <= 28800) {
out.println("15 minutes");
xGrouping.setGroupingUnit(GroupingUnitType.MINUTES_LITERAL);
xGrouping.setGroupingInterval(15);
xAxis.setFormatSpecifier( JavaDateFormatSpecifierImpl.create("dd MMM yyyy HH:mm") );
} else {
out.println("keep original settings");
}
}
xGrouping.setEnabled(true);
xAxis.getSeriesDefinitions().get(0).setGrouping(xGrouping);
out.close();</pre>
<br />
Unfortunately it isn't working ... Any idea how I could achieve what I want ?