i want to update chart value from templete docx, but the results did not meet my expectations.
the testing code is blow:
@Test
public void createChartWithAspose() throws Exception {
Document document = new Document(“C:\Users\CHN\Desktop\test\java_chart\pie-chart-template.docx”);
NodeCollection shapes = document.getChildNodes(NodeType.SHAPE, true);
shapes.forEach(shp -> {
Shape shape = (Shape) shp;
if (shape.hasChart()) {
updatePieChart(shape);
System.out.println("shape info updated!");
}
});
document.save("C:\\Users\\CHN\\Desktop\\test\\java_chart\\pie-chart-new.docx", SaveFormat.DOCX);
}
private void updatePieChart(Shape shape) {
Chart chart = shape.getChart();
chart.getSeries().clear();
String[] types = new String[] { "铺装类", "灯类", "梧子类", "酝电箱类", "栏杆扶手类", "废物箱类", "井盖类类", "乔木类", "绿翠寸登木类", "园艺草类" };
double[] values = new double[] { 100d, 7d, 5d, 7d, 18d, 7d, 9d, 7d, 2d, 12d };
ChartSeries ser0 = chart.getSeries().add("test", types, values);
for (ChartDataLabel label : ser0.getDataLabels()) {
label.setShowPercentage(true);
label.setShowValue(true);
}
}
图像 2.png (57.3 KB)
图像 3.png (80.4 KB)
the problem is:
- in template the lable show the percentage of values, but in the result the lable change to categories.
- in template the pie style has no border line which is diff to the result pie.