In GcExcel Java, you can use the methods of the IChart interface in order to configure the chart title of your choice.
You can work with Chart title in the following ways:
To set formula for chart title, refer to the following example code.
Java |
Copy Code |
---|---|
// Set formula for chart title. shape.getChart().setHasTitle(true); shape.getChart().getChartTitle().getTextFrame().getTextRange().getParagraphs().add("ChartSubtitle"); shape.getChart().getChartTitle().getTextFrame().getTextRange().getParagraphs().add("ChartTitle", 0); |
To set format for chart title and font style, refer to the following example code.
Java |
Copy Code |
---|---|
// Set chart titale's format and font style. shape.getChart().setHasTitle(true); //shape.getChart().getChartTitle().setText("MyChartTitle"); shape.getChart().getChartTitle().getFormat().getFill().getColor().setRGB(Color.GetDarkOrange()); shape.getChart().getChartTitle().getFormat().getLine().getColor().setRGB(Color.GetCornflowerBlue()); |
You can also configure the text angle for chart title by using the setOrientation method of IChartTitle interface. The text angle can also be exported or imported to JSON.
Refer to the following example code to set text angle for chart title.
Java |
Copy Code |
---|---|
//create a new workbook Workbook workbook = new Workbook(); // Fetch default worksheet IWorksheet worksheet = workbook.getWorksheets().get(0); //add chart IShape shape = worksheet.getShapes().addChart(ChartType.ColumnClustered, 250, 20, 360, 230); worksheet.getRange("A1:D6").setValue(new Object[][] { {null, "S1", "S2", "S3"}, {"Item1", 10, 25, 25}, {"Item2", -20, 36, 27}, {"Item3", 62, 70, -30}, {"Item4", 22, 65, 65}, {"Item5", 23, 50, 50} }); shape.getChart().getSeriesCollection().add(worksheet.getRange("A1:D6"), RowCol.Columns, true, true); //add chart title shape.getChart().setHasTitle(true); shape.getChart().getChartTitle().setText("MyChartTitle"); //config chart title angle shape.getChart().getChartTitle().setOrientation(30); //save to an excel file workbook.save("configcharttitleangle.xlsx"); |