We are getting some discrepancies when we convert a pie chart to an image. Specifically, the data labels on a pie chart are different in the generated image versus the original chart as shown in Excel.
You can observe this behavior by using the attached PieChart.xlsx workbook and running the following code:
final String fileName = [path] + "PieChart.xlsx"; final String shapeName = "Chart 1"; Workbook wb = new Workbook(fileName); Worksheet sheet = wb.getWorksheets().get("Sheet1"); Shape shape = sheet.getShapes().get(shapeName); ImageOrPrintOptions option = new ImageOrPrintOptions(); option.setImageFormat(ImageFormat.getPng()); option.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); String imgOut = fileName.replace(".xlsx", "_" + shapeName + ".png"); shape.toImage(imgOut, option); System.out.format("** Generated Image : " + imgOut);
If you compare the image generated by Cells (per attached “PieChart_Chart 1.png”) against the chart as shown in Excel, you can notice several discrepancies within the data labels.
Generally speaking, there’s 3 types of deltas:
- Vertical and/or Horizontal position of the data labels.
- Word wrap location of the labels.
- The call out lines are different or in some cases missing.
- The attached Word document “ChartDiscrepancies.docx” details all the discrepancies we’ve identified.
- Even though some discrepancies may seem trivial, it is important for us to produce an image which resembles the source chart as shown in Excel to the highest extent possible.
- The attachment PieChartDiscrepancies.zip contains 3 files:
- PieChart.xlsx: source workbook with pie chart
- ChartDiscrepancies.docx: Word document detailing the observed discrepancies
- PieChart_Chart 1.png: Image generated by Cells from the above code.
- Because we don’t have access to the attachments, we’re not sure if this is the same issue as:
Pie chart label is offset when rendering excel chart to image
- This issue was reproduced in Aspose.Cells for Java 18.1.