Document Solutions for Excel, Java Edition | Document Solutions
Features / Chart / Configure Chart / Chart Title
In This Topic
    Chart Title
    In This Topic

    In DsExcel 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:

    Set Formula for Chart Title

    To set formula for chart title, refer to the following example code.

    Copy Code
    // Set formula for chart title.
    shape.getChart().getChartTitle().getTextFrame().getTextRange().getParagraphs().add("ChartTitle", 0);

    Set Format for Chart Title and Font Style

    To set format for chart title and font style, refer to the following example code.

    Copy Code
    // Set chart titale's format and font style.

    Set Direction of Chart Title

    You can set the direction of the chart title to horizontal, vertical, rotated (to 90 or 270 degree), and stacked (with text reading left-to-right or right to left). The setDirection method in IChartTitle and IChartTitle.ITextFrame interfaces allows you to set the direction of the chart title using TextDirection enumeration.

    Refer to the following example code to set vertical chart title:

    Copy Code
    // Create chart.
    shape.getChart().getSeriesCollection().add(worksheet.getRange("A1:D6"), RowCol.Columns, true, true);
    // Display the chart title.
    // Set the chart title name.
    shape.getChart().getChartTitle().setText("Chart Title");
    // Set the direction of chart title to vertical.
    // OR

    Set Text Angle for Chart Title

    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.

    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
     //config chart title angle
     //save to an excel file"configcharttitleangle.xlsx");
    Note: The setOrientation method only applies if the value of setDirection method is Horizontal. However, the direction and orientation of the chart title can be exported or imported into a JSON file.