Excel.ChartSeries class

代表图表上的系列。

扩展

注解

API 集:ExcelApi 1.1

使用方

示例

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

// The following code adds data labels to the chart and positions them to demonstrate leader lines.
await Excel.run(async (context) => {
  const sheet = context.workbook.worksheets.getItem(sheetName);
  const chart = sheet.charts.getItemAt(0);
  const series = chart.series.getItemAt(0);
  
  // Enable data labels for the series. Leader lines are enabled by default.
  series.hasDataLabels = true;
  series.points.load("items");
  await context.sync();
  
  // Load the top position for each data label.
  series.points.items.forEach((point) => point.dataLabel.load("top"));
  await context.sync();

  // Move some data labels to create distance from their chart points.
  const point1 = series.points.items[1]; 
  const point2 = series.points.items[2]; 
  point1.dataLabel.top -= 50; 
  point2.dataLabel.top += 50;
  
  // Format the data labels.
  series.dataLabels.geometricShapeType = Excel.GeometricShapeType.rectangle;
  series.dataLabels.showCategoryName = true;
  series.dataLabels.format.border.weight = 1;
  
  await context.sync();
});

属性

axisGroup

指定指定序列的组。

chartType

表示系列的图表类型。 有关详细信息,请参阅 Excel.ChartType。

context

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

dataLabels

表示系列中所有数据标签的集合。

doughnutHoleSize

表示图表系列的圆环孔大小。 仅对圆环图和圆环分解图有效。 在无效图表上引发 InvalidArgument 错误。

explosion

指定饼图或圆环图切片的爆炸值。 如果未分解(切片尖端位于饼图中心),则返回 0(零)。

filtered

指定是否筛选序列。 不适用于曲面图。

firstSliceAngle

