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

    In DsExcel .NET, you can use the properties of the IChart Interface to set up the chart title as per your choice. When working with chart title, you can perform the following tasks:

    Set Formula for Chart Title

    Refer to the following example code to set formula for chart title.

    C#
    Copy Code
    //Set formula for chart title.
    shape.Chart.HasTitle = true;
    shape.Chart.ChartTitle.Formula = "=Sheet1!$E$1";
    worksheet.Range["E1"].Value = "Sample Chart";

    Set Format for Chart Title and Font Style

    Refer to the following example code to set format for chart title and font style.

    C#
    Copy Code
    //Set chart title's format and font style.
    shape.Chart.HasTitle = true;
    //shape.Chart.ChartTitle.Text = "aaaaa";
    shape.Chart.ChartTitle.Font.Bold = true;
    shape.Chart.ChartTitle.Format.Fill.Color.RGB = Color.Red;
    shape.Chart.ChartTitle.Format.Line.Color.RGB = Color.Blue;

    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 Direction property 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:

    C#
    Copy Code
    // Create chart.
    shape.Chart.SeriesCollection.Add(worksheet.Range["A1:D6"], RowCol.Columns, true, true);
    
    // Display the chart title.
    shape.Chart.HasTitle = true;
    
    // Set the chart title name.
    shape.Chart.ChartTitle.Text = "Chart Title";
    
    // Set the direction of chart title to vertical.
    shape.Chart.ChartTitle.TextFrame.Direction = TextDirection.Vertical;
    
    // OR
    shape.Chart.ChartTitle.Direction = TextDirection.Vertical;

    Set Text Angle for Chart Title

    You can also set the text angle for chart title by using the Orientation property of IChartTitle interface.

    Refer to the following example code to set text angle for chart title.

    C#
    Copy Code
    //add chart title
    shape.Chart.HasTitle = true;
    shape.Chart.ChartTitle.Text = "MyChartTitle";
    
    //config chart title angle
    shape.Chart.ChartTitle.Orientation = 30;
    Note: The Orientation property only applies if the value of Direction property is Horizontal. However, the direction and orientation of the chart title can be exported or imported into a JSON file.