Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » BIRT » Problem when reading Chart from ReportDesignHandle
Problem when reading Chart from ReportDesignHandle [message #757445] Fri, 18 November 2011 13:23 Go to next message
js Missing name is currently offline js Missing nameFriend
Messages: 73
Registered: July 2009
Member
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?
Re: Problem when reading Chart from ReportDesignHandle [message #757457 is a reply to message #757445] Fri, 18 November 2011 13:58 Go to previous messageGo to next message
js Missing name is currently offline js Missing nameFriend
Messages: 73
Registered: July 2009
Member
From the GroupOnYAxis example from org.eclipse.birt.chart.examples\src\org\eclipse\birt\chart\examples\api\data I see that the chart is read by first calling: getReportItem on the ExtendedItemHandle:

Chart cm = (Chart) eih.getReportItem().getProperty( "chart.instance" ); //$NON-NLS-1$


This seems to solve the problem, but is not how its described in the Birt book if anyone else is using this book as a reference.
Re: Problem when reading Chart from ReportDesignHandle [message #757836 is a reply to message #757445] Fri, 18 November 2011 17:21 Go to previous message
Jason Weathersby is currently offline Jason WeathersbyFriend
Messages: 9167
Registered: July 2009
Senior Member

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?
>
Previous Topic:Avoid multiple sheets in excel using Tribix
Next Topic:Two Platforms
Goto Forum:
  


Current Time: Mon Dec 22 00:08:25 GMT 2014

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

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