Excel.ChartFill class

表示图表元素的格式填充。

Extends

注解

[ API 集:ExcelApi 1.1 ]

属性

context

与 对象关联的请求上下文。 这会将加载项的进程连接到 Office 主机应用程序的进程。

方法

clear()

清除图表元素的填充颜色。

setSolidColor(color)

将图表元素的填充格式设置为统一颜色。

toJSON()

重写 JavaScript toJSON() 方法,以便在将 API 对象传递给 JSON.stringify()时提供更有用的输出。 JSON.stringify (,反过来又调用toJSON传递给它的 对象的 方法。) 而原始 Excel.ChartFill 对象是 API 对象,toJSON该方法返回一个纯 JavaScript 对象 (类型为 Excel.Interfaces.ChartFillData) ,该对象包含原始对象中任何已加载子属性的浅表副本。

属性详细信息

context

与 对象关联的请求上下文。 这会将加载项的进程连接到 Office 主机应用程序的进程。

context: RequestContext;

属性值

方法详细信息

clear()

清除图表元素的填充颜色。

clear(): void;

返回

void

注解

[ API 集:ExcelApi 1.1 ]

示例

// Clear the line format of the major gridlines on the value axis of the chart named "Chart1".
await Excel.run(async (context) => { 
    const gridlines = context.workbook.worksheets.getItem("Sheet1").charts.getItem("Chart1").axes.valueAxis.majorGridlines;
    gridlines.format.line.clear();
    await context.sync();
    
    console.log("Chart Major Gridlines Format Cleared");
});

setSolidColor(color)

将图表元素的填充格式设置为统一颜色。

setSolidColor(color: string): void;

参数

color

string

表示背景颜色的 HTML 颜色代码,格式#RRGGBB (例如“FFA500”) 或命名的 HTML 颜色 (例如“orange”) 。

返回

void

注解

[ API 集:ExcelApi 1.1 ]

示例

// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/excel/10-chart/chart-point.yaml

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()时提供更有用的输出。 JSON.stringify (,反过来又调用toJSON传递给它的 对象的 方法。) 而原始 Excel.ChartFill 对象是 API 对象,toJSON该方法返回一个纯 JavaScript 对象 (类型为 Excel.Interfaces.ChartFillData) ,该对象包含原始对象中任何已加载子属性的浅表副本。

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

返回

{ [key: string]: string; }