Share via


Chart.ApplyLayout(Int32, Object) 方法

定义

应用功能区上显示的布局。

public void ApplyLayout (int Layout, object ChartType);
abstract member ApplyLayout : int * obj -> unit
Public Sub ApplyLayout (Layout As Integer, Optional ChartType As Object)

参数

Layout
Int32

1 到 10 之间的一个整数,用于指定要应用于图表的布局的类型。

ChartType
Object

XlChartType 值之一。

示例

下面的代码示例应用可用于图表类型的第十个 Chart_1 布局。 此外,该示例使用 SetElement 方法应用进一步的布局更改:将图表标题的样式设置为居中且位于图表网格区域内,为水平轴添加标题,并为垂直轴添加旋转标题。 若要运行此代码示例,必须将名称 Chart_1 为 的聚集柱二维图表添加到默认工作表 Sheet1

private void DesignChart()
{
    Microsoft.Office.Tools.Excel.Chart myChart =
        Globals.Sheet1.Chart_1;

    myChart.ApplyLayout(10, myChart.ChartType);

    myChart.SetElement(
        Microsoft.Office.Core.MsoChartElementType.
        msoElementChartTitleCenteredOverlay);
    myChart.SetElement(
        Microsoft.Office.Core.MsoChartElementType.
        msoElementPrimaryCategoryAxisTitleHorizontal);
    myChart.SetElement(
        Microsoft.Office.Core.MsoChartElementType.
        msoElementPrimaryValueAxisTitleRotated);
}
Private Sub DesignChart()
    Dim myChart As Microsoft.Office.Tools.Excel.Chart = _
        Globals.Sheet1.Chart_1

    myChart.ApplyLayout(10)

    myChart.SetElement(Microsoft.Office.Core.MsoChartElementType. _
                       msoElementChartTitleCenteredOverlay)
    myChart.SetElement(Microsoft.Office.Core.MsoChartElementType. _
                       msoElementPrimaryCategoryAxisTitleHorizontal)
    myChart.SetElement(Microsoft.Office.Core.MsoChartElementType. _
                       msoElementPrimaryValueAxisTitleRotated)
End Sub

注解

参数的值Layout对应于功能区“设计”选项卡上的“图表布局”组中的可用选项。 选择图表时,“ 设计 ”选项卡可用。

每种类型的图表都有其自己的布局选项集。 例如,饼图的布局选项不同于柱形图的布局选项。 如果要从其他图表类型应用布局,可以使用 ChartType 参数指定参数将引用的 Layout 图表类型。 例如,如果有柱形图,并且想要应用折线图的布局,请将 Microsoft.Office.Interop.Excel.XlChartType.xlLine 值传递给 ChartType 参数。 布局仅添加可用于该特定图表类型的图表元素。

可选参数

有关可选参数的信息,请参阅 Office 解决方案中的可选参数

适用于