Excel.Chart class

表示工作簿中的 chart 对象。Represents a chart object in a workbook.

[API 集: ExcelApi 1.1][ API set: ExcelApi 1.1 ]

Extends

属性

axes

表示图表坐标轴。Represents chart axes. 只读。Read-only.

[API 集: ExcelApi 1.1][ API set: ExcelApi 1.1 ]

categoryLabelLevel

返回或设置 ChartCategoryLabelLevel 枚举常量,该常量代表分类标签源自位置的级别。Returns or sets a ChartCategoryLabelLevel enumeration constant referring to the level of where the category labels are being sourced from. 读/写。Read/Write.

[API 集: ExcelApi 1.8][ API set: ExcelApi 1.8 ]

chartType

表示图表的类型。Represents the type of the chart. 有关详细信息, 请参阅 ChartType。See Excel.ChartType for details.

[API 集: ExcelApi 1.7][ API set: ExcelApi 1.7 ]

context

与该对象关联的请求上下文。The request context associated with the object. 这会将加载项的进程连接到 Office 主机应用程序的进程。This connects the add-in's process to the Office host application's process.

dataLabels

表示图表上的数据标签。Represents the datalabels on the chart. 只读。Read-only.

[API 集: ExcelApi 1.1][ API set: ExcelApi 1.1 ]

displayBlanksAs

返回或设置图表上的空白单元格的绘制方式。Returns or sets the way that blank cells are plotted on a chart. 读/写。Read/Write.

[API 集: ExcelApi 1.8][ API set: ExcelApi 1.8 ]

format

封装图表区域的格式属性。Encapsulates the format properties for the chart area. 只读。Read-only.

[API 集: ExcelApi 1.1][ API set: ExcelApi 1.1 ]

height

表示 chart 对象的高度,以磅值表示。Represents the height, in points, of the chart object.

[API 集: ExcelApi 1.1][ API set: ExcelApi 1.1 ]

id

图表的唯一 ID。The unique id of chart. 只读。Read-only.

[API 集: ExcelApi 1.7][ API set: ExcelApi 1.7 ]

left

从图表左侧到工作表原点的距离,以磅值表示。The distance, in points, from the left side of the chart to the worksheet origin.

[API 集: ExcelApi 1.1][ API set: ExcelApi 1.1 ]

legend

表示图表的图例。Represents the legend for the chart. 只读。Read-only.

[API 集: ExcelApi 1.1][ API set: ExcelApi 1.1 ]

name

表示 chart 对象的名称。Represents the name of a chart object.

[API 集: ExcelApi 1.1][ API set: ExcelApi 1.1 ]

pivotOptions

封装数据透视图表的选项。Encapsulates the options for a pivot chart. 只读。Read-only.

[API 集: ExcelApi 1.9][ API set: ExcelApi 1.9 ]

plotArea

表示图表的绘制区域。Represents the plotArea for the chart.

[API 集: ExcelApi 1.8][ API set: ExcelApi 1.8 ]

plotBy

返回或设置图表上的列或行用作数据系列的方式。Returns or sets the way columns or rows are used as data series on the chart. 读/写。Read/Write.

[API 集: ExcelApi 1.8][ API set: ExcelApi 1.8 ]

plotVisibleOnly

如果仅绘制可见单元格,则为 True。True if only visible cells are plotted. 如果绘制可见单元格和隐藏单元格,则为 False。False if both visible and hidden cells are plotted. 读/写。Read/Write.

[API 集: ExcelApi 1.8][ API set: ExcelApi 1.8 ]

series

表示单个系列或图表中的系列集合。Represents either a single series or collection of series in the chart. 只读。Read-only.

[API 集: ExcelApi 1.1][ API set: ExcelApi 1.1 ]

seriesNameLevel

返回或设置 ChartSeriesNameLevel 枚举常量,该常量代表系列名称源自位置的级别。Returns or sets a ChartSeriesNameLevel enumeration constant referring to the level of where the series names are being sourced from. 读/写。Read/Write.

[API 集: ExcelApi 1.8][ API set: ExcelApi 1.8 ]

showAllFieldButtons

表示是否在数据透视图上显示所有字段按钮。Represents whether to display all field buttons on a PivotChart.

[API 集: ExcelApi 1.7][ API set: ExcelApi 1.7 ]

showDataLabelsOverMaximum

