[]
        
(Showing Draft Content)

Chart Title

Titles are the text fields that appear on a chart. It provides a descriptive heading for the chart data. You can add the title text to a chart by using the Text property of the IChartTitle interface. You can also adjust alignment, position, height, width, etc. using the various customization options available.


The following example code assigns a title "Sales Record" to the chart and includes it in the layout.

C#

spreadSheet1.Workbook.ActiveSheet.Cells[0, 1].Value = "Q1";
spreadSheet1.Workbook.ActiveSheet.Cells[0, 2].Value = "Q2";
spreadSheet1.Workbook.ActiveSheet.Cells[0, 3].Value = "Q3";
spreadSheet1.Workbook.ActiveSheet.Cells[1, 0].Value = "Mobile Phones";
spreadSheet1.Workbook.ActiveSheet.Cells[2, 0].Value = "Laptops";
spreadSheet1.Workbook.ActiveSheet.Cells[3, 0].Value = "Tablets";
for (var r = 1; r <= 3; r++)
{
    for (var c = 1; c <= 3; c++)
    {
        Random random = new Random();
        spreadSheet1.Workbook.ActiveSheet.Cells[r, c].Value = 0 + random.Next(0, 100);
    }
}
spreadSheet1.Workbook.ActiveSheet.Cells["A1:D4"].Select();
spreadSheet1.Workbook.ActiveSheet.Shapes.AddChart(GrapeCity.Spreadsheet.Charts.ChartType.ColumnClustered, 100, 150, 400, 300, true);
spreadSheet1.Workbook.ActiveSheet.ChartObjects[0].Chart.ChartTitle.Text = "Sales Report";
spreadSheet1.Workbook.ActiveSheet.ChartObjects[0].Chart.ChartTitle.Left = 10;
spreadSheet1.Workbook.ActiveSheet.ChartObjects[0].Chart.ChartTitle.IncludeInLayout = true;

VB

spreadSheet1.Workbook.ActiveSheet.Cells(0, 1).Value = "Q1"
spreadSheet1.Workbook.ActiveSheet.Cells(0, 2).Value = "Q2"
spreadSheet1.Workbook.ActiveSheet.Cells(0, 3).Value = "Q3"
spreadSheet1.Workbook.ActiveSheet.Cells(1, 0).Value = "Mobile Phones"
spreadSheet1.Workbook.ActiveSheet.Cells(2, 0).Value = "Laptops"
spreadSheet1.Workbook.ActiveSheet.Cells(3, 0).Value = "Tablets"
For r = 1 To 3
        For c = 1 To 3
            Dim random As Random = New Random()
            spreadSheet1.Workbook.ActiveSheet.Cells(r, c).Value = 0 + random.Next(0, 100)
        Next
Next
spreadSheet1.Workbook.ActiveSheet.Cells("A1:D4").[Select](gcdocsite__documentlink?toc-item-id=e422cb30-c077-432b-a677-f3e330939380)
spreadSheet1.Workbook.ActiveSheet.Shapes.AddChart(GrapeCity.Spreadsheet.Charts.ChartType.ColumnClustered, 100, 150, 400, 300, True)
spreadSheet1.Workbook.ActiveSheet.ChartObjects(0).Chart.ChartTitle.Text = "Sales Report"
spreadSheet1.Workbook.ActiveSheet.ChartObjects(0).Chart.ChartTitle.Left = 10
spreadSheet1.Workbook.ActiveSheet.ChartObjects(0).Chart.ChartTitle.IncludeInLayout = True

By default, the title is displayed on a chart. If not, use the ShowTitle() method on the chart object which ensures that the title of the chart is visible to the users.

Using the Formula property of the IChartTitle interface, you can also bind data from the worksheet to chart title. It links the title to a specific cell in the worksheet and when you make any changes to the cell, it will automatically reflect in the chart title. Note that users can use the Formula property to bind data to series values and categories as well.

Refer to the following example code to set the chart title to the value of cell A1 in Sheet1.

C#

spreadSheet1.Workbook.ActiveSheet.ChartObjects[0].Chart.ShowTitle();
spreadSheet1.Workbook.ActiveSheet.ChartObjects[0].Chart.ChartTitle.Formula = "Sheet1!A1";

VB

spreadSheet1.Workbook.ActiveSheet.ChartObjects(0).Chart.ShowTitle()
spreadSheet1.Workbook.ActiveSheet.ChartObjects(0).Chart.ChartTitle.Formula = "Sheet1!A1"