I've tried the webapp, which helped me get a bit of progress.
The part I don't understand is how the chart get's binded/referenced in the main document.xml.
I've used the attached document, that only has a bar chart for starters, as an example for myself.
The part specifically that I'm having now trouble with is (in the document or p code generated snippet):
- Code: Select all
Graphic graphic = dmlObjectFactory.createGraphic();
inline.setGraphic(graphic);
// Create object for graphicData
GraphicData graphicdata = dmlObjectFactory.createGraphicData();
graphic.setGraphicData(graphicdata);
graphicdata.setUri( "http://schemas.openxmlformats.org/drawingml/2006/chart");
org.docx4j.dml.chart.ObjectFactory dmlchartObjectFactory = new org.docx4j.dml.chart.ObjectFactory();
// Create object for chart (wrapped in JAXBElement)
CTRelId relid = dmlchartObjectFactory.createCTRelId();
JAXBElement<org.docx4j.dml.chart.CTRelId> relidWrapped = dmlchartObjectFactory.createChart(relid);
graphicdata.getAny().add( relidWrapped);
relid.setId( "rId5");
So it seems that graphicdata links to the rID5 relationship, which should be the one for the chart. However that relationship is never made anywhere, the only hint is the comment "// Create object for chart (wrapped in JAXBElement)" which suggests this is where I create the chart. I've created the method for generating the chart itself from the code generated output, which is:
- Code: Select all
public JAXBElement createIt() {
org.docx4j.dml.chart.ObjectFactory dmlchartObjectFactory = new org.docx4j.dml.chart.ObjectFactory();
CTChartSpace chartspace = dmlchartObjectFactory.createCTChartSpace();
JAXBElement<org.docx4j.dml.chart.CTChartSpace> chartspaceWrapped = dmlchartObjectFactory.createChartSpace(chartspace);
// Create object for style
CTStyle style = dmlchartObjectFactory.createCTStyle();
chartspace.setStyle(style);
// Create object for lang
CTTextLanguageID textlanguageid = dmlchartObjectFactory.createCTTextLanguageID();
chartspace.setLang(textlanguageid);
textlanguageid.setVal( "en-CA");
// Create object for chart
CTChart chart = dmlchartObjectFactory.createCTChart();
chartspace.setChart(chart);
// Create object for title
CTTitle title = dmlchartObjectFactory.createCTTitle();
chart.setTitle(title);
// Create object for overlay
CTBoolean boolean = dmlchartObjectFactory.createCTBoolean();
title.setOverlay(boolean);
// Create object for autoTitleDeleted
CTBoolean boolean2 = dmlchartObjectFactory.createCTBoolean();
chart.setAutoTitleDeleted(boolean2);
// Create object for plotArea
CTPlotArea plotarea = dmlchartObjectFactory.createCTPlotArea();
chart.setPlotArea(plotarea);
// Create object for layout
CTLayout layout = dmlchartObjectFactory.createCTLayout();
plotarea.setLayout(layout);
// Create object for valAx
CTBarChart barchart = dmlchartObjectFactory.createCTBarChart();
plotarea.getAreaChartOrArea3DChartOrLineChart().add( barchart);
// Create object for dLbls
CTDLbls dlbls = dmlchartObjectFactory.createCTDLbls();
barchart.setDLbls(dlbls);
// Create object for showLegendKey
CTBoolean boolean3 = dmlchartObjectFactory.createCTBoolean();
dlbls.setShowLegendKey(boolean3);
// Create object for showVal
CTBoolean boolean4 = dmlchartObjectFactory.createCTBoolean();
dlbls.setShowVal(boolean4);
// Create object for showCatName
CTBoolean boolean5 = dmlchartObjectFactory.createCTBoolean();
dlbls.setShowCatName(boolean5);
// Create object for showSerName
CTBoolean boolean6 = dmlchartObjectFactory.createCTBoolean();
dlbls.setShowSerName(boolean6);
// Create object for showPercent
CTBoolean boolean7 = dmlchartObjectFactory.createCTBoolean();
dlbls.setShowPercent(boolean7);
// Create object for showBubbleSize
CTBoolean boolean8 = dmlchartObjectFactory.createCTBoolean();
dlbls.setShowBubbleSize(boolean8);
// Create object for varyColors
CTBoolean boolean9 = dmlchartObjectFactory.createCTBoolean();
barchart.setVaryColors(boolean9);
// Create object for crossBetween
CTBarSer barser = dmlchartObjectFactory.createCTBarSer();
barchart.getSer().add( barser);
// Create object for order
CTUnsignedInt unsignedint = dmlchartObjectFactory.createCTUnsignedInt();
barser.setOrder(unsignedint);
unsignedint.setVal( 0 );
// Create object for val
CTNumDataSource numdatasource = dmlchartObjectFactory.createCTNumDataSource();
barser.setVal(numdatasource);
// Create object for numRef
CTNumRef numref = dmlchartObjectFactory.createCTNumRef();
numdatasource.setNumRef(numref);
numref.setF( "Sheet1!$B$2:$B$6");
// Create object for numCache
CTNumData numdata = dmlchartObjectFactory.createCTNumData();
numref.setNumCache(numdata);
numdata.setFormatCode( "General");
// Create object for ptCount
CTUnsignedInt unsignedint2 = dmlchartObjectFactory.createCTUnsignedInt();
numdata.setPtCount(unsignedint2);
unsignedint2.setVal( 5 );
// Create object for idx
CTUnsignedInt unsignedint3 = dmlchartObjectFactory.createCTUnsignedInt();
barser.setIdx(unsignedint3);
unsignedint3.setVal( 0 );
// Create object for tx
CTSerTx sertx = dmlchartObjectFactory.createCTSerTx();
barser.setTx(sertx);
// Create object for strRef
CTStrRef strref = dmlchartObjectFactory.createCTStrRef();
sertx.setStrRef(strref);
strref.setF( "Sheet1!$B$1");
// Create object for strCache
CTStrData strdata = dmlchartObjectFactory.createCTStrData();
strref.setStrCache(strdata);
// Create object for ptCount
CTUnsignedInt unsignedint4 = dmlchartObjectFactory.createCTUnsignedInt();
strdata.setPtCount(unsignedint4);
unsignedint4.setVal( 1 );
// Create object for cat
CTAxDataSource axdatasource = dmlchartObjectFactory.createCTAxDataSource();
barser.setCat(axdatasource);
// Create object for strRef
CTStrRef strref2 = dmlchartObjectFactory.createCTStrRef();
axdatasource.setStrRef(strref2);
strref2.setF( "Sheet1!$A$2:$A$6");
// Create object for strCache
CTStrData strdata2 = dmlchartObjectFactory.createCTStrData();
strref2.setStrCache(strdata2);
// Create object for ptCount
CTUnsignedInt unsignedint5 = dmlchartObjectFactory.createCTUnsignedInt();
strdata2.setPtCount(unsignedint5);
unsignedint5.setVal( 5 );
// Create object for invertIfNegative
CTBoolean boolean10 = dmlchartObjectFactory.createCTBoolean();
barser.setInvertIfNegative(boolean10);
// Create object for gapWidth
CTGapAmount gapamount = dmlchartObjectFactory.createCTGapAmount();
barchart.setGapWidth(gapamount);
gapamount.setVal( new Integer(150) );
// Create object for grouping
CTBarGrouping bargrouping = dmlchartObjectFactory.createCTBarGrouping();
barchart.setGrouping(bargrouping);
bargrouping.setVal(org.docx4j.dml.chart.STBarGrouping.CLUSTERED);
// Create object for crosses
CTUnsignedInt unsignedint6 = dmlchartObjectFactory.createCTUnsignedInt();
barchart.getAxId().add( unsignedint6);
unsignedint6.setVal( 113793024 );
// Create object for crossBetween
CTUnsignedInt unsignedint7 = dmlchartObjectFactory.createCTUnsignedInt();
barchart.getAxId().add( unsignedint7);
unsignedint7.setVal( 109210432 );
// Create object for barDir
CTBarDir bardir = dmlchartObjectFactory.createCTBarDir();
barchart.setBarDir(bardir);
bardir.setVal(org.docx4j.dml.chart.STBarDir.BAR);
// Create object for catAx
CTCatAx catax = dmlchartObjectFactory.createCTCatAx();
plotarea.getValAxOrCatAxOrDateAx().add( catax);
// Create object for delete
CTBoolean boolean11 = dmlchartObjectFactory.createCTBoolean();
catax.setDelete(boolean11);
// Create object for tickLblPos
CTTickLblPos ticklblpos = dmlchartObjectFactory.createCTTickLblPos();
catax.setTickLblPos(ticklblpos);
ticklblpos.setVal(org.docx4j.dml.chart.STTickLblPos.NEXT_TO);
// Create object for crossAx
CTUnsignedInt unsignedint8 = dmlchartObjectFactory.createCTUnsignedInt();
catax.setCrossAx(unsignedint8);
unsignedint8.setVal( 109210432 );
// Create object for crosses
CTCrosses crosses = dmlchartObjectFactory.createCTCrosses();
catax.setCrosses(crosses);
crosses.setVal(org.docx4j.dml.chart.STCrosses.AUTO_ZERO);
// Create object for auto
CTBoolean boolean12 = dmlchartObjectFactory.createCTBoolean();
catax.setAuto(boolean12);
// Create object for lblAlgn
CTLblAlgn lblalgn = dmlchartObjectFactory.createCTLblAlgn();
catax.setLblAlgn(lblalgn);
lblalgn.setVal(org.docx4j.dml.chart.STLblAlgn.CTR);
// Create object for lblOffset
CTLblOffset lbloffset = dmlchartObjectFactory.createCTLblOffset();
catax.setLblOffset(lbloffset);
lbloffset.setVal( new Integer(100) );
// Create object for noMultiLvlLbl
CTBoolean boolean13 = dmlchartObjectFactory.createCTBoolean();
catax.setNoMultiLvlLbl(boolean13);
// Create object for axId
CTUnsignedInt unsignedint9 = dmlchartObjectFactory.createCTUnsignedInt();
catax.setAxId(unsignedint9);
unsignedint9.setVal( 113793024 );
// Create object for scaling
CTScaling scaling = dmlchartObjectFactory.createCTScaling();
catax.setScaling(scaling);
// Create object for orientation
CTOrientation orientation = dmlchartObjectFactory.createCTOrientation();
scaling.setOrientation(orientation);
orientation.setVal(org.docx4j.dml.chart.STOrientation.MIN_MAX);
// Create object for axPos
CTAxPos axpos = dmlchartObjectFactory.createCTAxPos();
catax.setAxPos(axpos);
axpos.setVal(org.docx4j.dml.chart.STAxPos.L);
// Create object for majorTickMark
CTTickMark tickmark = dmlchartObjectFactory.createCTTickMark();
catax.setMajorTickMark(tickmark);
tickmark.setVal(org.docx4j.dml.chart.STTickMark.OUT);
// Create object for minorTickMark
CTTickMark tickmark2 = dmlchartObjectFactory.createCTTickMark();
catax.setMinorTickMark(tickmark2);
tickmark2.setVal(org.docx4j.dml.chart.STTickMark.NONE);
// Create object for valAx
CTValAx valax = dmlchartObjectFactory.createCTValAx();
plotarea.getValAxOrCatAxOrDateAx().add( valax);
// Create object for numFmt
CTNumFmt numfmt = dmlchartObjectFactory.createCTNumFmt();
valax.setNumFmt(numfmt);
numfmt.setFormatCode( "General");
// Create object for delete
CTBoolean boolean14 = dmlchartObjectFactory.createCTBoolean();
valax.setDelete(boolean14);
// Create object for tickLblPos
CTTickLblPos ticklblpos2 = dmlchartObjectFactory.createCTTickLblPos();
valax.setTickLblPos(ticklblpos2);
ticklblpos2.setVal(org.docx4j.dml.chart.STTickLblPos.NEXT_TO);
// Create object for crossAx
CTUnsignedInt unsignedint10 = dmlchartObjectFactory.createCTUnsignedInt();
valax.setCrossAx(unsignedint10);
unsignedint10.setVal( 113793024 );
// Create object for crosses
CTCrosses crosses2 = dmlchartObjectFactory.createCTCrosses();
valax.setCrosses(crosses2);
crosses2.setVal(org.docx4j.dml.chart.STCrosses.AUTO_ZERO);
// Create object for axId
CTUnsignedInt unsignedint11 = dmlchartObjectFactory.createCTUnsignedInt();
valax.setAxId(unsignedint11);
unsignedint11.setVal( 109210432 );
// Create object for scaling
CTScaling scaling2 = dmlchartObjectFactory.createCTScaling();
valax.setScaling(scaling2);
// Create object for orientation
CTOrientation orientation2 = dmlchartObjectFactory.createCTOrientation();
scaling2.setOrientation(orientation2);
orientation2.setVal(org.docx4j.dml.chart.STOrientation.MIN_MAX);
// Create object for axPos
CTAxPos axpos2 = dmlchartObjectFactory.createCTAxPos();
valax.setAxPos(axpos2);
axpos2.setVal(org.docx4j.dml.chart.STAxPos.B);
// Create object for majorGridlines
CTChartLines chartlines = dmlchartObjectFactory.createCTChartLines();
valax.setMajorGridlines(chartlines);
// Create object for majorTickMark
CTTickMark tickmark3 = dmlchartObjectFactory.createCTTickMark();
valax.setMajorTickMark(tickmark3);
tickmark3.setVal(org.docx4j.dml.chart.STTickMark.OUT);
// Create object for minorTickMark
CTTickMark tickmark4 = dmlchartObjectFactory.createCTTickMark();
valax.setMinorTickMark(tickmark4);
tickmark4.setVal(org.docx4j.dml.chart.STTickMark.NONE);
// Create object for crossBetween
CTCrossBetween crossbetween = dmlchartObjectFactory.createCTCrossBetween();
valax.setCrossBetween(crossbetween);
crossbetween.setVal(org.docx4j.dml.chart.STCrossBetween.BETWEEN);
// Create object for legend
CTLegend legend = dmlchartObjectFactory.createCTLegend();
chart.setLegend(legend);
// Create object for overlay
CTBoolean boolean15 = dmlchartObjectFactory.createCTBoolean();
legend.setOverlay(boolean15);
// Create object for legendPos
CTLegendPos legendpos = dmlchartObjectFactory.createCTLegendPos();
legend.setLegendPos(legendpos);
legendpos.setVal(org.docx4j.dml.chart.STLegendPos.R);
// Create object for plotVisOnly
CTBoolean boolean16 = dmlchartObjectFactory.createCTBoolean();
chart.setPlotVisOnly(boolean16);
// Create object for dispBlanksAs
CTDispBlanksAs dispblanksas = dmlchartObjectFactory.createCTDispBlanksAs();
chart.setDispBlanksAs(dispblanksas);
dispblanksas.setVal(org.docx4j.dml.chart.STDispBlanksAs.GAP);
// Create object for showDLblsOverMax
CTBoolean boolean17 = dmlchartObjectFactory.createCTBoolean();
chart.setShowDLblsOverMax(boolean17);
// Create object for date1904
CTBoolean boolean18 = dmlchartObjectFactory.createCTBoolean();
chartspace.setDate1904(boolean18);
// Create object for roundedCorners
CTBoolean boolean19 = dmlchartObjectFactory.createCTBoolean();
chartspace.setRoundedCorners(boolean19);
// Create object for externalData
CTExternalData externaldata = dmlchartObjectFactory.createCTExternalData();
chartspace.setExternalData(externaldata);
// Create object for autoUpdate
CTBoolean boolean20 = dmlchartObjectFactory.createCTBoolean();
externaldata.setAutoUpdate(boolean20);
externaldata.setId( "rId1");
return chartspaceWrapped;
}
The problem is that it returns a "JAXBElement<org.docx4j.dml.chart.CTChartSpace>" where as that comment where rID5 is binding needs a "JAXBElement<org.docx4j.dml.chart.CTRelId>". So I don't understand how I can use the method that creates the chart and how to bind that created chart to the graphicdata .
I've deleted my stackoverflow post.