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:
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"; |
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; |
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; |
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; |