Chart (X - Axis & Y - Axis Title) Issue

Hi,


I have created a Bar chart in a ods file using Aspose api. Set the x - axis and y - axis title. But x axis title is displaying vertically and y - axis title is displaying horizontally. Attached the document.

Regards,
Santhosh

Hi Santhosh,


Can you please share your source code that can re-create this problem. Thanks

Hi,


Here is my code,

com.aspose.cells.Charts chartsObject = sheet.getCharts();
com.aspose.cells.Chart chart = chartsObject.addChart(ChartType.BAR_CLUSTERED, 5, 0, 15, 5);
com.aspose.cells.ChartShape chartShp = chart.getChartShape();

//Set chart height and width
chartShp.setHeight(chartHeight);
chartShp.setWidth(chartWidth);
chartShp.setPositionXY(chartXPos, chartYPos);

//Set Title for X-axis and Y-axis
if(xAxisTitle != null)
{
chart.getCategoryAxis().getTitle().setText(xAxisTitle);
}
if(yAxisTitle != null)
{
chart.getValueAxis().getTitle().setText(yAxisTitle);
}
chart.setLegendShown(chartLegend);
com.aspose.cells.NSeries serieses = chart.getNSeries();
com.aspose.cells.Title title = chart.getTitle();

serieses.add(chartRange, seriesIn, isRowHeader, isColHeader); //SeriesIn rows/cols
title.setText(chartTitle); //Set the chart Title

Regards,
Santhosh

Hi,

Well, I think you misunderstood the category and value axis of the BAR Clustered chart. It is not an issue. The category axis is rendered vertically while the value axis is rendered horizontally. You may confirm this in Excel for your verification. Aspose.Cells works fine and in the same way as MS Excel does. So you need to adjust your code accordingly. E.g you may set:

chart.getCategoryAxis().getTitle().setText(yAxisTitle);
//…
chart.getValueAxis().getTitle().setText(xAxisTitle);


Here is my other test code, I generate ODS and XLS file that looks fine and identical regarding x-axis and y-axis titles.

Sample code:
Workbook book = new Workbook();
Worksheet sheet = book.getWorksheets().getSheet(0);
Cells cells = sheet.getCells();
Cell cell;

cell = cells.getCell(0, 0);
cell.setValue(“value A”);
cell = cells.getCell(0, 1);
cell.setValue(9.53);

cell = cells.getCell(1, 0);
cell.setValue(“value B”);
cell = cells.getCell(1, 1);
cell.setValue(5.17);

cell = cells.getCell(2, 0);
cell.setValue(“value C”);
cell = cells.getCell(2, 1);
cell.setValue(1.27);

Chart chart = sheet.getCharts().addChart(ChartType.BAR_CLUSTERED, 0, 2, 10, 10);
chart.getNSeries().add(“B1:B3”, true);
chart.getNSeries().setCategoryData(“A1:A3”);





chart.getCategoryAxis().getTitle().setText(“My y Axis title”);

chart.getValueAxis().getTitle().setText(“My X Axis Title”);

chart.getValueAxis().getTitle().getFont().setBold(true);
chart.getValueAxis().getTitle().setRotation(90);


book.save(“MyoutputODS” + “.ods”, FileFormatType.ODS);
book.save(“MyoutputXLS” + “.xls”, FileFormatType.EXCEL97TO2003);

Thank you.