BubbleChart - toImage generated image differs from actual chart

Hi,
Please run the sample below and find the following issues in image generated.

1) DataLabels are not present in the image
2) X and Y axis min and max values and interval are not same in chart and image
3) Legend box height is not similar in image and chart
4) Legend marker shape is not same in image and chart

Thanks
Muhammed

import java.io.ByteArrayOutputStream;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.lang.reflect.Array;

import com.aspose.cells.ASeries;
import com.aspose.cells.CellsHelper;
import com.aspose.cells.Chart;
import com.aspose.cells.ChartType;
import com.aspose.cells.Color;
import com.aspose.cells.FileFormatType;
import com.aspose.cells.ImageFormat;
import com.aspose.cells.ImageOptions;
import com.aspose.cells.LegendPositionType;
import com.aspose.cells.MsoLineDashStyle;
import com.aspose.cells.PatternFill;
import com.aspose.cells.SheetType;
import com.aspose.cells.TickLabelPositionType;
import com.aspose.cells.Workbook;
import com.aspose.cells.Worksheet;
import com.aspose.slides.OleObjectFrame;
import com.aspose.slides.Presentation;
import com.aspose.slides.Slide;

public class BubbleChartGridLines {

public static void main(String args[]) {

try {
String[] colTitle = new String[] { "BrandA Rinse Conditioners",
"BrandB Ltd Rinse Conditioners",
"BrandC Rinse Conditioners",
"BrandD Rinse Conditioners",
"BrandE Rinse Conditioners",
"BrandF Rinse Conditioners",
"BrandG Rinse Conditioners",
"BrandH Rinse Conditioners",
"BrandJ Rinse Conditioners"
};

//Array of cell data
double[][] data = new double[][] { {1.689, 1.808, 0, 1.027, 1.896, 1.95, 1.225, 1.358, 1.07},
{62925500, 1851840, 0, 699800.8, 56409260, 2, 665954.2, 305, 49353140},
{106295400, 3347520, 0, 718515.3, 106955700, 3.9, 816087.1, 414.2, 52803340}
};

Workbook wb = new Workbook();
Worksheet dataSheet = wb.getWorksheets().addSheet();
wb.getPalette().setColor(0, new Color(0xFF, 0x00, 0x00));
wb.getPalette().setColor(1, new Color(0x42, 0xDF, 0xF4));
wb.getPalette().setColor(2, new Color(0x00, 0xF4, 0x65));
wb.getPalette().setColor(3, new Color(0xF9, 0x04, 0x21));

String dataSheetName = "DataSheet";
dataSheet.setName(dataSheetName);

int rowIndex = 0;
for (int i = 0; i < colTitle.length; i++) {
dataSheet.getCells().getCell(rowIndex, i).setValue(colTitle[i]);
}

for (int i = 0; i < data.length; i++) {
for (int j = 0; j < data[i].length; j++) {
dataSheet.getCells().getCell(i + 1, j).setValue(data[i][j]);
}
}

//Add a chart sheet
Worksheet chartSheet = wb.getWorksheets().addSheet();
chartSheet.setName("ChartSheet");
int chartSheetIdx = chartSheet.getIndex();

//Add a chart in ChartSheet with data series from DataSheet
int chartRows = 25, chartCols = 15;

Chart chart = chartSheet.getCharts().addChart(ChartType.BUBBLE, 0, 0, 1, 1, 500, 400);
for (int i = 0; i < colTitle.length; i++) {
String dataRef = "=" + dataSheet.getName() + "!$" + CellsHelper.convertColumnIndexToName(i) + "$" + (rowIndex + 3);
int index = chart.getNSeries().add(dataRef, true);
ASeries series = chart.getNSeries().get(index);
//String nameRef = dataSheet.getName() + "!$" + CellsHelper.convertColumnIndexToName(lid) + "$" + (rowIndex + 1);
series.setName(dataSheet.getCells().getCell(rowIndex, i).getStringValue());

String xRef = "=" + dataSheet.getName() + "!$" + CellsHelper.convertColumnIndexToName(i) + "$" + (rowIndex + 2);
series.setXValues(xRef);

String bRef = "=" + dataSheet.getName() + "!$" + CellsHelper.convertColumnIndexToName(i) + "$" + (rowIndex + 4);
series.setBubbleSizes(bRef);

series.getDataLabels().setValueShown(true);

//System.out.println("DataRef = " + dataRef + ", xRef = " + xRef + ", bRef = " + bRef);
}

short dashType = MsoLineDashStyle.SOLID;
chart.getValueAxis().getMajorGridLines().setVisible(true);
chart.getValueAxis().getMajorGridLines().setDashType(dashType);
chart.getValueXAxis().getMajorGridLines().setVisible(true);
chart.getValueXAxis().getMajorGridLines().setDashType(dashType);

chart.getTitle().setText("Bubble Chart");
chart.getLegend().setPosition(LegendPositionType.LEFT);

//Get Chart as image.
ImageOptions imgOpts = new ImageOptions();
imgOpts.setImageFormat(ImageFormat.PNG);
imgOpts.setFashion(FileFormatType.EXCEL2003);

chart.toImage(new FileOutputStream("D:\\Temp\\chart.png"), imgOpts);

wb.getWorksheets().setActiveSheet(chartSheetIdx);
wb.setOleSize(0, chartRows, 0, chartCols);

//Save the workbook to stream
ByteArrayOutputStream bout = new ByteArrayOutputStream();
wb.save(bout);
wb.save(new FileOutputStream("D:\\Temp\\output.xls"));

Presentation pres = new Presentation();
Slide sld = pres.addEmptySlide();

int slideWidth = (int) pres.getSlideSize().getX() - 1500;

int slideHeight = (int) pres.getSlideSize().getY();
int x = 1500 / 2;
OleObjectFrame oof = sld.getShapes().addOleObjectFrame(x, 0, slideWidth, slideHeight, "Excel.Sheet.8", bout.toByteArray());

com.aspose.slides.Picture pic = new com.aspose.slides.Picture(pres, new FileInputStream("D:\\Temp\\chart.png"));
int picId = pres.getPictures().add(pic);
oof.setPictureId(picId);

//Write the presentation on disk
pres.write(new FileOutputStream("D:\\Temp\\output.ppt"));
System.out.println("BubbleChartGridLines successfully completed!!!" + CellsHelper.getReleaseVersion());

}
catch (Exception e) {
e.printStackTrace();
}
}

}

