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();
ctNumVals.clear();
ctStrVals.clear();
int index = 0;
while (values.length > ctNumVals.size()) {
CTNumVal numVal = new CTNumVal();
numVal.setIdx(ctNumVals.size());
numVal.setV(values[index++]);
ctNumVals.add(ctNumVals.size(), numVal);
}
index = 0;
while (labels.length > ctStrVals.size()) {
CTStrVal strVal = new CTStrVal();
strVal.setIdx(ctStrVals.size());
strVal.setV(labels[index++]);
ctStrVals.add(ctStrVals.size(), strVal);
}
ctNumData.getPtCount().setVal(values.length);
ctStrData.getPtCount().setVal(labels.length);
}
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
slices.get(i).getSpPr().getSolidFill().setSrgbClr(color);
}
else if(labels[i].equals("b")) {
color.setVal("A42035"); //red
slices.get(i).getSpPr().getSolidFill().setSrgbClr(color);
}
}
}
that will result in a corrupted word file, I even used CTScRgbColor but the same thing happened.