Free Support Forum - aspose.com

chart.toImage - Axis tick label differes from actual chart - Bar Chart

Hi,

Please run the following sample find the issues mentioned below.

1. On Value Axis, label entries are not proper.
2. Category axis positioning is diff in chart and image. In image category axis is positioned at extreme left, where as chart has category axis in the middle.

import java.io.*;

import java.lang.reflect.Array;

import com.aspose.cells.ImageFormat;

import com.aspose.cells.*;

import com.aspose.slides.*;

public class AxisLabelConflict {

public static void main(String args[]) {

try {

String[] cellsName = new String[] { "B1", "B2", "B3", "B4",

"C1", "C2", "C3", "C4",

"D1", "D2", "D3", "D4",

"E1", "E2", "E3", "E4",

"F1", "F2", "F3", "F4"

};

//Array of cell data

int[] cellsValue = new int[] { 67, 86, 68, 91,

44, -64, -89, 48,

46, -97, 78, 6,

43, -29, 69, 26,

24, 4, -38, 25 };

Workbook wb = new Workbook();

Worksheet dataSheet = wb.getWorksheets().getSheet(0);

String dataSheetName = "DataSheet";

dataSheet.setName(dataSheetName);

dataSheet.getCells().getCell("A1").setValue("India");

dataSheet.getCells().getCell("A2").setValue("United States");

dataSheet.getCells().getCell("A3").setValue("United Kingdom");

dataSheet.getCells().getCell("A4").setValue("Japan");

dataSheet.getCells().getCell("A5").setValue("China");

//Populate DataSheet with data

int size = Array.getLength(cellsName);

for (int i = 0; i < size; i++) {

String cellName = cellsName[i];

int 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 chartWidth = 400;

int chartHeight = 300;

int chartHeightInRows = 0;

int chartWidthInCols = 0;

int cellWidth = dataSheet.getCells().getColumnWidthPixel(0);

int cellHeight = dataSheet.getCells().getRowHeightPixel(0);

chartWidthInCols = (int)(chartWidth / cellWidth);

chartHeightInRows = (int)(chartHeight / cellHeight);

chartWidth = chartWidthInCols * cellWidth;

chartHeight = chartHeightInRows * cellHeight;

System.out.println("OLE SIZE = Cols: " + chartWidthInCols + ", Rows: " + chartHeightInRows);

System.out.println("CHART SIZE = chartWidth: " + chartWidth + ", chartHeight: " + chartHeight);

Chart chart = chartSheet.getCharts().addChart(ChartType.BAR_CLUSTERED, 0, 0, 0, 0, chartWidth, chartHeight);

chart.getNSeries().add(dataSheetName + "!B1:F4", false);

for (int i = 0; i < chart.getNSeries().size(); i++) {

ASeries series = chart.getNSeries().get(i);

PatternFill pf = new PatternFill();

pf.setBackgroundColor(wb.getPalette().getColor(i));

pf.setForegroundColor(wb.getPalette().getColor(i));

series.getArea().setFill(pf);

}

String categoryAreaRef = dataSheet.getName() + "!A1:A5";

chart.getNSeries().setCategoryData(categoryAreaRef);

/*chart.getCategoryAxis().setDisplayUnitLabelShown(false);

chart.getCategoryAxis().setTickLabelPosition(TickLabelPositionType.NONE);*/

chart.getTitle().setText("Aspose.Cells");

//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, chartHeightInRows - 1, 0, chartWidthInCols - 1);

//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.getSlideByPosition(1);

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

int slideHeight = (int) pres.getSlideSize().getY();

int x = (slideWidth - chartWidth * 8) / 2;

int y = (slideHeight - chartHeight * 8) / 2;

OleObjectFrame oof = sld.getShapes().addOleObjectFrame(800, 500, chartWidth * 8, chartHeight * 8, "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("successfully completed!!!");

}

catch (Exception e) {

e.printStackTrace();

}

}

}

Hi,

Thanks for providing us sample code.

We found the issues (1 and 2) using your code. We will figure it out soon.

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

Thank you.

Hi,

Please try the attached version. We have fixed the issue of label entries for Value Axis. For the issue of
CategoryAxis’ position, we are still working on it and will provide new fix when
we finish it.

Thank you.

Hi,
In the excel chart, I am having tick labels -200, -100, 0, 100, 200, whereas in image its -150, 100, -50, 0, 50, 100, 150.

Please cross check.

-Muhammed

Hi,

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

Thank you for your feedback.

Well, I checked your issue with Aspose.Cells for Java V2.1.2.1 and the tick labels in the generated image file are same as XLS file. The xls file shows the same tick labels i.e. -150, 100, -50, 0, 50, 100, 150 when you open it in Excel 2003. But if you open the file in MS Excel 2007, it shows -200, -100, 0, 100, and 200. I think this is the different behavior of MS Excel version and not an issue with Aspose.Cells.

Thank You & Best Regards,

Ok…
Can you please let me know the ETA for axis positioning issue?
_Muhammed

Hi,



We are working on your issue and hopefully we can provide you a fix in the next week.



Thanks for your understanding!

Hi,

This issue has been pending for long. Is there any update on the axis positioning issue?

Thanks,

Hi,

As we told you, we are working on your issue and hopefully we can provide you a fix in this week.

Thanks for your understanding!

Hi.

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

Please try the attached latest version and let us know if it works fine for you.

Thank You & Best Regards,

Hi,

Category axis positioning is correct in the image now.

Thanks
-Muhammed

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


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