Search in sources :

Example 1 with CTNumDataSource

use of org.docx4j.dml.chart.CTNumDataSource in project docx4j-template by vindell.

the class Docx4j_替换模板 method replacePieChartData.

/**
 * 替换图表数据
 */
private void replacePieChartData(WordprocessingMLPackage wordMLPackage, String[] chartArr) throws Docx4JException {
    RelationshipsPart rp = wordMLPackage.getMainDocumentPart().getRelationshipsPart();
    Relationship rel = rp.getRelationshipByType(Namespaces.SPREADSHEETML_CHART);
    Chart chart = (Chart) rp.getPart(rel);
    CTChartSpace chartSpace = chart.getContents();
    List<Object> charObjList = chartSpace.getChart().getPlotArea().getAreaChartOrArea3DChartOrLineChart();
    CTPieChart pieChart = (CTPieChart) charObjList.get(0);
    List<CTPieSer> serList = pieChart.getSer();
    CTNumDataSource serVal = serList.get(0).getVal();
    List<CTNumVal> ptList = serVal.getNumRef().getNumCache().getPt();
    ptList.get(0).setV(chartArr[0]);
    ptList.get(1).setV(chartArr[1]);
}
Also used : CTPieChart(org.docx4j.dml.chart.CTPieChart) CTPieSer(org.docx4j.dml.chart.CTPieSer) CTNumDataSource(org.docx4j.dml.chart.CTNumDataSource) CTChartSpace(org.docx4j.dml.chart.CTChartSpace) Relationship(org.docx4j.relationships.Relationship) CTNumVal(org.docx4j.dml.chart.CTNumVal) RelationshipsPart(org.docx4j.openpackaging.parts.relationships.RelationshipsPart) Chart(org.docx4j.openpackaging.parts.DrawingML.Chart) CTPieChart(org.docx4j.dml.chart.CTPieChart)

Aggregations

CTChartSpace (org.docx4j.dml.chart.CTChartSpace)1 CTNumDataSource (org.docx4j.dml.chart.CTNumDataSource)1 CTNumVal (org.docx4j.dml.chart.CTNumVal)1 CTPieChart (org.docx4j.dml.chart.CTPieChart)1 CTPieSer (org.docx4j.dml.chart.CTPieSer)1 Chart (org.docx4j.openpackaging.parts.DrawingML.Chart)1 RelationshipsPart (org.docx4j.openpackaging.parts.relationships.RelationshipsPart)1 Relationship (org.docx4j.relationships.Relationship)1