Excel.ChartFill class

表示图表元素的格式填充。Represents the fill formatting for a chart element.

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

Extends

属性

context

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

方法

clear()

清除图表元素的填充颜色。Clear the fill color of a chart element.

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

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.

setSolidColor(color)

将图表元素的填充格式设置为统一颜色。Sets the fill formatting of a chart element to a uniform color.

[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给它的对象的方法。尽管原始 ChartFill 对象是 API 对象, 但toJSON方法返回一个无格式的 JavaScript 对象 (类型为Excel.Interfaces.ChartFillData, in turn, calls the toJSON method of the object that is passed to it.) Whereas the original Excel.ChartFill object is an API object, the toJSON method returns a plain JavaScript object (typed as Excel.Interfaces.ChartFillData), 其中包含原始对象中所有已加载的子属性的浅表副本。) that contains shallow copies of any loaded child properties from the original object.

属性详细信息

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

方法详细信息

clear()

清除图表元素的填充颜色。Clear the fill color of a chart element.

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

clear(): void;

返回

void

示例Examples

// Clear the line format of the major Gridlines on value axis of the Chart named "Chart1"
Excel.run(function (ctx) { 
    var gridlines = ctx.workbook.worksheets.getItem("Sheet1").charts.getItem("Chart1").axes.valueAxis.majorGridlines;
    gridlines.format.line.clear();
    return ctx.sync().then(function() {
            console.log("Chart Major Gridlines Format Cleared");
    });
}).catch(function(error) {
    console.log("Error: " + error);
    if (error instanceof OfficeExtension.Error) {
        console.log("Debug info: " + JSON.stringify(error.debugInfo));
    }
});

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?: string | string[] | OfficeExtension.LoadOption): Excel.ChartFill;

参数

option
string | string | OfficeExtension.LoadOption[]

返回

setSolidColor(color)

将图表元素的填充格式设置为统一颜色。Sets the fill formatting of a chart element to a uniform color.

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

setSolidColor(color: string): void;

参数

color
string

代表#RRGGBB (例如 "FFA500") 或命名的 HTML 颜色 (例如 "橙色") 的边框线条颜色的 HTML 颜色代码。HTML color code representing the color of the border line, of the form #RRGGBB (e.g. "FFA500") or as a named HTML color (e.g. "orange").

返回

void

示例Examples

Excel.run(function (ctx) { 
    var chart = ctx.workbook.worksheets.getItem("Sheet1").charts.getItem("Chart1");    

    chart.format.fill.setSolidColor("#FF0000");

    return ctx.sync().then(function() {
            console.log("Chart1 Background Color Changed.");
    });
}).catch(function(error) {
    console.log("Error: " + error);
    if (error instanceof OfficeExtension.Error) {
        console.log("Debug info: " + JSON.stringify(error.debugInfo));
    }
});
await Excel.run(async (context) => {
    const sheet = context.workbook.worksheets.getItem("Sample");

    let pointsCollection = sheet.charts.getItemAt(0).series.getItemAt(0).points;
    let point = pointsCollection.getItemAt(2);

    // Set color for chart point.
    point.format.fill.setSolidColor('red');

    await context.sync();        
});

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给它的对象的方法。尽管原始 ChartFill 对象是 API 对象, 但toJSON方法返回一个无格式的 JavaScript 对象 (类型为Excel.Interfaces.ChartFillData, in turn, calls the toJSON method of the object that is passed to it.) Whereas the original Excel.ChartFill object is an API object, the toJSON method returns a plain JavaScript object (typed as Excel.Interfaces.ChartFillData), 其中包含原始对象中所有已加载的子属性的浅表副本。) that contains shallow copies of any loaded child properties from the original object.

toJSON(): {
            [key: string]: string;
        };

返回

{ [key: string]: string; }