We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Charts toImage issue

I’m trying to add a preview of a chart in another workbook to a summary workbook.

attached you can see 2 charts, one with data showing and one without.

the one without is the result of the following code.


worksheet.getComments().add(row, col);
Comment com = worksheet.getComments().get(row, col);
try {
Workbook trWorkbook = workbookMap.get(“the correct workbook”);
ByteArrayOutputStream out = new ByteArrayOutputStream();
ImageOrPrintOptions iopOptions = new ImageOrPrintOptions();
iopOptions.setImageFormat(ImageFormat.getPng());
iopOptions.setHorizontalResolution(300);
iopOptions.setVerticalResolution(200);
iopOptions.setQuality(100);
trWorkbook.getWorksheets().get(2).getCharts().get(0).getChartObject().toImage(out, iopOptions);
com.getCommentShape().getFill().setImageData(out.toByteArray());
com.setHeightInch(5.0);
com.setWidthInch(7.0);
} catch (Exception e) {
e.printStackTrace();
}
Is there something I’m doing wrong? Or is there a chart setting that I am missing while making the chart that would make the image correctly?

Hi,


Thanks for providing us sample code, screenshots and details.

Could you try to change the line of code:
i.e.,
trWorkbook.getWorksheets().get(2).getCharts().get(0).getChartObject().toImage(out, iopOptions);
to:
trWorkbook.getWorksheets().get(2).getCharts().get(0).toImage(out, iopOptions);

if it makes any difference.

If you still find the issue, kindly do provide us your template Excel file (containing the chart) in question, we will check it soon.

Thank you.

Tried that suggestion and nothing changed.

the basic idea is that i am taking a chart from one workbook and then using toImage on that chart so i can put that image in a comment on the other workbook


is it possible i am not setting up the chart correctly?

here’s the code for each chart being made


chart.getNSeries().add("’" + hiddenInfo.getWorksheet().getName() + “’!$Y” +
“$” + hiddenInfo.getDataStartRow() + “:$Y$” + hiddenInfo.getDataEndRow(), true);
chart.getNSeries().get(i).setXValues("’" + hiddenInfo.getWorksheet().getName() + “’!$B$” + hiddenInfo.getDataStartRow() + “:$B$” + hiddenInfo.getDataEndRow());
chart.getNSeries().get(i).setName(groupList.get(i));

chart.getNSeries().get(i).getSeriesLines().setVisible(false);
chart.getNSeries().get(i).getLine().setVisible(false);
chart.getNSeries().get(i).getLeaderLines().setVisible(false);
chart.getNSeries().get(i).getDropLines().setVisible(false);

chart.getCategoryAxis().getTitle().setText(“Timestamp”);
chart.getCategoryAxis().setMajorTickMark(TickMarkType.OUTSIDE);
chart.getCategoryAxis().setAutomaticMajorUnit(true);
chart.getCategoryAxis().setAutomaticMinorUnit(true);
chart.getValueAxis().setMajorTickMark(TickMarkType.OUTSIDE);
chart.getValueAxis().setAutomaticMajorUnit(true);
chart.getValueAxis().setAutomaticMinorUnit(true);
chart.getValueAxis().getTitle().setText(tr.getDisplayName());
chart.getChartObject().setName(tr.getDisplayName());
chart.getChartObject().setPrintable(true);
chart.setAutoScaling(true);

Hi,


Thanks for sharing further details and code snippet.

I think you should simply try to save the chart (with updated data or other formattings) in your original workbook to Excel file to check if the chart is displayed properly or not. Also, I am afraid, we need to evaluate your issue thoroughly with your complete JAVA program (runnable) and your template file, so we could better help you on it. So, kindly do the needful and provide your sample JAVA program (runnable) and template file to investigate your issue soon.

Thank you.