表示当值大于数值轴上的最大值时是否显示数据标签。Represents whether to show the data labels when the value is greater than the maximum value on the value axis. 如果数值轴变为小于数据点的大小, 则可以使用此属性来设置是否显示数据标签。If value axis became smaller than the size of data points, you can use this property to set whether to show the data labels. 该属性只适用于二维图表。This property applies to 2-D charts only.

[API 集: ExcelApi 1.8][ API set: ExcelApi 1.8 ]

style

返回或设置图表的图表样式。Returns or sets the chart style for the chart. 读/写。Read/Write.

[API 集: ExcelApi 1.8][ API set: ExcelApi 1.8 ]

title

表示指定图表的标题,包括标题的文本、可见性、位置和格式。Represents the title of the specified chart, including the text, visibility, position, and formatting of the title. 只读。Read-only.

[API 集: ExcelApi 1.1][ API set: ExcelApi 1.1 ]

top

表示从对象左边界至第 1 行顶部(在工作表上)或图表区域顶部(在图表上)的距离,以磅值表示。Represents the distance, in points, from the top edge of the object to the top of row 1 (on a worksheet) or the top of the chart area (on a chart).

[API 集: ExcelApi 1.1][ API set: ExcelApi 1.1 ]

width

表示 chart 对象的宽度,以磅值表示。Represents the width, in points, of the chart object.

[API 集: ExcelApi 1.1][ API set: ExcelApi 1.1 ]

worksheet

包含当前 chart 的 worksheet 对象。The worksheet containing the current chart. 只读。Read-only.

[API 集: ExcelApi 1.2][ API set: ExcelApi 1.2 ]

方法

activate()

在 Excel UI 中激活图表。Activates the chart in the Excel UI.

[API 集: ExcelApi 1.9][ API set: ExcelApi 1.9 ]

delete()

删除 chart 对象。Deletes the chart object.

[API 集: ExcelApi 1.1][ API set: ExcelApi 1.1 ]

getImage(width, height, fittingMode)

通过缩放图表以适应指定的尺寸,将图表呈现为 base64 编码的图像。Renders the chart as a base64-encoded image by scaling the chart to fit the specified dimensions. 在调整大小的过程中保留纵横比。The aspect ratio is preserved as part of the resizing.

[API 集: ExcelApi 1.2][ API set: ExcelApi 1.2 ]

getImage(width, height, fittingModeString)

通过缩放图表以适应指定的尺寸,将图表呈现为 base64 编码的图像。Renders the chart as a base64-encoded image by scaling the chart to fit the specified dimensions. 在调整大小的过程中保留纵横比。The aspect ratio is preserved as part of the resizing.

[API 集: ExcelApi 1.2][ API set: ExcelApi 1.2 ]

load(option)

将命令加入队列以加载对象的指定属性。Queues up a command to load the specified properties of the object. 在读取属性之前,你必须调用“context.sync()”。You must call "context.sync()" before reading the properties.

load(propertyNames)

将命令加入队列以加载对象的指定属性。Queues up a command to load the specified properties of the object. 在读取属性context.sync()之前, 必须先调用。You must call context.sync() before reading the properties.

load(propertyNamesAndPaths)

将命令加入队列以加载对象的指定属性。Queues up a command to load the specified properties of the object. 在读取属性context.sync()之前, 必须先调用。You must call context.sync() before reading the properties.

set(properties, options)

同时设置一个对象的多个属性。Sets multiple properties of an object at the same time. 您可以传递具有相应属性的纯对象或相同类型的其他 API 对象。You can pass either a plain object with the appropriate properties, or another API object of the same type.

set(properties)

基于现有加载的对象同时设置该对象的多个属性。Sets multiple properties on the object at the same time, based on an existing loaded object.

setData(sourceData, seriesBy)

重置图表的源数据。Resets the source data for the chart.

[API 集: ExcelApi 1.1][ API set: ExcelApi 1.1 ]

setData(sourceData, seriesByString)

重置图表的源数据。Resets the source data for the chart.

[API 集: ExcelApi 1.1][ API set: ExcelApi 1.1 ]

setPosition(startCell, endCell)

相对于工作表上的单元格放置图表。Positions the chart relative to cells on the worksheet.

[API 集: ExcelApi 1.1][ API set: ExcelApi 1.1 ]

toJSON()

