|
|
Re: Problem when reading Chart from ReportDesignHandle [message #757836 is a reply to message #757445] |
Fri, 18 November 2011 17:21 |
|
Is the code in this if executing?
if (object instanceof ExtendedItemHandle) {
System.out.println("Ext Item found!");
ExtendedItemHandle eih = (ExtendedItemHandle) object;
chart = (Chart) eih.getProperty("chart.instance");
}
BTW once you add a chart to the report you also need to setup bindings
to a dataset using the api as well.
Jason
On 11/18/2011 8:23 AM, js wrote:
> I am trying to read a chart from a ReportDesignHandle based on the
> example from pp 325 in Integrating and Extending BIRT:
>
> http://www.amazon.com/Integrating-Extending-BIRT-Jason-Weathersby/dp/0321580303
>
>
> But after adding a chart dynamically I cannot read it from the
> ReportDesignHandle. Here is what I do:
>
>
> ReportDesignHandle report = BEngine.getEngine().createDesign();
>
> // Create dummy chart
> Chart dummyChart = getDummyChart();
> assertNotNull(dummyChart);
>
> // Embed dummy chart in an ExtendedItem
> ExtendedItemHandle chartHandle =
> report.getElementFactory().newExtendedItem(null, "Chart");
> try {
> chartHandle.getReportItem().setProperty("chart.instance", dummyChart);
> } catch (ExtendedElementException e) {
> e.printStackTrace();
> }
>
> // Add ExtendedItem to report.... Is this the problem?
> try {
> report.getBody().add(chartHandle);
> } catch (ContentException e) {
> e.printStackTrace();
> } catch (NameException e) {
> e.printStackTrace();
> }
>
> // Test that we can read the chart from the report
> Chart chart = null;
> List contents = report.getBody().getContents();
> for (Object object : contents) {
> if (object instanceof ListHandle) {
> // Never entered!
> }
> if (object instanceof ExtendedItemHandle) {
> System.out.println("Ext Item found!");
> ExtendedItemHandle eih = (ExtendedItemHandle) object;
> chart = (Chart) eih.getProperty("chart.instance");
> }
> }
> assertNotNull(chart);
>
>
>
> But the last line fails, the chart is null.
>
> I simply want to add the chart to the body of the report and not the
> footer as described in the book. Should it not be ok to do:
>
>
> report.getBody().add(chartHandle);
>
>
> ?
>
> If I save the report after adding it to the report and open it in the
> designer I see the chart in the design/body.
>
> Any ideas?
>
|
|
|
Powered by
FUDForum. Page generated in 0.03258 seconds