Free Support Forum - aspose.com

Chart toimage throws java.awt.HeadlessException

Hi,

I am using Aspose cells 7.0.0, when I tried to create a chart image using Chart.toImage I get java.awt.HeadlessException

Exception in thread “main” java.awt.HeadlessException
at sun.awt.HeadlessToolkit.getScreenResolution(HeadlessToolkit.java:189)
But, this happens only when I tried to create multiple chart image in the same JVM context and the “java.awt.headless” system property is set to “true”. Otherwise this issue doesn’t occur.

by setting java.awt.headless to true
- If Chart.toImage is used once it works fine
- If Chart.toImage is used multiple times, it fails

Otherwise, if I disable the java.awt.headless system property then everything works fine…

System.setProperty(“java.awt.headless”, “true”);

int MAX_BOOKS = 2;

for (int i = 0; i < MAX_BOOKS; i++) {
System.out.println(“Creating workbook " + (i + 1));

Workbook workbook = new Workbook();
Worksheet dataSheet = workbook.getWorksheets().add(“Data”);
Cells cells = dataSheet.getCells();

cells.get(“A1”).setValue(”");
cells.get(“A2”).setValue(“America”);
cells.get(“A3”).setValue(“Asia”);
cells.get(“B1”).setValue(“Total”);
cells.get(“B2”).setValue(“100”);
cells.get(“B3”).setValue(“98”);

Worksheet chartSheet = workbook.getWorksheets().get(
workbook.getWorksheets().add(SheetType.CHART));
chartSheet.setName(“Chart”);
workbook.getWorksheets().setActiveSheetIndex(chartSheet.getIndex());

Chart chart = chartSheet.getCharts().get(
chartSheet.getCharts().add(ChartType.LINE, 0, 0, 50, 50));
int index = chart.getNSeries().add("=Data!A2:B3", true);
chart.getNSeries().get(index).setName("=Data!" + “B1”);

chart.setSizeWithWindow(false);
chart.setShowLegend(false);

ImageOrPrintOptions imageOptions = new ImageOrPrintOptions();
imageOptions.setImageFormat(ImageFormat.getJpeg());

ByteArrayOutputStream imageOutputStream = new ByteArrayOutputStream();
chart.toImage(imageOutputStream, imageOptions);

System.out.println(“image " + (i + 1) + " Created”);
}

I have also attached the code along with this post.

Kindly suggest, if I am missing anything here or is there any alternate for this issue?

Thanks
Sundhar
Aspose OEM License Holder

Though this issue is similar to Wierd behaviour when using Worksheet.autoFitColumns() throws java.awt.HeadlessException, but the way this issue occurs is from different call.

I am not sure, if both are related to same root cause

Hi,


This issue is associated with other issue that we already logged for your other thread, the issue is logged with an id: CELLSJAVA-30489. We will investigate to figure out soon.

Thank you.

The issues you have found earlier (filed as CELLSJAVA-30489) have been fixed in this update.


This message was posted using Notification2Forum from Downloads module by Aspose Notifier.