指定第一个饼图或圆环图切片的角度,从垂直) 顺时针方向 (度为单位。 只适用于饼图、三维饼图和圆环图。 可以是 0 到 360 之间的值。

format

表示图表系列的格式,包括填充和线条格式。

gapWidth

表示图表系列的间隙宽度。 仅对条形图和柱形图以及特定类别的折线图和饼图有效。 在无效图表上引发无效参数异常。

hasDataLabels

指定系列是否具有数据标签。

invertIfNegative

如果 Excel 在项对应于负数时反转项中的模式,则为 true。

markerBackgroundColor

指定图表系列的标记背景色。

markerForegroundColor

指定图表系列的标记前景色。

markerSize

指定一系列图表的标记大小。 支持的大小范围为 2 到 72。 如果设置的大小超出支持范围,则此方法将返回 InvalidArgument 错误。

markerStyle

指定图表系列的标记样式。 有关详细信息,请参阅 Excel.ChartMarkerStyle。

name

指定图表中一系列的名称。 名称的长度不应超过 255 个字符。

overlap

指定条柱的摆放方式。 可以是 -100 到 100 之间的值。 只适用于二维条形图和二维柱形图。

plotOrder

指定图表组中图表系列的绘图顺序。

points

返回系列中所有点的集合。

secondPlotSize

指定饼图或条形饼图的次要部分的大小,以主饼图大小的百分比表示。 可以是 5 到 200 之间的值。

showShadow

指定序列是否具有阴影。

smooth

指定序列是否平滑。 仅适用于折线图和散点图。

splitType

指定饼图或条形饼图的两个部分的拆分方式。

trendlines

系列中趋势线的集合。

varyByCategories

如果 Excel 为每个数据标记分配不同的颜色或图案,则为 true。 图表必须只包含一个系列。

方法

delete()

删除 chart series 对象。

load(options)

将命令加入队列以加载对象的指定属性。 阅读属性前必须先调用 context.sync()。

load(propertyNames)

将命令加入队列以加载对象的指定属性。 阅读属性前必须先调用 context.sync()。

load(propertyNamesAndPaths)

将命令加入队列以加载对象的指定属性。 阅读属性前必须先调用 context.sync()。

set(properties, options)

同时设置对象的多个属性。 可以传递具有相应属性的纯文本对象,也可以传递另一个相同类型的 API 对象。

set(properties)

基于现有加载的对象,同时在对象上设置多个属性。

setBubbleSizes(sourceData)

设置图表系列的气泡大小。 仅适用于气泡图。

setValues(sourceData)

设置图表系列的值。 对于散点图,它引用 y 轴值。

setXAxisValues(sourceData)

设置图表系列的 x 轴的值。

toJSON()

覆盖 JavaScript toJSON() 方法,以便在将 API 对象传递给 JSON.stringify()时提供更有用的输出。 (JSON.stringify反过来调用 toJSON 传递给它的对象的方法。) 虽然原始 Excel.ChartSeries 对象是 API 对象, toJSON 但该方法返回一个纯 JavaScript 对象, (类型化为 Excel.Interfaces.ChartSeriesData) ,其中包含从原始对象加载的任何子属性的浅层副本。

属性详细信息

axisGroup

指定指定序列的组。

axisGroup: Excel.ChartAxisGroup | "Primary" | "Secondary";

属性值

Excel.ChartAxisGroup | "Primary" | "Secondary"

注解

API 集:ExcelApi 1.8

chartType

表示系列的图表类型。 有关详细信息,请参阅 Excel.ChartType。

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"

注解

API 集:ExcelApi 1.7

context

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

context: RequestContext;

属性值

dataLabels

表示系列中所有数据标签的集合。

readonly dataLabels: Excel.ChartDataLabels;

属性值

注解

API 集:ExcelApi 1.8

doughnutHoleSize

表示图表系列的圆环孔大小。 仅对圆环图和圆环分解图有效。 在无效图表上引发 InvalidArgument 错误。

doughnutHoleSize: number;

属性值

number

注解

API 集:ExcelApi 1.7

explosion

指定饼图或圆环图切片的爆炸值。 如果未分解(切片尖端位于饼图中心),则返回 0(零)。

explosion: number;

属性值

number

注解

API 集:ExcelApi 1.8

filtered

指定是否筛选序列。 不适用于曲面图。

filtered: boolean;

属性值

boolean

注解

API 集:ExcelApi 1.7

firstSliceAngle

指定第一个饼图或圆环图切片的角度,从垂直) 顺时针方向 (度为单位。 只适用于饼图、三维饼图和圆环图。 可以是 0 到 360 之间的值。

firstSliceAngle: number;

属性值

number

注解

API 集:ExcelApi 1.8

format

表示图表系列的格式,包括填充和线条格式。

readonly format: Excel.ChartSeriesFormat;

属性值

注解

API 集:ExcelApi 1.1

示例

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

await Excel.run(async (context) => {
    const worksheet = context.workbook.worksheets.getActiveWorksheet();
    const chart = worksheet.charts.getItem("SlopeChart");
    chart.series.load("count");
    await context.sync();

    // Color everything gray before highlighting spokes.
    for (let i = 0; i < chart.series.count; i++) {
        chart.series.getItemAt(i).format.line.color = "#636363";
        chart.series.getItemAt(i).dataLabels.format.font.color = "#636363";
    }

    const highlight: Excel.ChartSeries = chart.series.getItemAt(5);
    highlight.format.line.color = "#4472C4";
    highlight.dataLabels.format.font.color = "#D9D9D9";

    highlight.load("name");
    await context.sync();
    highlight.name += " (Focus)";
    await context.sync();
});

gapWidth

表示图表系列的间隙宽度。 仅对条形图和柱形图以及特定类别的折线图和饼图有效。 在无效图表上引发无效参数异常。

gapWidth: number;

属性值

number

注解

API 集:ExcelApi 1.7

hasDataLabels

指定系列是否具有数据标签。

hasDataLabels: boolean;

属性值

boolean

注解

API 集:ExcelApi 1.7

示例

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

// The following code adds data labels to the chart and positions them to demonstrate leader lines.
await Excel.run(async (context) => {
  const sheet = context.workbook.worksheets.getItem(sheetName);
  const chart = sheet.charts.getItemAt(0);
  const series = chart.series.getItemAt(0);
  
  // Enable data labels for the series. Leader lines are enabled by default.
  series.hasDataLabels = true;
  series.points.load("items");
  await context.sync();
  
  // Load the top position for each data label.
  series.points.items.forEach((point) => point.dataLabel.load("top"));
  await context.sync();

  // Move some data labels to create distance from their chart points.
  const point1 = series.points.items[1]; 
  const point2 = series.points.items[2]; 
  point1.dataLabel.top -= 50; 
  point2.dataLabel.top += 50;
  
  // Format the data labels.
  series.dataLabels.geometricShapeType = Excel.GeometricShapeType.rectangle;
  series.dataLabels.showCategoryName = true;
  series.dataLabels.format.border.weight = 1;
  
  await context.sync();
});

invertIfNegative

如果 Excel 在项对应于负数时反转项中的模式,则为 true。

invertIfNegative: boolean;

属性值

boolean

注解

API 集:ExcelApi 1.8

markerBackgroundColor

指定图表系列的标记背景色。

markerBackgroundColor: string;

属性值

string

注解

API 集:ExcelApi 1.7

示例

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

await Excel.run(async (context) => {
    let sheet = context.workbook.worksheets.getItem("Sample");
    let salesTable = sheet.tables.getItem("SalesTable");
    let dataRange = sheet.getRange("A1:E7");

    // Create an XY scatter chart.
    let chart = sheet.charts.add("XYScatterSmooth", dataRange, "Auto");
    chart.title.text = "Bicycle Parts Quarterly Sales"; 
  
    let series = chart.series;
    let series0 = series.getItemAt(0);
    let series1 = series.getItemAt(1);
    let series2 = series.getItemAt(2);
    let series3 = series.getItemAt(3);

    // Set markers.
    series0.markerStyle = "Dash";
    series0.markerForegroundColor = "black";
    series1.markerStyle = "Star";
    series1.markerForegroundColor = "black";
    series2.markerStyle = "X";
    series2.markerSize = 12;
    series3.markerStyle = "Triangle";
    series3.markerBackgroundColor = "purple";

    await context.sync();
});

markerForegroundColor

指定图表系列的标记前景色。

markerForegroundColor: string;

属性值

string

注解

API 集:ExcelApi 1.7

示例

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

await Excel.run(async (context) => {
    let sheet = context.workbook.worksheets.getItem("Sample");
    let salesTable = sheet.tables.getItem("SalesTable");
    let dataRange = sheet.getRange("A1:E7");

    // Create an XY scatter chart.
    let chart = sheet.charts.add("XYScatterSmooth", dataRange, "Auto");
    chart.title.text = "Bicycle Parts Quarterly Sales"; 
  
    let series = chart.series;
    let series0 = series.getItemAt(0);
    let series1 = series.getItemAt(1);
    let series2 = series.getItemAt(2);
    let series3 = series.getItemAt(3);

    // Set markers.
    series0.markerStyle = "Dash";
    series0.markerForegroundColor = "black";
    series1.markerStyle = "Star";
    series1.markerForegroundColor = "black";
    series2.markerStyle = "X";
    series2.markerSize = 12;
    series3.markerStyle = "Triangle";
    series3.markerBackgroundColor = "purple";

    await context.sync();
});

markerSize

指定一系列图表的标记大小。 支持的大小范围为 2 到 72。 如果设置的大小超出支持范围,则此方法将返回 InvalidArgument 错误。

markerSize: number;

属性值

number

注解

API 集:ExcelApi 1.7

示例

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

await Excel.run(async (context) => {
    let sheet = context.workbook.worksheets.getItem("Sample");
    let salesTable = sheet.tables.getItem("SalesTable");
    let dataRange = sheet.getRange("A1:E7");

    // Create an XY scatter chart.
    let chart = sheet.charts.add("XYScatterSmooth", dataRange, "Auto");
    chart.title.text = "Bicycle Parts Quarterly Sales"; 
  
    let series = chart.series;
    let series0 = series.getItemAt(0);
    let series1 = series.getItemAt(1);
    let series2 = series.getItemAt(2);
    let series3 = series.getItemAt(3);

    // Set markers.
    series0.markerStyle = "Dash";
    series0.markerForegroundColor = "black";
    series1.markerStyle = "Star";
    series1.markerForegroundColor = "black";
    series2.markerStyle = "X";
    series2.markerSize = 12;
    series3.markerStyle = "Triangle";
    series3.markerBackgroundColor = "purple";

    await context.sync();
});

markerStyle

指定图表系列的标记样式。 有关详细信息,请参阅 Excel.ChartMarkerStyle。

markerStyle: Excel.ChartMarkerStyle | "Invalid" | "Automatic" | "None" | "Square" | "Diamond" | "Triangle" | "X" | "Star" | "Dot" | "Dash" | "Circle" | "Plus" | "Picture";

属性值

Excel.ChartMarkerStyle | "Invalid" | "Automatic" | "None" | "Square" | "Diamond" | "Triangle" | "X" | "Star" | "Dot" | "Dash" | "Circle" | "Plus" | "Picture"

注解

API 集:ExcelApi 1.7

示例

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

await Excel.run(async (context) => {
    let sheet = context.workbook.worksheets.getItem("Sample");
    let salesTable = sheet.tables.getItem("SalesTable");
    let dataRange = sheet.getRange("A1:E7");

    // Create an XY scatter chart.
    let chart = sheet.charts.add("XYScatterSmooth", dataRange, "Auto");
    chart.title.text = "Bicycle Parts Quarterly Sales"; 
  
    let series = chart.series;
    let series0 = series.getItemAt(0);
    let series1 = series.getItemAt(1);
    let series2 = series.getItemAt(2);
    let series3 = series.getItemAt(3);

    // Set markers.
    series0.markerStyle = "Dash";
    series0.markerForegroundColor = "black";
    series1.markerStyle = "Star";
    series1.markerForegroundColor = "black";
    series2.markerStyle = "X";
    series2.markerSize = 12;
    series3.markerStyle = "Triangle";
    series3.markerBackgroundColor = "purple";

    await context.sync();
});

name

指定图表中一系列的名称。 名称的长度不应超过 255 个字符。

name: string;

属性值

string

注解

API 集:ExcelApi 1.1

overlap

指定条柱的摆放方式。 可以是 -100 到 100 之间的值。 只适用于二维条形图和二维柱形图。

overlap: number;

属性值

number

注解

API 集:ExcelApi 1.8

plotOrder

指定图表组中图表系列的绘图顺序。

plotOrder: number;

属性值

number

注解

API 集:ExcelApi 1.7

points

返回系列中所有点的集合。

readonly points: Excel.ChartPointsCollection;

属性值

注解

API 集:ExcelApi 1.1

示例

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

// The following code adds data labels to the chart and positions them to demonstrate leader lines.
await Excel.run(async (context) => {
  const sheet = context.workbook.worksheets.getItem(sheetName);
  const chart = sheet.charts.getItemAt(0);
  const series = chart.series.getItemAt(0);
  
  // Enable data labels for the series. Leader lines are enabled by default.
  series.hasDataLabels = true;
  series.points.load("items");
  await context.sync();
  
  // Load the top position for each data label.
  series.points.items.forEach((point) => point.dataLabel.load("top"));
  await context.sync();

  // Move some data labels to create distance from their chart points.
  const point1 = series.points.items[1]; 
  const point2 = series.points.items[2]; 
  point1.dataLabel.top -= 50; 
  point2.dataLabel.top += 50;
  
  // Format the data labels.
  series.dataLabels.geometricShapeType = Excel.GeometricShapeType.rectangle;
  series.dataLabels.showCategoryName = true;
  series.dataLabels.format.border.weight = 1;
  
  await context.sync();
});

secondPlotSize

指定饼图或条形饼图的次要部分的大小,以主饼图大小的百分比表示。 可以是 5 到 200 之间的值。

secondPlotSize: number;

属性值

number

注解

API 集:ExcelApi 1.8

showShadow

指定序列是否具有阴影。

showShadow: boolean;

属性值

boolean

注解

API 集:ExcelApi 1.7

smooth

指定序列是否平滑。 仅适用于折线图和散点图。

smooth: boolean;

属性值

boolean

注解

API 集:ExcelApi 1.7

splitType

指定饼图或条形饼图的两个部分的拆分方式。

splitType: Excel.ChartSplitType | "SplitByPosition" | "SplitByValue" | "SplitByPercentValue" | "SplitByCustomSplit";

属性值

Excel.ChartSplitType | "SplitByPosition" | "SplitByValue" | "SplitByPercentValue" | "SplitByCustomSplit"

注解

API 集:ExcelApi 1.8

trendlines

系列中趋势线的集合。

readonly trendlines: Excel.ChartTrendlineCollection;

属性值

注解

API 集:ExcelApi 1.7

示例

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

await Excel.run(async (context) => {
    const sheet = context.workbook.worksheets.getItem("Sample");

    let seriesCollection = sheet.charts.getItemAt(0).series;

     // Add a trendline.  
    seriesCollection.getItemAt(0).trendlines.add("Linear");

    await context.sync();
});

varyByCategories

如果 Excel 为每个数据标记分配不同的颜色或图案,则为 true。 图表必须只包含一个系列。

varyByCategories: boolean;

属性值

boolean

注解

API 集:ExcelApi 1.8

方法详细信息

delete()

删除 chart series 对象。

delete(): void;

返回

void

注解

API 集:ExcelApi 1.7

示例

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

await Excel.run(async (context) => {
  const sheet = context.workbook.worksheets.getItem("Sample");
  const seriesCollection = sheet.charts.getItemAt(0).series;
  seriesCollection.load("count");
  await context.sync();

  if (seriesCollection.count > 0) {
    const series = seriesCollection.getItemAt(0);

    // Delete the first series.
    series.delete();
  }

  await context.sync();
});

load(options)

将命令加入队列以加载对象的指定属性。 阅读属性前必须先调用 context.sync()。

load(options?: Excel.Interfaces.ChartSeriesLoadOptions): Excel.ChartSeries;

参数

options
Excel.Interfaces.ChartSeriesLoadOptions

为要加载的对象属性提供选项。

返回

load(propertyNames)

将命令加入队列以加载对象的指定属性。 阅读属性前必须先调用 context.sync()。

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

参数

propertyNames

string | string[]

指定要加载的属性的逗号分隔的字符串或字符串数组。

返回

示例

// Rename the 1st series of Chart1 to "New Series Name".
await Excel.run(async (context) => { 
    const chart = context.workbook.worksheets.getItem("Sheet1").charts.getItem("Chart1");    
    chart.series.getItemAt(0).name = "New Series Name";
    await context.sync();

    console.log("Series1 Renamed");
});

load(propertyNamesAndPaths)

将命令加入队列以加载对象的指定属性。 阅读属性前必须先调用 context.sync()。

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

参数

propertyNamesAndPaths

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

propertyNamesAndPaths.select 是指定要加载的属性的逗号分隔字符串,以及 propertyNamesAndPaths.expand 指定要加载的导航属性的逗号分隔字符串。

返回

set(properties, options)

同时设置对象的多个属性。 可以传递具有相应属性的纯文本对象,也可以传递另一个相同类型的 API 对象。

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

参数

properties
Excel.Interfaces.ChartSeriesUpdateData

一个 JavaScript 对象,其属性与调用该方法的对象的属性同构结构。

options
OfficeExtension.UpdateOptions

提供一个选项,用于在 properties 对象尝试设置任何只读属性时禁止错误。

返回

void

set(properties)

基于现有加载的对象,同时在对象上设置多个属性。

set(properties: Excel.ChartSeries): void;

参数

properties
Excel.ChartSeries

返回

void

setBubbleSizes(sourceData)

设置图表系列的气泡大小。 仅适用于气泡图。

setBubbleSizes(sourceData: Range | string): void;

参数

sourceData

Excel.Range | string

A Range 或者,在 ApiSet 1.21 中,是 en-US 图表数据引用语法中的字符串。 字符串可以包含单元格或表引用、定义的名称、数字文本或数组。 字符串为空或 = 无效。

返回

void

注解

API 集:ExcelApi 1.7

示例

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

await Excel.run(async (context) => {
  /*
    The table is expected to look like this:
    Product, Inventory, Price, Current Market Share
    Calamansi, 2000, $2.45, 10%
    ...

    We want each bubble to represent a single row.
  */

  // Get the worksheet and table data.
  const sheet = context.workbook.worksheets.getItem("Sample");
  const table = sheet.tables.getItem("Sales");
  const dataRange = table.getDataBodyRange();

  // Get the table data without the row names.
  const valueRange = dataRange.getOffsetRange(0, 1).getResizedRange(0, -1);

  // Create the chart.
  const bubbleChart = sheet.charts.add(Excel.ChartType.bubble, valueRange);
  bubbleChart.name = "Product Chart";

  // Remove the default series, since we want a unique series for each row.
  bubbleChart.series.getItemAt(0).delete();

  // Load the data necessary to make a chart series.
  dataRange.load(["rowCount", "values"]);
  await context.sync();

  // For each row, create a chart series (a bubble).
  for (let i = 0; i < dataRange.rowCount; i++) {
    const newSeries = bubbleChart.series.add(dataRange.values[i][0], i);
    newSeries.setXAxisValues(dataRange.getCell(i, 1));
    newSeries.setValues(dataRange.getCell(i, 2));
    newSeries.setBubbleSizes(dataRange.getCell(i, 3));

    // Show the product name and market share percentage.
    newSeries.dataLabels.showSeriesName = true;
    newSeries.dataLabels.showBubbleSize = true;
    newSeries.dataLabels.showValue = false;
  }

  await context.sync();
});

setValues(sourceData)

设置图表系列的值。 对于散点图,它引用 y 轴值。

setValues(sourceData: Range): void;

参数

sourceData
Excel.Range

Range与源数据对应的对象。

返回

void

注解

API 集:ExcelApi 1.7

示例

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

await Excel.run(async (context) => {
  const sheet = context.workbook.worksheets.getItem("Sample");

  const chart: Excel.Chart = sheet.charts.getItemAt(0);
  let rangeSelection = sheet.getRange("C2:C7");
  let xRangeSelection = sheet.getRange("A1:A7");

  // Add a series.
  const newSeries: Excel.ChartSeries = chart.series.add("Qtr2");
  newSeries.setValues(rangeSelection);
  newSeries.setXAxisValues(xRangeSelection);

  await context.sync();
});

setXAxisValues(sourceData)

设置图表系列的 x 轴的值。

setXAxisValues(sourceData: Range): void;

参数

sourceData
Excel.Range

Range与源数据对应的对象。

返回

void

注解

API 集:ExcelApi 1.7

示例

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

await Excel.run(async (context) => {
    const sheet = context.workbook.worksheets.getItem("Sample");

    let seriesCollection = sheet.charts.getItemAt(0);
    let rangeSelection = sheet.getRange("C2:C7");
    let xRangeSelection = sheet.getRange("A1:A7");

    // Add a series.
    const newSeries: Excel.ChartSeries = seriesCollection.series.add("Qtr2");
    newSeries.setValues(rangeSelection);
    newSeries.setXAxisValues(xRangeSelection);

    // Set the size of the doughnut hole.
    // The hole size is expressed as a percentage of the chart size.
    newSeries.doughnutHoleSize = 80;

    await context.sync();
});

toJSON()

覆盖 JavaScript toJSON() 方法,以便在将 API 对象传递给 JSON.stringify()时提供更有用的输出。 (JSON.stringify反过来调用 toJSON 传递给它的对象的方法。) 虽然原始 Excel.ChartSeries 对象是 API 对象, toJSON 但该方法返回一个纯 JavaScript 对象, (类型化为 Excel.Interfaces.ChartSeriesData) ,其中包含从原始对象加载的任何子属性的浅层副本。

toJSON(): Excel.Interfaces.ChartSeriesData;

返回