Page 1 of 1

modify Charts in docx

PostPosted: Thu Jul 23, 2020 11:02 pm
by 12AM
I am working with the object, getting its jaxb element which is CTChartSpace.
I have used this approach to edit chart data :
Code: Select all
private void fillChart(CTNumData ctNumData, CTStrData ctStrData, String[] labels, String[] values) {
      List<CTNumVal> ctNumVals = ctNumData.getPt();
        List<CTStrVal> ctStrVals = ctStrData.getPt();

      int index = 0;
        while (values.length > ctNumVals.size()) {
           CTNumVal numVal = new CTNumVal();
            ctNumVals.add(ctNumVals.size(), numVal);

        index = 0;
        while (labels.length > ctStrVals.size()) {
           CTStrVal strVal = new CTStrVal();
            ctStrVals.add(ctStrVals.size(), strVal);


this code works fine, but if I want to edit the chart the data reset to the default chart data, is there any way to modify the excel sheet from the word or do I need to access with its excel sheet and modify it there?

my other issue is I want to modify Chart slices colors, so I thought this code will work since I want each slice to have a different color:
Code: Select all
private void changeChartColors(CTPieSer ctSeries, String[] labels) {
      List<CTDPt> slices = ctSeries.getDPt();
      CTSRgbColor color = new CTSRgbColor();
         for(int i = 0; i<labels.length; i++) {
            if(labels[i].equals("a")) {
               color.setVal("00AA8F"); //green
            else if(labels[i].equals("b")) {
               color.setVal("A42035"); //red

that will result in a corrupted word file, I even used CTScRgbColor but the same thing happened.