Chart.toImage - Legend entry missing from image when Legend placement is TOP or BOTTOM

Hi,

Please find the sample below and see the issues mentioned below.

1. Legend entry(2004) missing from image when Legend placement is TOP or BOTTOM
2. Right margin in chart and image are not same.

Thanks
Muhammed

import java.io.ByteArrayOutputStream;
import java.io.FileInputStream;
import java.io.FileOutputStream;

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.FileFormatType;
import com.aspose.cells.ImageFormat;
import com.aspose.cells.ImageOptions;
import com.aspose.cells.LegendPositionType;
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 ScatterPlotLegend {

public static void main(String args[]) {

try {
String[] colTitle = new String[] { "2002",
"Q1-2002",
"Q2-2002",
"Q3-2002",
"Q4-2002",
"2003",
"2004"
};

//Array of cell data
double[][] data = new double[][] { {2E+06, 184060, 405535, 143260, 635198, 144003, 446113},
{112700, 730652, 151000, 2E+06, 499500, 1E+06, 792900}
};

Workbook wb = new Workbook();
Worksheet dataSheet = wb.getWorksheets().addSheet();

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.SCATTER, 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);

series.setMarkerStyle(ChartMarkerType.CIRCLE);

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

chart.getLegend().setPosition(LegendPositionType.BOTTOM);

//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"));

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

}

Hi,

After an initial test, we found the issue, we will figure it out soon.

Your issue has been logged into our issue tracking system with an issue id: CELLSJAVA-16003.

We will inform you when it is sorted out.

Thank you.

Hi,

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

Thank you.

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


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

working fine