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

Free Support Forum - aspose.com

Chart.toImage - Axis tick labels with rotation of 45 overlaps with plot area

Hi,

Plaese find the below sample which demonstrate the issue mentioned -
1. I have set a rotation of 45 for category axis tick labels. When I take image using toImage, it overlaps with plot area. Plaese find the screen shot for details.

I am using Aspose.CellsV2.1.2.4. BTW, do you have any utility class/method to find aspose version? Now I have a bunch of Aspose.Cells jar files. It was nice if I can get the version with a single line of code in my java file.

-Muhammed

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 * -1, -89 * -1, 48,
46, -97 * -1, 78, 6,
43, -29 * -1, 69, 26,
24, 4, -38 * -1, 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;

Chart chart = chartSheet.getCharts().addChart(ChartType.COLUMN_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().setTickLabelPosition(TickLabelPositionType.NEXT_TO_AXIS);
chart.getCategoryAxis().setRotation(45);

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,

1) I have found the issue as you have mentioned. I have logged your issue into our issue tracking system with an issue id: CELLSJAVA-14681. We will inform you when it is sorted out.

2) Yes, Aspose.Cells for Java does provide CellsHelper.getReleaseVersion() API to get the version number of the component.
See the document for further reference:
http://www.aspose.com/documentation/java-components/aspose.cells-for-java/check-version-number-of-the-component.html

Thanks for your continuous testing and enhancing the Chart to Image feature.

Hi,

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

Please try the attached latest version. We have fixed the issue of tick labels overlapping the plot area.

Thank You & Best Regards,

Working fine.

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


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

Hi,

Please change the orientation to -45, and see that generated image still show 45 orientation.

Change
chart.getCategoryAxis().setRotation(45);

to

chart.getCategoryAxis().setRotation(-45);

Note that actual excel chart shows -45 orientation.

If you change the following lines, you can see it rotate -45 in the image as well. (Although it overlaps with axis line - another issue already logged for that.)

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

to

dataSheet.getCells().getCell("A2").setValue("US");
dataSheet.getCells().getCell("A3").setValue("UK");

Thanks
Muhammed

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

We have found your mentioned issue regarding Axis tick Label rotation. We have re-opened your issue (issue id: CELLSJAVA-14681). We will look into it and get back to

Thank You & Best Regards,

Hi,

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

Please try the attached latest version of Aspose.Cells for Java. We have fixed your mentioned issue.

Thank You & Best Regards,