重写 JavaScript toJSON()方法, 以便在将 API 对象传递到时提供更有用的输出JSON.stringify()Overrides the JavaScript toJSON() method in order to provide more useful output when an API object is passed to JSON.stringify(). (JSON.stringify反过来, 也会调用传递toJSON给它的对象的方法。尽管原始的 Excel 图表对象是 API 对象, 但toJSON方法返回一个简单的 JavaScript 对象 (类型为Excel.Interfaces.ChartData, in turn, calls the toJSON method of the object that is passed to it.) Whereas the original Excel.Chart object is an API object, the toJSON method returns a plain JavaScript object (typed as Excel.Interfaces.ChartData), 其中包含原始对象中所有已加载的子属性的浅表副本。) that contains shallow copies of any loaded child properties from the original object.

事件

onActivated

图表激活时发生。Occurs when the chart is activated.

[API 集: ExcelApi 1.8][ API set: ExcelApi 1.8 ]

onDeactivated

图表停用时发生。Occurs when the chart is deactivated.

[API 集: ExcelApi 1.8][ API set: ExcelApi 1.8 ]

属性详细信息

axes

表示图表坐标轴。Represents chart axes. 只读。Read-only.

[API 集: ExcelApi 1.1][ API set: ExcelApi 1.1 ]

readonly axes: Excel.ChartAxes;

属性值

categoryLabelLevel

返回或设置 ChartCategoryLabelLevel 枚举常量,该常量代表分类标签源自位置的级别。Returns or sets a ChartCategoryLabelLevel enumeration constant referring to the level of where the category labels are being sourced from. 读/写。Read/Write.

[API 集: ExcelApi 1.8][ API set: ExcelApi 1.8 ]

categoryLabelLevel: number;

属性值

number

chartType

表示图表的类型。Represents the type of the chart. 有关详细信息, 请参阅 ChartType。See Excel.ChartType for details.

[API 集: ExcelApi 1.7][ API set: ExcelApi 1.7 ]

chartType: Excel.ChartType | "Invalid" | "ColumnClustered" | "ColumnStacked" | "ColumnStacked100" | "3DColumnClustered" | "3DColumnStacked" | "3DColumnStacked100" | "BarClustered" | "BarStacked" | "BarStacked100" | "3DBarClustered" | "3DBarStacked" | "3DBarStacked100" | "LineStacked" | "LineStacked100" | "LineMarkers" | "LineMarkersStacked" | "LineMarkersStacked100" | "PieOfPie" | "PieExploded" | "3DPieExploded" | "BarOfPie" | "XYScatterSmooth" | "XYScatterSmoothNoMarkers" | "XYScatterLines" | "XYScatterLinesNoMarkers" | "AreaStacked" | "AreaStacked100" | "3DAreaStacked" | "3DAreaStacked100" | "DoughnutExploded" | "RadarMarkers" | "RadarFilled" | "Surface" | "SurfaceWireframe" | "SurfaceTopView" | "SurfaceTopViewWireframe" | "Bubble" | "Bubble3DEffect" | "StockHLC" | "StockOHLC" | "StockVHLC" | "StockVOHLC" | "CylinderColClustered" | "CylinderColStacked" | "CylinderColStacked100" | "CylinderBarClustered" | "CylinderBarStacked" | "CylinderBarStacked100" | "CylinderCol" | "ConeColClustered" | "ConeColStacked" | "ConeColStacked100" | "ConeBarClustered" | "ConeBarStacked" | "ConeBarStacked100" | "ConeCol" | "PyramidColClustered" | "PyramidColStacked" | "PyramidColStacked100" | "PyramidBarClustered" | "PyramidBarStacked" | "PyramidBarStacked100" | "PyramidCol" | "3DColumn" | "Line" | "3DLine" | "3DPie" | "Pie" | "XYScatter" | "3DArea" | "Area" | "Doughnut" | "Radar" | "Histogram" | "Boxwhisker" | "Pareto" | "RegionMap" | "Treemap" | "Waterfall" | "Sunburst" | "Funnel";

属性值

