Chart Title horizontal alignment does not work, always defaults to center

Hi Team,

I am trying to set the chart title’s horizontal alignment as RIGHT. But horizontal alignment is always coming as CENTER. Please find below the code which I am using.

Workbook workbook = new Workbook();
	Worksheet sheet = workbook.getWorksheets().get(0);

	Cells cells = sheet.getCells();
	cells.get(0, 1).putValue("Income");
	cells.get(1, 0).putValue("Company A");
	cells.get(2, 0).putValue("Company B");
	cells.get(3, 0).putValue("Company C");
	cells.get(1, 1).putValue(10000);
	cells.get(2, 1).putValue(20000);
	cells.get(3, 1).putValue(30000);

	int chartIndex = sheet.getCharts().add(com.aspose.cells.ChartType.COLUMN, 2, 2, 31, 21);

	Chart chart = sheet.getCharts().get(chartIndex);
	chart.getNSeries().add("B2:B4", true);
	chart.getNSeries().setCategoryData("A2:A4");

	Series aSeries = chart.getNSeries().get(0);
	aSeries.setName("=B1");
	chart.setShowLegend(true);
	chart.getTitle().setText("Income Analysis");
	chart.getTitle().setTextHorizontalAlignment(com.aspose.cells.TextAlignmentType.RIGHT );
	
	workbook.save("C:\\chartTitle.xlsx");

Attached the output excel. chartTitle.zip (8.4 KB)

Could you please let me know if I am doing anything wrong or guide me how to set chartTitle alignment

Thanks,
Thilak

@Thilakbabu,

Thanks for the output file.

I checked in MS Excel and there is no built-in feature to set chart title’s alignment Right. I can only find a few options for vertical alignment and text direction but there is no Right type alignment for the chart title. You can also confirm this in MS Excel manually for the chart. That’s why your line of code won’t work for chart’s title.

chart.getTitle().setTextHorizontalAlignment(com.aspose.cells.TextAlignmentType.RIGHT );

Aspose.Cells does provide to set/place title via X and Y attributes. Please note total area of the chart is 4000 (units) so you may devise your code a bit to accomplish your task. For example, you may try the line of code instead to place it on the right most side of the chart area:

chart.getTitle().setX(4000 - chart.getTitle().getWidth());

Hope, this helps a bit.