Hi,

<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thank you for sharing the sample code.

We have found your mentioned issue after an initial test. We will look into it and get back to you soon. Your issue has been registered in our internal issue tracking system with issue id: CELLSJAVA-15228.

Thank You & Best Regards,

Hi,

Please try the attached version.

We have fixed the issue of Legend marker shape and DataLabels. The Legend
in the generated image has been improved too. For the issue of X&Y axis
min&max values, we are still working on it.


Thank you.

Hi,

1) DataLabels are not present in the image :- DataLabels are present in image, but positioning seems to be different from chart

2) X and Y axis min and max values and interval are not same in chart and image :- Not Fixed

3) Legend box height is not similar in image and chart :- Not Fixed

4) Legend marker shape is not same in image and chart :- Working fine

Thanks
Muhammed

Hi,

1) We noticed the issue with the positioning of the data labels.
2) As we declared we are still working on it.
3) We noticed the issue and will try to figure it out.



Thank you.

Hi,

Some of the issues mentioned seems to be working fine in latest release(2.2.0.0).
(X axis interval is not same in image and chart)

Also, Legend box height is not similar in image and chart :- Not Fixed

Thanks
Muhammed

Hi,

<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thank you for the feedback.

We will further look into your reported issues and get back to you soon. We have reopened your issue with issue id : CELLSJAVA-15228.

Thank You & Best Regards,

Hi,<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Please try the attached latest version. We have fixed your mentioned issue.

Thank You & Best Regards,

Hi,<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Also, to further update you, please call Workbook.calculateFormula() before Chart.toImage(). In the old versions, we call calculateFormula() automatically in Chart.toImage(). But it was a big issue performance wise (to calculate all formulas repeatedly for every chart when there are lots of charts and formulas). So, in our latest fix and the new versions, we will remove the calculateFormula() operation from Chart.toImage() and it is needed for the users to call it manually, if there are formulas set by API and have not been calculated.

Thank You & Best Regards,

Hi,

issue 3 still persist. Rest of them are working fine.
3) Legend box height is not similar in image and chart :- Not Fixed

Thanks
Muhammed

Hi,

We will soon look into the legend’s size issue in the generated chart image and get back to you.

Thank you.