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

Free Support Forum - aspose.com

Set the rotation angle of chart axis title in Java

Hi, i would like to update the title text direction from vertical to horizontal, but i didn’t find a way can do that: can you please help? here’s my sample code.

i tried:
chart.getValueAxis().getTitle().setRotationAngle()
chart.getValueAxis().getTitle().setTextDirection();
chart.getValueAxis().getTitle().setHorizontalAlignment();
chart.getValueAxis().getTitle().setVerticalAlignment();

    Workbook workbook = new Workbook();
    WorksheetCollection worksheets = workbook.getWorksheets();

// Obtaining the reference of the first worksheet
    Worksheet worksheet = worksheets.get(0);
    Cells cells = worksheet.getCells();

    cells.get(“A1”).setValue(16393);

    cells.get(“B1”).setValue(“Microsoft”);


// Adding a chart to the worksheet
    ChartCollection charts = worksheet.getCharts();

// Accessing the instance of the newly added chart
    int chartIndex = charts.add(ChartType.BAR, 5, 5, 40, 25);
    Chart chart = charts.get(chartIndex);

    SeriesCollection nSeries = chart.getNSeries();
    nSeries.add(“A1:A1”, true);
    nSeries.setCategoryData(“B1:B1”);

    Title title = chart.getTitle();
    title.setText(“Top Employers”);

// Setting the font color of the chart title to blue
    Font font = title.getFont();
    font.setColor(Color.getBlue());

    Axis valueAxis = chart.getValueAxis();
    title = valueAxis.getTitle();
    title.setText(“number of followers”);
//    title.setRotationAngle(90);
//    title.setTextDirection();
//    title.setTextHorizontalAlignment(0);
//    title.setTextVerticalAlignment(1);

//    nSeries.changeSeriesOrder(0, 9);

    workbook.save(“sampleChart1.xls”);

I think this is a bug related to bar chart, when create bar chart the default value title text direction is vertical, which should be horizontal.

Hi,


Thanks for your posting and using Aspose.Cells.

Please set the rotation angle of your axis title to 0 not 90. Please see the following sample code, the red line inside the code which is modified by us in your original code as well as the output Excel file generated by the code for your reference.

Java
Workbook workbook = new Workbook();

WorksheetCollection worksheets = workbook.getWorksheets();

// Obtaining the reference of the first worksheet

Worksheet worksheet = worksheets.get(0);

Cells cells = worksheet.getCells();

cells.get(“A1”).setValue(16393);

cells.get(“B1”).setValue(“Microsoft”);

// Adding a chart to the worksheet

ChartCollection charts = worksheet.getCharts();

// Accessing the instance of the newly added chart

int chartIndex = charts.add(ChartType.BAR, 5, 5, 40, 25);

Chart chart = charts.get(chartIndex);

SeriesCollection nSeries = chart.getNSeries();

nSeries.add(“A1:A1”, true);

nSeries.setCategoryData(“B1:B1”);

Title title = chart.getTitle();

title.setText(“Top Employers”);

// Setting the font color of the chart title to blue

Font font = title.getFont();

font.setColor(Color.getBlue());

Axis valueAxis = chart.getValueAxis();

title = valueAxis.getTitle();

title.setText(“number of followers”);

title.setRotationAngle(0); //>>>>>>>>>>>>>modified this line

workbook.save(dirPath + “sampleChart1.xls”);