Discrepancies in Pie Chart Converted To Image

Hello,

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:

  1. Vertical and/or Horizontal position of the data labels.
  2. Word wrap location of the labels.
  3. The call out lines are different or in some cases missing.

Assitional Notes:

  • 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.

Thank you.

@oraspose

Thanks for using Aspose APIs.

We were able to observe these discrepancies, we will look into them and fix them if possible. Once, there is some news for you, we will let you know asap.

This issue has been logged as

  • CELLSJAVA-42515 - Some discrepancies in Pie Chart Labels when it is converted to image

Download Link:
output-18.1.2.pdf (26.6 KB)

Java

Workbook wb = new Workbook(dirPath + "PieChart.xlsx");

Chart ch = wb.getWorksheets().get(0).getCharts().get(0);

ch.toPdf(dirPath + "output-" + CellsHelper.getVersion() +  ".pdf");

@oraspose

We are afraid these issues cannot be fixed for now because of complexity.

e.g.

  1. For the first label “Pie Item 1 58%”, we can get the relative position. The position cannot be drawn for the labels. We need to calculate the default position and then using the default position reduce the relative (i.e. read from Excel file) to get actual position. Now, we cannot calculate the default position for all cases.

  2. For the fourth label “Pie Item4 12%”, as it is too near to pie slice, we think, we don’t need to draw the leader line.

  3. For the sixth label “Pie Item Num_6 9%”, Aspose.Cells has 2 lines and Microsoft Excel has 3 lines. It is related to the width of chart. Now we cannot do same as MS Excel for all case. If you drag the right-bottom corner of the chart in Excel and enlarge/reduce the size of chart, you can find the label changes with the size of chart.

,
oraspose
Please try our latest version aspose.cells-for-java-21.6.
Your issue(filed as CELLSJAVA-41761) should be fixed now.
Let us know your feedback