SetDefaultChart Method

Chart.SetDefaultChart Method

Specifies the name of the chart template that Microsoft Office Excel uses when it creates new charts.

Namespace:  Microsoft.Office.Tools.Excel
Assembly:  Microsoft.Office.Tools.Excel (in Microsoft.Office.Tools.Excel.dll)

void SetDefaultChart(
	Object Name


Type: System.Object
A string that indicates the name of the default chart template that will be used to create new charts. This name can identify a chart in the gallery for a user-defined template, or it can be one of the Microsoft.Office.Interop.Excel.XlChartType values that specifies a built-in chart template.

The following code example sets the default chart template to the line chart type. Next the example adds a new chart to the active worksheet and populates its source data from a specified range on the worksheet. To run this code example, your workbook must contain a worksheet named Sheet1 with a chart named Chart_1.

private void SetDefaultLineChartTemplate()
    // Set default chart template
    Microsoft.Office.Tools.Excel.Chart myChart =

    // Add a new chart and populate source data
    Microsoft.Office.Tools.Excel.Chart myNewChart = 
    Globals.Sheet1.Range["A1","A1"].Value2 = "Product";
    Globals.Sheet1.Range["B1","B1"].Value2 = "Units Sold";            
    for (int i = 1; i<4; i++)
        Globals.Sheet1.Range["A" + (i + 1).ToString(),missing].Value2 = "Product" + i.ToString();
        Globals.Sheet1.Range["B" + (i + 1).ToString(),missing].Value2 = i * 10;
    Excel.Range data = Globals.Sheet1.Range["A1", "B4"];
    myNewChart.SetSourceData(data, missing);

Community Additions

© 2016 Microsoft