Extract chart image from report [message #253235] |
Wed, 22 August 2007 08:01  |
Eclipse User |
|
|
|
Originally posted by: psegrp.yahoo.fr
Hi,
I'd like to extract an image (PNG or SVG) of a chart defined inside a
report. I'm looking the best way to do that.
I know I could launch HTML generation and then use the image file, but
it would be better if I could only generate the chart and not the whole
report.
NB : note that the chart needs the report for its datasource or styles.
Any clue ?
Thanks
|
|
|
Chart extracted, how to use report dataset ? [message #253265 is a reply to message #253235] |
Wed, 22 August 2007 10:25  |
Eclipse User |
|
|
|
Originally posted by: psegrp.yahoo.fr
Now, I can extract chart object from report (actually a library) and I
know how to generate image file from this chart using its sample data
(with chart.createSampleRuntimeSeries()).
But I don't find how to generate the chart using the data configuration
set in the design. I think I should be able to reassign the dataset to
the chart object (well not directly) in some way so the series may be
built but I don't know how.
Here is the code :
public void extract(File libraryFile, File outputDir, String chartId)
throws BirtException
{
initPlatform();
Chart chart = retrieveChart(libraryFile, chartId);
PluginSettings ps = PluginSettings.instance();
IDeviceRenderer idr = ps.getDevice("dv.PNG");
idr.setProperty(IDeviceRenderer.FILE_IDENTIFIER,
outputDir.getPath() + "/" + chartId + ".png");
Generator gr = Generator.instance();
Bounds bo = BoundsImpl.create(0, 0, 800, 600);
GeneratedChartState gcs = gr.build(idr.getDisplayServer(), chart,
null, bo, null);
gr.render(idr, gcs);
}
private Chart retrieveChart(File libraryFile, String chartId)
throws DesignFileException,
ExtendedElementException
{
SessionHandle sessionHandle = new DesignEngine(null)
.newSessionHandle((ULocale) null);
LibraryHandle libraryHandle = sessionHandle
.openLibrary(libraryFile.getPath());
ExtendedItemHandle eih = (ExtendedItemHandle) libraryHandle
.findElement(chartId);
Chart chart = (Chart) eih.getReportItem()
.getProperty("chart.instance");
// HERE I SHOULD RETRIEVE DATA AS CONFIGURED WITH DESIGNER
chart.createSampleRuntimeSeries();
return chart;
}
Thank you
|
|
|
Powered by
FUDForum. Page generated in 0.04730 seconds