Excel.ChartType | "Invalid" | "ColumnClustered" | "ColumnStacked" | "ColumnStacked100" | "3DColumnClustered" | "3DColumnStacked" | "3DColumnStacked100" | "BarClustered" | "BarStacked" | "BarStacked100" | "3DBarClustered" | "3DBarStacked" | "3DBarStacked100" | "LineStacked" | "LineStacked100" | "LineMarkers" | "LineMarkersStacked" | "LineMarkersStacked100" | "PieOfPie" | "PieExploded" | "3DPieExploded" | "BarOfPie" | "XYScatterSmooth" | "XYScatterSmoothNoMarkers" | "XYScatterLines" | "XYScatterLinesNoMarkers" | "AreaStacked" | "AreaStacked100" | "3DAreaStacked" | "3DAreaStacked100" | "DoughnutExploded" | "RadarMarkers" | "RadarFilled" | "Surface" | "SurfaceWireframe" | "SurfaceTopView" | "SurfaceTopViewWireframe" | "Bubble" | "Bubble3DEffect" | "StockHLC" | "StockOHLC" | "StockVHLC" | "StockVOHLC" | "CylinderColClustered" | "CylinderColStacked" | "CylinderColStacked100" | "CylinderBarClustered" | "CylinderBarStacked" | "CylinderBarStacked100" | "CylinderCol" | "ConeColClustered" | "ConeColStacked" | "ConeColStacked100" | "ConeBarClustered" | "ConeBarStacked" | "ConeBarStacked100" | "ConeCol" | "PyramidColClustered" | "PyramidColStacked" | "PyramidColStacked100" | "PyramidBarClustered" | "PyramidBarStacked" | "PyramidBarStacked100" | "PyramidCol" | "3DColumn" | "Line" | "3DLine" | "3DPie" | "Pie" | "XYScatter" | "3DArea" | "Area" | "Doughnut" | "Radar" | "Histogram" | "Boxwhisker" | "Pareto" | "RegionMap" | "Treemap" | "Waterfall" | "Sunburst" | "Funnel"

context

与该对象关联的请求上下文。The request context associated with the object. 这会将加载项的进程连接到 Office 主机应用程序的进程。This connects the add-in's process to the Office host application's process.

context: RequestContext;

属性值

RequestContext

dataLabels

表示图表上的数据标签。Represents the datalabels on the chart. 只读。Read-only.

[API 集: ExcelApi 1.1][ API set: ExcelApi 1.1 ]

readonly dataLabels: Excel.ChartDataLabels;

属性值

displayBlanksAs

返回或设置图表上的空白单元格的绘制方式。Returns or sets the way that blank cells are plotted on a chart. 读/写。Read/Write.

[API 集: ExcelApi 1.8][ API set: ExcelApi 1.8 ]

displayBlanksAs: Excel.ChartDisplayBlanksAs | "NotPlotted" | "Zero" | "Interplotted";

属性值

Excel.ChartDisplayBlanksAs | "NotPlotted" | "Zero" | "Interplotted"

format

封装图表区域的格式属性。Encapsulates the format properties for the chart area. 只读。Read-only.

[API 集: ExcelApi 1.1][ API set: ExcelApi 1.1 ]

readonly format: Excel.ChartAreaFormat;

属性值

height

表示 chart 对象的高度,以磅值表示。Represents the height, in points, of the chart object.

[API 集: ExcelApi 1.1][ API set: ExcelApi 1.1 ]

height: number;

属性值

number

id

图表的唯一 ID。The unique id of chart. 只读。Read-only.

[API 集: ExcelApi 1.7][ API set: ExcelApi 1.7 ]

readonly id: string;

属性值

string

left

从图表左侧到工作表原点的距离,以磅值表示。The distance, in points, from the left side of the chart to the worksheet origin.

[API 集: ExcelApi 1.1][ API set: ExcelApi 1.1 ]

left: number;

属性值

number

legend

表示图表的图例。Represents the legend for the chart. 只读。Read-only.

[API 集: ExcelApi 1.1][ API set: ExcelApi 1.1 ]

readonly legend: Excel.ChartLegend;

属性值

name

表示 chart 对象的名称。Represents the name of a chart object.

[API 集: ExcelApi 1.1][ API set: ExcelApi 1.1 ]

name: string;

属性值

string

示例Examples

// Rename the chart to new name, resize the chart to 200 points in both height and weight. 
// Move Chart1 to 100 points to the top and left. 
Excel.run(function (ctx) { 
    var chart = ctx.workbook.worksheets.getItem("Sheet1").charts.getItem("Chart1");    
    chart.name = "New Name";
    chart.top = 100;
    chart.left = 100;
    chart.height = 200;
    chart.width = 200;
    return ctx.sync(); 
}).catch(function(error) {
    console.log("Error: " + error);
    if (error instanceof OfficeExtension.Error) {
        console.log("Debug info: " + JSON.stringify(error.debugInfo));
    }
});

pivotOptions

封装数据透视图表的选项。Encapsulates the options for a pivot chart. 只读。Read-only.

