共用方式為


Chart.ChartStyle 屬性

取得或設定圖表的樣式。

命名空間:  Microsoft.Office.Tools.Excel
組件:  Microsoft.Office.Tools.Excel (在 Microsoft.Office.Tools.Excel.dll 中)

語法

'宣告
Property ChartStyle As Object
    Get
    Set
Object ChartStyle { get; set; }

屬性值

型別:System.Object
1 到 48 的整數,表示圖表的樣式。

備註

ChartStyle 屬性的值會對應至功能區 [設計] 索引標籤上之 [圖表樣式] 群組中的可用選項。 當您選取圖示時,[設計] 索引標籤就可以使用。

範例

下列程式碼範例會將立體群組直條圖加入至 Sheet1,並將其樣式設定為樣式 4。 此範例接著會建立任意資料的範圍,並將它設定為圖表來源資料。 接下來,程式碼會指定圖表牆和底板的色彩。

Private Sub SetChartBackWalls()
    ' Add a new chart and populate source data
    Dim myNewChart As Microsoft.Office.Tools.Excel.Chart = _
    Globals.Sheet1.Controls.AddChart( _
        Globals.Sheet1.Range("D5", "J16"), "myNewChart")
    myNewChart.ChartType = Excel.XlChartType.xl3DColumnClustered
    ' Set chart style
    myNewChart.ChartStyle = 4

    Globals.Sheet1.Range("A1").Value2 = "Product"
    Globals.Sheet1.Range("B1").Value2 = "Units Sold"
    Dim i As Integer
    For i = 1 To 3
        Globals.Sheet1.Range("A" + (i + 1).ToString()).Value2 = _
            "Product" + i.ToString()
        Globals.Sheet1.Range("B" + (i + 1).ToString()).Value2 = i * 10
    Next
    Dim data As Excel.Range = Globals.Sheet1.Range("A1", "B4")
    myNewChart.SetSourceData(data)

    ' Set foreground color for 3D chart walls and floor
    myNewChart.BackWall.Format.Fill.ForeColor.RGB = _
        System.Drawing.Color.LightGray.ToArgb()
    myNewChart.SideWall.Format.Fill.ForeColor.RGB = _
        System.Drawing.Color.LightGray.ToArgb()
    myNewChart.Floor.Format.Fill.ForeColor.RGB = _
        System.Drawing.Color.Gray.ToArgb()
End Sub
private void SetChartBackWalls()
{
    // Add a new chart and populate source data
    Microsoft.Office.Tools.Excel.Chart myNewChart =
    Globals.Sheet1.Controls.AddChart(
        Globals.Sheet1.Range["D5", "J16"], "myNewChart");
    myNewChart.ChartType = Excel.XlChartType.xl3DColumnClustered;
    // Set chart style
    myNewChart.ChartStyle = 4;

    Globals.Sheet1.Range["A1",missing].Value2 = "Product";
    Globals.Sheet1.Range["B1",missing].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);

    // Set foreground color for 3D chart walls and floor
    myNewChart.BackWall.Format.Fill.ForeColor.RGB =
        System.Drawing.Color.LightGray.ToArgb();
    myNewChart.SideWall.Format.Fill.ForeColor.RGB =
        System.Drawing.Color.LightGray.ToArgb();
    myNewChart.Floor.Format.Fill.ForeColor.RGB = 
        System.Drawing.Color.Gray.ToArgb();        
}

.NET Framework 安全性

請參閱

參考

Chart 介面

Microsoft.Office.Tools.Excel 命名空間