The chart style changed after renew series


#1

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:

  1. in template the lable show the percentage of values, but in the result the lable change to categories.
  2. in template the pie style has no border line which is diff to the result pie.

#2

the template docx and the result docx file
pie-chart-docx.zip (41.8 KB)


#3

@sendreams

We have tested the scenario and have managed to reproduce the same issue at our side. For the sake of correction, we have logged this problem in our issue tracking system as WORDSNET-18600. You will be notified via this forum thread once this issue is resolved.

We apologize for your inconvenience.


#4

@sendreams

Please use the following modified code as a workaround of this issue. Hope this helps you.

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 (int i = 0; i < types.length; i++)
        {
            ChartDataLabel label = ser0.getDataLabels().add(i);
            label.setShowPercentage(true);
            label.setShowValue(false);
            label.setShowSeriesName(false);
            label.setShowCategoryName(false);
            label.setShowLegendKey(false);
        }
    }

#5

The issues you have found earlier (filed as WORDSNET-18600) have been fixed in this Aspose.Words for .NET 19.8 update and this Aspose.Words for Java 19.8 update.