[API 集: ExcelApi 1.9][ API set: ExcelApi 1.9 ]

readonly pivotOptions: Excel.ChartPivotOptions;

属性值

plotArea

表示图表的绘制区域。Represents the plotArea for the chart.

[API 集: ExcelApi 1.8][ API set: ExcelApi 1.8 ]

readonly plotArea: Excel.ChartPlotArea;

属性值

plotBy

返回或设置图表上的列或行用作数据系列的方式。Returns or sets the way columns or rows are used as data series on the chart. 读/写。Read/Write.

[API 集: ExcelApi 1.8][ API set: ExcelApi 1.8 ]

plotBy: Excel.ChartPlotBy | "Rows" | "Columns";

属性值

Excel.ChartPlotBy | "Rows" | "Columns"

plotVisibleOnly

如果仅绘制可见单元格,则为 True。True if only visible cells are plotted. 如果绘制可见单元格和隐藏单元格,则为 False。False if both visible and hidden cells are plotted. 读/写。Read/Write.

[API 集: ExcelApi 1.8][ API set: ExcelApi 1.8 ]

plotVisibleOnly: boolean;

属性值

boolean

series

表示单个系列或图表中的系列集合。Represents either a single series or collection of series in the chart. 只读。Read-only.

[API 集: ExcelApi 1.1][ API set: ExcelApi 1.1 ]

readonly series: Excel.ChartSeriesCollection;

属性值

seriesNameLevel

返回或设置 ChartSeriesNameLevel 枚举常量,该常量代表系列名称源自位置的级别。Returns or sets a ChartSeriesNameLevel enumeration constant referring to the level of where the series names are being sourced from. 读/写。Read/Write.

[API 集: ExcelApi 1.8][ API set: ExcelApi 1.8 ]

seriesNameLevel: number;

属性值

number

showAllFieldButtons

表示是否在数据透视图上显示所有字段按钮。Represents whether to display all field buttons on a PivotChart.

[API 集: ExcelApi 1.7][ API set: ExcelApi 1.7 ]

showAllFieldButtons: boolean;

属性值

boolean

showDataLabelsOverMaximum

表示当值大于数值轴上的最大值时是否显示数据标签。Represents whether to show the data labels when the value is greater than the maximum value on the value axis. 如果数值轴变为小于数据点的大小, 则可以使用此属性来设置是否显示数据标签。If value axis became smaller than the size of data points, you can use this property to set whether to show the data labels. 该属性只适用于二维图表。This property applies to 2-D charts only.

[API 集: ExcelApi 1.8][ API set: ExcelApi 1.8 ]

showDataLabelsOverMaximum: boolean;

属性值

boolean

style

返回或设置图表的图表样式。Returns or sets the chart style for the chart. 读/写。Read/Write.

[API 集: ExcelApi 1.8][ API set: ExcelApi 1.8 ]

style: number;

属性值

number

title

表示指定图表的标题,包括标题的文本、可见性、位置和格式。Represents the title of the specified chart, including the text, visibility, position, and formatting of the title. 只读。Read-only.

[API 集: ExcelApi 1.1][ API set: ExcelApi 1.1 ]

readonly title: Excel.ChartTitle;

属性值

top

表示从对象左边界至第 1 行顶部(在工作表上)或图表区域顶部(在图表上)的距离,以磅值表示。Represents the distance, in points, from the top edge of the object to the top of row 1 (on a worksheet) or the top of the chart area (on a chart).

[API 集: ExcelApi 1.1][ API set: ExcelApi 1.1 ]

top: number;

属性值

number

width

表示 chart 对象的宽度,以磅值表示。Represents the width, in points, of the chart object.

[API 集: ExcelApi 1.1][ API set: ExcelApi 1.1 ]

width: number;

属性值

number

worksheet

包含当前 chart 的 worksheet 对象。The worksheet containing the current chart. 只读。Read-only.

[API 集: ExcelApi 1.2][ API set: ExcelApi 1.2 ]

readonly worksheet: Excel.Worksheet;

属性值

方法详细信息

activate()

在 Excel UI 中激活图表。Activates the chart in the Excel UI.

[API 集: ExcelApi 1.9][ API set: ExcelApi 1.9 ]

activate(): void;

返回

void

delete()

删除 chart 对象。Deletes the chart object.

[API 集: ExcelApi 1.1][ API set: ExcelApi 1.1 ]

delete(): void;

返回

void

示例Examples

