Specify TextBox margin inside chart

How can I specify TextBox margin inside chart?
I have created TextBox in chart as follows.
TextBox sh = chart.getShapes().addTextBoxInChart(0, 3500, 200, 500);

Full code and expected screenshot are attached.

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

	// Adding some sample value to cells
	Cells cells = sheet.getCells();
	Cell cell = cells.get("A1");
	cell.setValue(77430413.36);//
	
	cell = cells.get("A2");
	cell.setValue(16736103.67);
	
	cell = cells.get("A3");
	cell.setValue(19976585.27);
	
	cell = cells.get("B1");
	cell.setValue(202900375.97);
	
	cell = cells.get("B2");
	cell.setValue(98687169.34);
	
	cell = cells.get("B3");
	cell.setValue(29872744.72);
	
	cell = cells.get("c1");
	cell.setValue(10076585.23);
	
	cell = cells.get("c2");
	cell.setValue(9976585.91);
	
	cell = cells.get("c3");
	cell.setValue(8876585.17);
	
	ChartCollection charts = sheet.getCharts();
	
	// Adding a chart to the worksheet
	int chartLastColumn = 11;
	int chartLastRow = 20;//25
	int chartIndex = charts.add(ChartType.COLUMN, 5, 0, chartLastRow, chartLastColumn);
	Chart chart = charts.get(chartIndex);
	
		
	String chartTitle = "Chart Title Alignment Test";
	
	TextBox sh = chart.getShapes().addTextBoxInChart(0, 3500, 200, 500);
	sh.getLineFormat().setVisible(false);
	sh.setText("1111111111 22222222222222 333333333333333 4444444444444 5555555555");
	sh.getTextFrame().setAutoSize(true);
	sh.setTextWrapped(false);
	int[] size = sh.calculateTextSize();
	sh.setHeight(size[1]);
	sh.setWidth(size[0]);
	sh.getFill().setType(FillType.NONE);
	sh.setPlacement(PlacementType.FREE_FLOATING);
	sh.setTextHorizontalAlignment(TextAlignmentType.RIGHT);	
	sh.getFont().setSize(9);
	sh.getFont().setBold(true);
	sh.getFont().setName("Arial");
	sh.getLineFormat().setVisible(false);
	//sh.getTextFrame().setTopMarginPt(0.0);
			
	Title title = chart.getTitle();
	title.setText(chartTitle);
	
	// Adding NSeries (chart data source) to the chart ranging from "A1"
	// cell to "B3"
	SeriesCollection serieses = chart.getNSeries();
	serieses.add("A1:C3", true);
	for (int i = 0; i < serieses.getCount(); i++) {
		serieses.get(i).getDataLabels().setValueShown(true);
	}
	
	// Saving the Excel file
	workbook.save("AsposeShapeMargin.xlsx");

ChartTextBoxMargin.PNG (63.0 KB)

@Muhammed.Karattu,

Please note, the unit for width and height of chart area is 1/4000. So, you should place the textbox (taking its height and width in account) with respect to chart area’s x, y and its height/width attributes. You may write your logic to insert your custom text boxes around your desired position accordingly. See the following sample line of code that inserts the sample text box inside chart.

TextBox txt1 =  chart.getShapes().addTextBoxInChart(chart.getPlotArea().getY()+450,chart.getPlotArea().getX()+585, 300, 650);
....

Moreover, please see the document with details and examples on how to insert controls to charts for your complete reference.
https://docs.aspose.com/cells/java/controls-in-charts/

@Muhammed.Karattu,
You can add the following code to set the margin.

TextBox sh = chart.getShapes().addTextBoxInChart(0, 3500, 200, 500);
ShapeTextAlignment textBoxAlign = sh.getTextBody().getTextAlignment();
textBoxAlign.setBottomMarginPt(1.0);
textBoxAlign.setTopMarginPt(1.0);
textBoxAlign.setLeftMarginPt(1.0);
textBoxAlign.setRightMarginPt(1.0);

Hope helps a bit.

Hi John.He,
This is working with Aspose.Cells 16.x version.
However we are using Aspose.Cells 8.x version where this API is not available.
Any way to achieve this in Aspose.Cells 8.x version?

@Muhammed.Karattu,

We are sorry but we are not sure if such a feature (to set margin for text box shape inside the chart) was available in older version (8.x version) of Aspose.Cells. You may browse the API Reference if these APIs are there in your Aspose.Cells version. We can only recommend you to try using newer versions of the APIs.

I believe your APIs are not backward compatible. We need to make many code changes to upgrade to latest versions.

@Muhammed.Karattu,

Mostly, the APIs are backward compatible, but for some features/cases, we have enhanced them. We have implemented better naming conventions to ensure API naming uniformity, making them more readable and consistent across the board. However, we apologize for any inconvenience caused and will try to avoid such practices as much as possible. You may need to update your existing sample code slightly.

If you encounter any issues while updating your existing code segments to newer versions, kindly let us know, and we will be happy to assist you soon.