We are seeing an issue where the labels on the a Chart’s horizontal axis (aka X-axis) are appearing vertically instead of diagonally. If you open the attached
WaterfallChart.xlsx file in Excel, you should see that the X-axis labels have diagonal orientation. However, when Aspose Cells converts the Chart to an image, it shows the X-axis labels with a vertical orientation. Our expectation is that the the X-axis labels in the Aspose generated image appear diagonally (similar to Excel).
This behavior can be seen in the latest Aspose Cells for Java version 20.9, the attached
WaterfallChart.xlsx workbook and the following Java code:
final String xlFile = [PATH] + "WaterfallChart.xlsx"; Workbook wb = new Workbook(xlFile); Shape chart = wb.getWorksheets().get("Sheet1").getShapes().get("Chart 1); // Convert the Chart to PNG Image ImageOrPrintOptions options = new ImageOrPrintOptions(); options.setImageType(ImageType.PNG); options.setDesiredSize(chart.getWidth(), chart.getHeight()); ByteArrayOutputStream baos = new ByteArrayOutputStream(); chart.toImage(baos, options); byte imgBytes = baos.toByteArray(); // Save the image file Path imgFile = Paths.get(xlFile.replace(".xlsx", ".png")); Files.deleteIfExists(imgFile); Files.write(imgFile, imgBytes); System.out.format("Saved image as: %s%n", imgFile.toString());
Running the above code should produce a new
WaterfallChart.png file similar to the one attached. Rendering the PNG shows the X-axis labels with horizontal orientation. Additionally, notice how the chart area is much smaller (compared to Excel) - because the X-axis labels are taking up much more of the available vertical space.
- Aspose Cells for Java 20.9
- Java version 1.8.0_211
- Windows 10 OS (but also reproducible under Linux).
File description from the
VerticalChartLabels.zip (17.2 KB) attachment:
- WaterfallChart.png: PNG file generated by the code above on our environment.
- WaterfallChart.xlsx: Workbook containing the source chart that is converted to a PNG image per the code above.