Excel.run(function (ctx) { 
    var chart = ctx.workbook.worksheets.getItem("Sheet1").charts.getItem("Chart1");    
    chart.delete();
    return ctx.sync(); 
}).catch(function(error) {
    console.log("Error: " + error);
    if (error instanceof OfficeExtension.Error) {
        console.log("Debug info: " + JSON.stringify(error.debugInfo));
    }
});

getImage(width, height, fittingMode)

通过缩放图表以适应指定的尺寸,将图表呈现为 base64 编码的图像。Renders the chart as a base64-encoded image by scaling the chart to fit the specified dimensions. 在调整大小的过程中保留纵横比。The aspect ratio is preserved as part of the resizing.

[API 集: ExcelApi 1.2][ API set: ExcelApi 1.2 ]

getImage(width?: number, height?: number, fittingMode?: Excel.ImageFittingMode): OfficeExtension.ClientResult<string>;

参数

width
number

(可选)生成的图像所需的宽度。(Optional) The desired width of the resulting image.

height
number

(可选)生成的图像所需的高度。(Optional) The desired height of the resulting image.

fittingMode
Excel.ImageFittingMode

Optional用于将图表缩放到指定尺寸 (如果同时设置了高度和宽度) 的方法。(Optional) The method used to scale the chart to the specified to the specified dimensions (if both height and width are set).

返回

OfficeExtension.ClientResult<string>

示例Examples

Excel.run(function (ctx) { 
    var chart = ctx.workbook.worksheets.getItem("Sheet1").charts.getItem("Chart1");    
    var image = chart.getImage();
    return ctx.sync(); 
}).catch(function(error) {
    console.log("Error: " + error);
    if (error instanceof OfficeExtension.Error) {
        console.log("Debug info: " + JSON.stringify(error.debugInfo));
    }
});

getImage(width, height, fittingModeString)

通过缩放图表以适应指定的尺寸,将图表呈现为 base64 编码的图像。Renders the chart as a base64-encoded image by scaling the chart to fit the specified dimensions. 在调整大小的过程中保留纵横比。The aspect ratio is preserved as part of the resizing.

[API 集: ExcelApi 1.2][ API set: ExcelApi 1.2 ]

getImage(width?: number, height?: number, fittingModeString?: "Fit" | "FitAndCenter" | "Fill"): OfficeExtension.ClientResult<string>;

参数

width
number

(可选)生成的图像所需的宽度。(Optional) The desired width of the resulting image.

height
number

(可选)生成的图像所需的高度。(Optional) The desired height of the resulting image.

fittingModeString
"Fit" | "FitAndCenter" | "Fill"

Optional用于将图表缩放到指定尺寸 (如果同时设置了高度和宽度) 的方法。(Optional) The method used to scale the chart to the specified to the specified dimensions (if both height and width are set).

返回

OfficeExtension.ClientResult<string>

load(option)

将命令加入队列以加载对象的指定属性。Queues up a command to load the specified properties of the object. 在读取属性之前,你必须调用“context.sync()”。You must call "context.sync()" before reading the properties.

load(option?: Excel.Interfaces.ChartLoadOptions): Excel.Chart;

参数

返回

注解

除了此签名之外, 此方法还具有以下签名:In addition to this signature, this method has the following signatures:

load(option?: string | string[]): Excel.Chart-Where 选项是一个逗号分隔的字符串或一个字符串数组, 用于指定要加载的属性。load(option?: string | string[]): Excel.Chart - Where option is a comma-delimited string or an array of strings that specify the properties to load.

load(option?: { select?: string; expand?: string; }): Excel.Chart-Where 选项。选择是一个用逗号分隔的字符串, 用于指定要加载的属性和选项。 expand 是一个用逗号分隔的字符串, 用于指定要加载的导航属性。load(option?: { select?: string; expand?: string; }): Excel.Chart - Where option.select is a comma-delimited string that specifies the properties to load, and options.expand is a comma-delimited string that specifies the navigation properties to load.

load(option?: { select?: string; expand?: string; top?: number; skip?: number }): Excel.Chart-仅适用于集合类型。load(option?: { select?: string; expand?: string; top?: number; skip?: number }): Excel.Chart - Only available on collection types. 它类似于前面的签名。It is similar to the preceding signature. Top 指定结果中可包含的集合项的最大数量。Option.top specifies the maximum number of collection items that can be included in the result. 选项。 skip 指定要跳过且不包含在结果中的项目数。Option.skip specifies the number of items that are to be skipped and not included in the result. 如果指定了 top 选项, 则在跳过指定数目的项目后将启动结果集。If option.top is specified, the result set will start after skipping the specified number of items.

