ScatterChart.toImage - marker size using setMarkerSize is not reflected in the image generated

Hi,

Please find the sample below and see that marker size set using series.setMarkerSize is not reflected in the image. Instead legend entry marker is resized wrongly.

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.ChartMarkerType;
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.PatternFill;
import com.aspose.cells.SheetType;
import com.aspose.cells.TickLabelPositionType;
import com.aspose.cells.TickMarkerType;
import com.aspose.cells.TrendlineType;
import com.aspose.cells.WeightType;
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 ScatterMarkerSize {

public static void main(String args[]) {

try {
String[] cellsName = new String[] { "A2", "A3",
"B2", "B3",
"C2", "C3",
"D2", "D3",
"E2", "E3",
"F2", "F3",
"G2", "G3",
"H2", "H3",
"I2", "I3",
};

//Array of cell data
double[] cellsValue = new double[] { 1.001, 73,
1.626, 1273211,
1.257, 930732.6,
1.666, 2284024,
2.352, 262502,
2.636, 4973.4,
1.835, 2554.3,
1.399, 33498.3,
1.874, 67.9
};

Workbook wb = new Workbook();
Worksheet dataSheet = wb.getWorksheets().addSheet();
wb.getPalette().setColor(55, Color.RED);
wb.getPalette().setColor(54, Color.GREEN);
wb.getPalette().setColor(53, Color.YELLOW);

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

//Populate DataSheet with data
dataSheet.getCells().getCell("A1").setValue("BrandA Rinse Conditioners");
dataSheet.getCells().getCell("B1").setValue("BrandB Rinse Conditioners");
dataSheet.getCells().getCell("C1").setValue("BrandC Rinse Conditioners");
dataSheet.getCells().getCell("D1").setValue("BrandD Rinse Conditioners");
dataSheet.getCells().getCell("E1").setValue("BrandE Rinse Conditioners");
dataSheet.getCells().getCell("F1").setValue("BrandF Rinse Conditioners");
dataSheet.getCells().getCell("G1").setValue("BrandG Rinse Conditioners");
dataSheet.getCells().getCell("H1").setValue("BrandH Rinse Conditioners");
dataSheet.getCells().getCell("I1").setValue("BrandI Rinse Conditioners");

int size = Array.getLength(cellsName);
for (int i = 0; i < size; i++) {
String cellName = cellsName[i];
double cellValue = cellsValue[i];
dataSheet.getCells().getCell(cellName).setValue(cellValue);
}

//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.SCATTER, 0, 0, 1, 1, 300, 200);

//double dummyPoint[] = new double[9];

int rowIndex = 0;
for (int i = 0; i < 9; 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());
series.setMarkerStyle(ChartMarkerType.CIRCLE);

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

series.setMarkerSize(15);

//dummyPoint[i] = dataSheet.getCells().getCell(dataRef).getDoubleValue().doubleValue();

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

String dummySeriesRef = dataSheetName + "!A3:I3";

chart.getValueAxis().getMajorGridLines().setVisible(true);
chart.getValueAxis().getMinorGridLines().setVisible(false);
chart.getValueAxis().setTickLabelPosition(TickLabelPositionType.NEXT_TO_AXIS);
chart.getValueAxis().setMajorTickMark(TickMarkerType.OUTSIDE);

chart.getCategoryAxis().getMajorGridLines().setVisible(true);
chart.getCategoryAxis().getMinorGridLines().setVisible(false);

chart.getValueXAxis().getMajorGridLines().setVisible(true);
chart.getValueXAxis().getMinorGridLines().setVisible(false);
chart.getValueXAxis().setTickLabelPosition(TickLabelPositionType.NEXT_TO_AXIS);
chart.getValueXAxis().setMajorTickMark(TickMarkerType.OUTSIDE);

//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("ScatterChartMaker 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-15731.

Thank You & Best Regards,

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


This message was posted using Notification2Forum from Downloads module by aspose.notifier.

Hi,
Its working fine now.
Thanks
Muhammed