Hi,
Please run the following sample and see that - X-Axis tick labels are overlapped with Axis line when chart.getCategoryAxis().setRotation(-45)
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.DisplayUnitType;
import com.aspose.cells.FileFormatType;
import com.aspose.cells.GradientColorType;
import com.aspose.cells.GradientDirectionType;
import com.aspose.cells.GradientFill;
import com.aspose.cells.GradientFillType;
import com.aspose.cells.GradientStyleType;
import com.aspose.cells.ImageFormat;
import com.aspose.cells.ImageOptions;
import com.aspose.cells.LegendEntries;
import com.aspose.cells.PatternFill;
import com.aspose.cells.TickLabelPositionType;
import com.aspose.cells.TrendlineType;
import com.aspose.cells.Workbook;
import com.aspose.cells.Worksheet;
public class TickLabelAxisLineOverlap {
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[][] {
{1748, 11, 1151, 254, 332, 3134469, 5249538},
{23898210, 5777005, 6673706, 5361677, 6085822, 21063006, 19316327},
{18406, 14326, 1443, 1127, 1510, 4995, 7929},
{2217498, 405535, 635198, 446113, 730652, 1817664, 1342517}
};
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 chartWidth = 600;
int chartHeight = 400;
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);
String dataRef = dataSheet.getName() + "!" + CellsHelper.convertCellIndexToName(0, 0) + ":" + CellsHelper.convertCellIndexToName(data.length, colTitle.length - 1);
chart.getNSeries().add(dataRef, false);
String categoryAreaRef = dataSheet.getName() + "!" + CellsHelper.convertCellIndexToName(0, 0) + ":" + CellsHelper.convertCellIndexToName(0, colTitle.length - 1);
chart.getNSeries().setCategoryData(categoryAreaRef);
chart.getCategoryAxis().setRotation(-45);
chart.getCategoryAxis().setTickLabelPosition(TickLabelPositionType.LOW);
//chart.getValueAxis().setTickLabelPosition(TickLabelPositionType.LOW);
//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"));
System.out.println("successfully completed!!!" + CellsHelper.getReleaseVersion());
}
catch (Exception e) {
e.printStackTrace();
}
}
}