load(propertyNames)

将命令加入队列以加载对象的指定属性。Queues up a command to load the specified properties of the object. 在读取属性context.sync()之前, 必须先调用。You must call context.sync() before reading the properties.

load(propertyNames?: string | string[]): Excel.Chart;

参数

propertyNames
string | string[]

一个以逗号分隔的字符串或字符串数组, 用于指定要加载的属性。A comma-delimited string or an array of strings that specify the properties to load.

返回

示例Examples

// Get a chart named "Chart1"
Excel.run(function (ctx) { 
    var chart = ctx.workbook.worksheets.getItem("Sheet1").charts.getItem("Chart1");    
    chart.load('name');
    return ctx.sync().then(function() {
            console.log(chart.name);
    });
}).catch(function(error) {
    console.log("Error: " + error);
    if (error instanceof OfficeExtension.Error) {
        console.log("Debug info: " + JSON.stringify(error.debugInfo));
    }
});

load(propertyNamesAndPaths)

将命令加入队列以加载对象的指定属性。Queues up a command to load the specified properties of the object. 在读取属性context.sync()之前, 必须先调用。You must call context.sync() before reading the properties.

load(propertyNamesAndPaths?: { select?: string; expand?: string; }): Excel.Chart;

参数

propertyNamesAndPaths
{ select?: string; expand?: string; }

其中, propertyNamesAndPaths 是用逗号分隔的字符串, 用于指定要加载的属性和 propertyNamesAndPaths。扩展是一个用逗号分隔的字符串, 用于指定要加载的导航属性。Where propertyNamesAndPaths.select is a comma-delimited string that specifies the properties to load, and propertyNamesAndPaths.expand is a comma-delimited string that specifies the navigation properties to load.

返回

set(properties, options)

同时设置一个对象的多个属性。Sets multiple properties of an object at the same time. 您可以传递具有相应属性的纯对象或相同类型的其他 API 对象。You can pass either a plain object with the appropriate properties, or another API object of the same type.

set(properties: Interfaces.ChartUpdateData, options?: OfficeExtension.UpdateOptions): void;

参数

properties
Interfaces.ChartUpdateData

一个 JavaScript 对象, 其属性的结构 isomorphically 为在其上调用方法的对象的属性。A JavaScript object with properties that are structured isomorphically to the properties of the object on which the method is called.

options
OfficeExtension.UpdateOptions

提供一个选项, 以在 properties 对象尝试设置任何只读属性时禁止显示错误。Provides an option to suppress errors if the properties object tries to set any read-only properties.

返回

void

注解

此方法具有以下附加签名:This method has the following additional signature:

set(properties: Excel.Chart): void

set(properties)

基于现有加载的对象同时设置该对象的多个属性。Sets multiple properties on the object at the same time, based on an existing loaded object.

set(properties: Excel.Chart): void;

参数

properties
Excel.Chart

返回

void

setData(sourceData, seriesBy)

重置图表的源数据。Resets the source data for the chart.

[API 集: ExcelApi 1.1][ API set: ExcelApi 1.1 ]

setData(sourceData: Range, seriesBy?: Excel.ChartSeriesBy): void;

参数

sourceData
Range

与源数据对应的 range 对象。The range object corresponding to the source data.

seriesBy
Excel.ChartSeriesBy

指定列或行在图表上用作数据系列的方式。Specifies the way columns or rows are used as data series on the chart. 可以是下列值之一: 自动 (默认)、行和列。Can be one of the following: Auto (default), Rows, and Columns. 有关详细信息, 请参阅 ChartSeriesBy。See Excel.ChartSeriesBy for details.

返回

void

setData(sourceData, seriesByString)

重置图表的源数据。Resets the source data for the chart.

[API 集: ExcelApi 1.1][ API set: ExcelApi 1.1 ]

setData(sourceData: Range, seriesByString?: "Auto" | "Columns" | "Rows"): void;

参数

sourceData
Range

与源数据对应的 range 对象。The range object corresponding to the source data.

seriesByString
"Auto" | "Columns" | "Rows"

指定列或行在图表上用作数据系列的方式。Specifies the way columns or rows are used as data series on the chart. 可以是下列值之一: 自动 (默认)、行和列。Can be one of the following: Auto (default), Rows, and Columns. 有关详细信息, 请参阅 ChartSeriesBy。See Excel.ChartSeriesBy for details.

