Discussions
Categories
Groups
Community Home
Categories
INTERNAL ENABLEMENT
POPULAR
PUBLIC CLOUD
PRIVATE CLOUD
Quick Links
MY LINKS
HELPFUL TIPS
Back to website
Home
Intelligence (Analytics)
API for BIRT report
ashish13
Hi,
Is there any open source API for generating report not the designer, so than i can customize my code through java and generate the report.
Thanks,
Ashish
Find more posts tagged with
Comments
Yaytay
<blockquote class='ipsBlockquote' data-author="'ashish13'" data-cid="98130" data-time="1332413873" data-date="22 March 2012 - 03:57 AM"><p>
Hi,<br />
<br />
Is there any open source API for generating report not the designer, so than i can customize my code through java and generate the report.<br />
<br />
Thanks,<br />
Ashish<br /></p></blockquote>
<br />
<a class='bbc_url' href='
http://www.eclipse.org/birt/phoenix/deploy/reportEngineAPI.php'>http://www.eclipse.org/birt/phoenix/deploy/reportEngineAPI.php</a><br
/>
<br />
This is one of my standard functions for running a report and then opening the output file in POI:<br />
<br />
<pre class='_prettyXprint _lang-auto _linenums:0'>
protected InputStream runAndRenderReportAsOne( String filename, String outputFormat ) throws BirtException, IOException {
IReportEngine reportEngine = createReportEngine();
String filepath = deriveFilepath(filename);
InputStream resourceStream = openFileStream( filename );
assertNotNull( resourceStream );
try {
IReportRunnable reportRunnable = reportEngine.openReportDesign( resourceStream );
assertNotNull(reportRunnable);
File tempDoc = createTempFile(baseFilename( filename ), ".rptdocument");
assertNotNull(tempDoc);
try {
IRunAndRenderTask reportRunRenderTask = reportEngine.createRunAndRenderTask( reportRunnable );
assertNotNull(reportRunRenderTask);
try {
addParameters( reportRunRenderTask );
addFilepathToAppContext(filepath, reportRunRenderTask);
File tempOutput = createTempFile(baseFilename( filename ), "." + outputFormat);
System.err.println( tempOutput );
FileOutputStream outputStream = new FileOutputStream( tempOutput );
assertNotNull(outputStream);
try {
reportRunRenderTask.setRenderOption(prepareRenderOptions( outputFormat, outputStream ));
reportRunRenderTask.run();
assertEquals(0, reportRunRenderTask.getErrors().size());
} finally {
outputStream.close();
}
return new ByteArrayInputStream(getBytesFromFile(tempOutput));
} finally {
reportRunRenderTask.close();
}
} finally {
tempDoc.delete();
}
} finally {
resourceStream.close();
}
}
</pre>
ashish13
Hi Yaytay,
Thanks for your reply. I have to create one report in which i have to define header dynamically based on the data available in DB and accordingly the data will populated. Can i do the same using BIRT report designer. I have attached the sample servlet. The Year has to be populated dynamically and the rest of the data based on that.
Thanks,
Ashish
Yaytay
<blockquote class='ipsBlockquote' data-author="'ashish13'" data-cid="98137" data-time="1332422116" data-date="22 March 2012 - 06:15 AM"><p>
Thanks for your reply. I have to create one report in which i have to define header dynamically based on the data available in DB and accordingly the data will populated. Can i do the same using BIRT report designer. I have attached the sample servlet. The Year has to be populated dynamically and the rest of the data based on that.<br /></p></blockquote>
<br />
I'm not quite sure I understand the problem, however I have two possible solutions for you to consider:<br />
<br />
<ul class='bbcol decimal'><li>Create a report for one year where the year is a report parameter.<br />
You can then call the report from the ReportEngine API passing in each of the years that you want to generate the output for.</li><li>Create a single report and use a BIRT List to separate the years.<br />
This could give you each year on a separate page, but would keep everything in one place (and would work without having to write any custom code).<br />
If having the output in a single file is OK I would definitely try this approach first.</li></ul>
ashish13
Hi Yaytay,
The year will be populated dynamically and it will change for each report based on the year selection on screen. The rest of the data will populate based on the MM/YYYY format and i have to do coloring based on the range defined for the record. Also I have to provide different color based on some conditions.
If i am understanding right, you are suggesting me to generate two different report and merge the same using poi. Am i correct?
Thanks,
Ashish
Yaytay
<blockquote class='ipsBlockquote' data-author="'ashish13'" data-cid="98177" data-time="1332471805" data-date="22 March 2012 - 08:03 PM"><p>
Hi Yaytay,<br />
<br />
<br />
The year will be populated dynamically and it will change for each report based on the year selection on screen. The rest of the data will populate based on the MM/YYYY format and i have to do coloring based on the range defined for the record. Also I have to provide different color based on some conditions.<br />
<br />
If i am understanding right, you are suggesting me to generate two different report and merge the same using poi. Am i correct?<br />
<br />
Thanks,<br />
Ashish<br /></p></blockquote>
<br />
Well, does the report I've attached here help?<br />
<br />
This uses a multi-values report parameter to specify the years, then uses a List to put each year onto a different sheet.<br />
Furthermore it uses a couple of event handlers to set the names of Excel sheets generated using Ramesh' Excel emitter.<br />
<br />
The only outside work this would need is to specify the years as a set of values for a single parameter.<br />
<br />
The report here is self contained, relying on a scripted data set and a sample data set.<br />
<br />
Jim
ashish13
<blockquote class='ipsBlockquote' data-author="'Yaytay'" data-cid="98185" data-time="1332499719" data-date="23 March 2012 - 03:48 AM"><p>
Well, does the report I've attached here help?<br />
<br />
This uses a multi-values report parameter to specify the years, then uses a List to put each year onto a different sheet.<br />
Furthermore it uses a couple of event handlers to set the names of Excel sheets generated using Ramesh' Excel emitter.<br />
<br />
The only outside work this would need is to specify the years as a set of values for a single parameter.<br />
<br />
The report here is self contained, relying on a scripted data set and a sample data set.<br />
<br />
Jim<br /></p></blockquote>
<br />
<br />
Hi Jim,<br />
<br />
I want all the years in a single row populated in the row based the selection. Then the data will be populated accordingly.<br />
<br />
Thanks,<br />
Ashish
Yaytay
<blockquote class='ipsBlockquote' data-author="'ashish13'" data-cid="98188" data-time="1332501005" data-date="23 March 2012 - 04:10 AM"><p>
I want all the years in a single row populated in the row based the selection. Then the data will be populated accordingly.<br /></p></blockquote>
<br />
Then instead of the List you want to use a Crosstab.<br />
<br />
If your total volume of data is small you can do the filtering like I have, but if you have a lot of data look at this plugin: <a class='bbc_url' href='
http://code.google.com/a/eclipselabs.org/p/birt-functions-lib/wiki/BindParameters'>http://code.google.com/a/eclipselabs.org/p/birt-functions-lib/wiki/BindParameters</a><br
/>
It lets you filter your dataset based on a multi-value parameter.<br />
<br />
Jim
ashish13
Hi Jim,
Can you please explian what you have done to set the name of sheets. I am not able to figure out where you have added the scripts. You are giving the name based on the year. Can you please elaborate.
Thanks,
Ashish
Yaytay
<blockquote class='ipsBlockquote' data-author="'ashish13'" data-cid="98190" data-time="1332502604" data-date="23 March 2012 - 04:36 AM"><p>
Hi Jim,<br />
<br />
Can you please explian what you have done to set the name of sheets. I am not able to figure out where you have added the scripts. You are giving the name based on the year. Can you please elaborate.<br />
<br />
Thanks,<br />
Ashish<br /></p></blockquote>
It took a bit of experimentation with both the right event handlers and the right expression, if you aren't using the Lists you'll have to do some experimentation yourself.<br />
However, the script is:<br />
<pre class='_prettyXprint _lang-auto _linenums:0'>
java.lang.System.err.println( "List.onCreate" );
java.lang.System.err.println( "this.getRowData().getColumnValue( \"Year\" ) = " + String( this.getRowData().getColumnValue( "Year" ) ) );
reportContext.setPageVariable( reportContext.PAGE_VAR_PAGE_LABEL, String( this.getRowData().getColumnValue( "Year" ) ) );
</pre>
And it's in both List.onCreate and List.onPageBreak. The onPageBreak event only fires at the end of a page, so you have to have another event handler to set it on the first page.
ashish13
<blockquote class='ipsBlockquote' data-author="'Yaytay'" data-cid="98189" data-time="1332501974" data-date="23 March 2012 - 04:26 AM"><p>
Then instead of the List you want to use a Crosstab.<br />
<br />
If your total volume of data is small you can do the filtering like I have, but if you have a lot of data look at this plugin: <a class='bbc_url' href='
http://code.google.com/a/eclipselabs.org/p/birt-functions-lib/wiki/BindParameters'>http://code.google.com/a/eclipselabs.org/p/birt-functions-lib/wiki/BindParameters</a><br
/>
It lets you filter your dataset based on a multi-value parameter.<br />
<br />
Jim<br /></p></blockquote>
<br />
<br />
Hi Jim,<br />
<br />
I am able to get the year data into horizontal row and the other field into vertical row.<br />
As per my understanding, through crosstab, i can create report on if i am using some definite set of command in summary field like sum, max etc. but i have to check the year and divide the year into months and based on the start month i have to populate the data. Is it possible using crosstab.<br />
<br />
Thanks,<br />
Ashish
Yaytay
You can make your data whatever you want if you use a scripted dataset, and you can base a crosstab on any dataset.
It's also possible to base a scripted dataset on data from some other source, so you can get your real data via some other mechanism and use that to set up the scripted dataset.
The mechanism for doing this depends on how you are deploying your report.