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)