返回

void

示例Examples

// Set the sourceData to be "A1:B4" and seriesBy to be "Columns"
Excel.run(function (ctx) { 
    var chart = ctx.workbook.worksheets.getItem("Sheet1").charts.getItem("Chart1");    
    var sourceData = "A1:B4";
    chart.setData(sourceData, "Columns");
    return ctx.sync(); 
}).catch(function(error) {
    console.log("Error: " + error);
    if (error instanceof OfficeExtension.Error) {
        console.log("Debug info: " + JSON.stringify(error.debugInfo));
    }
});

setPosition(startCell, endCell)

相对于工作表上的单元格放置图表。Positions the chart relative to cells on the worksheet.

[API 集: ExcelApi 1.1][ API set: ExcelApi 1.1 ]

setPosition(startCell: Range | string, endCell?: Range | string): void;

参数

startCell
Range | string

起始单元格。这是图表将移动到的位置。起始单元格为左上角或右上角的单元格,具体取决于用户的从右到左显示设置。The start cell. This is where the chart will be moved to. The start cell is the top-left or top-right cell, depending on the user's right-to-left display settings.

endCell
Range | string

(可选)结束单元格。(Optional) The end cell. 如果指定,图表的宽度和高度将设置为完全覆盖此单元格/区域。If specified, the chart's width and height will be set to fully cover up this cell/range.

返回

void

示例Examples

Excel.run(function (ctx) { 
    var sheetName = "Charts";
    var rangeSelection = "A1:B4";
    var range = ctx.workbook.worksheets.getItem(sheetName).getRange(rangeSelection);
    var sourceData = sheetName + "!" + "A1:B4";
    var chart = ctx.workbook.worksheets.getItem(sheetName).charts.add("pie", range, "auto");
    chart.width = 500;
    chart.height = 300;
    chart.setPosition("C2", null);
    return ctx.sync(); 
}).catch(function(error) {
    console.log("Error: " + error);
    if (error instanceof OfficeExtension.Error) {
        console.log("Debug info: " + JSON.stringify(error.debugInfo));
    }
});

toJSON()

重写 JavaScript toJSON()方法, 以便在将 API 对象传递到时提供更有用的输出JSON.stringify()Overrides the JavaScript toJSON() method in order to provide more useful output when an API object is passed to JSON.stringify(). (JSON.stringify反过来, 也会调用传递toJSON给它的对象的方法。尽管原始的 Excel 图表对象是 API 对象, 但toJSON方法返回一个简单的 JavaScript 对象 (类型为Excel.Interfaces.ChartData, in turn, calls the toJSON method of the object that is passed to it.) Whereas the original Excel.Chart object is an API object, the toJSON method returns a plain JavaScript object (typed as Excel.Interfaces.ChartData), 其中包含原始对象中所有已加载的子属性的浅表副本。) that contains shallow copies of any loaded child properties from the original object.

toJSON(): Excel.Interfaces.ChartData;

返回

事件详细信息

onActivated

图表激活时发生。Occurs when the chart is activated.

[API 集: ExcelApi 1.8][ API set: ExcelApi 1.8 ]

readonly onActivated: OfficeExtension.EventHandlers<Excel.ChartActivatedEventArgs>;

返回

OfficeExtension.EventHandlers<Excel.ChartActivatedEventArgs>

示例Examples

Excel.run(function (context){
    var pieChart = context.workbook.worksheets.getActiveWorksheet().charts.getItem("Pie");
    pieChart.onActivated.add(function (event) {
        return Excel.run((context) => {
            console.log("The pie chart is the active chart. ID: " + event.chartId);
            return context.sync();
        });
    });
    return context.sync();
});

onDeactivated

图表停用时发生。Occurs when the chart is deactivated.

[API 集: ExcelApi 1.8][ API set: ExcelApi 1.8 ]

readonly onDeactivated: OfficeExtension.EventHandlers<Excel.ChartDeactivatedEventArgs>;

返回

OfficeExtension.EventHandlers<Excel.ChartDeactivatedEventArgs>

示例Examples

Excel.run(function (context){
    var pieChart = context.workbook.worksheets.getActiveWorksheet().charts.getItem("Pie");
    pieChart.onDeactivated.add(function (event) {
        return Excel.run((context) => {
            console.log("The pie chart is NOT active.");
            return context.sync();
        });
    });
    return context.sync();
});