Page 1 of 1

Problem with org.docx4j.dml.chart.ObjectFactory

PostPosted: Tue Mar 06, 2012 11:54 am
by trigeek
So I am trying to reproduce the following XML as part of a test for chart addition:

</p:nvGraphicFramePr>
<p:xfrm>
<a:off x="1524000" y="1397000"/>
<a:ext cx="6096000" cy="4064000"/>
</p:xfrm>
<a:graphic>
<a:graphicData uri="http://schemas.openxmlformats.org/drawingml/2006/chart">
<c:chart xmlns:c="http://schemas.openxmlformats.org/drawingml/2006/chart" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships" r:id="rId2"/>
</a:graphicData>
</a:graphic>
</p:graphicFrame>

And I get everything to work fine except creating the line:
<c:chart xmlns:c="http://schemas.openxmlformats.org/drawingml/2006/chart" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships" r:id="rId2"/>

The code for this relevant portion is:

Graphic g = new Graphic();
GraphicData gd = new GraphicData();
gd.setUri("http://schemas.openxmlformats.org/drawingml/2006/chart");

org.docx4j.dml.chart.ObjectFactory factory = new org.docx4j.dml.chart.ObjectFactory();
CTRelId ctrelid = new CTRelId();
ctrelid.setId(relId);
JAXBElement<CTRelId> e = factory.createChart(ctrelid);

gd.getAny().add(e);
g.setGraphicData(gd);

What the above code produces (again in the relevant portion is):

<a:graphic>
<a:graphicData uri="http://schemas.openxmlformats.org/drawingml/2006/chart">
<c:chart r:id="rId2"/>
</a:graphicData>
</a:graphic>

As you can see the <c:chart is missing the xlmns:c and xmlns:r that is in the Powerpoint generated version....

What am i doing wrong?

Any help appreciated.

Thanks,
Rob

Re: Problem with org.docx4j.dml.chart.ObjectFactory

PostPosted: Tue Mar 06, 2012 9:40 pm
by jason
Those are namespace declarations, which you don't need to add explicitly, since JAXB takes care of that. You'll see it puts them on the root element.

Re: Problem with org.docx4j.dml.chart.ObjectFactory

PostPosted: Thu Mar 29, 2012 5:56 pm
by SmithaRSanthosh
After the graphic code lines, how do u add the graphic object to the main document file.