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

指定指定序列的组。

binOptions

封装直方图和排列图的容器选项。

boxwhiskerOptions

封装箱形图的选项。

bubbleScale

这可以是从 0(零)到 300 的整数值,表示默认大小的百分比。 该属性仅适用于气泡图。

chartType

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

context

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

dataLabels

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

doughnutHoleSize

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

explosion

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

filtered

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

firstSliceAngle

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

format

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

gapWidth

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

gradientMaximumColor

指定区域地图图表系列最大值的颜色。

gradientMaximumType

指定区域地图图表系列的最大值的类型。

gradientMaximumValue

指定区域映射图表系列的最大值。

gradientMidpointColor

指定区域地图图表系列的中点值的颜色。

gradientMidpointType

指定区域地图图表系列的中点值的类型。

gradientMidpointValue

指定区域地图图表系列的中点值。

gradientMinimumColor

指定区域地图图表系列最小值的颜色。

gradientMinimumType

指定区域映射图表系列最小值的类型。

gradientMinimumValue

指定区域映射图表系列的最小值。

gradientStyle

指定区域地图图表的系列渐变样式。

hasDataLabels

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

invertColor

指定一系列中负数据点的填充颜色。

invertIfNegative

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

mapOptions

封装区域地图图表的选项。

markerBackgroundColor

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

markerForegroundColor

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

markerSize

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

markerStyle

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

name

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

overlap

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

parentLabelStrategy

指定树状图的系列父标签策略区域。

plotOrder

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

points

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

secondPlotSize

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

showConnectorLines

指定连接线是否在瀑布图中显示。

showLeaderLines

指定是否为系列中的每个数据标签显示引线。

showShadow

指定序列是否具有阴影。

smooth

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

splitType

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

splitValue

指定分隔饼图或条饼图两个部分的阈值。

trendlines

系列中趋势线的集合。

varyByCategories

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

xErrorBars

表示图表系列的误差线对象。

yErrorBars

表示图表系列的误差线对象。

方法

delete()

删除 chart series 对象。

getDimensionDataSourceString(dimension)

获取图表系列数据源的字符串表示形式。 字符串表示可以是单元格地址等信息。

getDimensionDataSourceString(dimension)

获取图表系列数据源的字符串表示形式。 字符串表示可以是单元格地址等信息。

getDimensionDataSourceType(dimension)

获取图表系列的数据源类型。

getDimensionDataSourceType(dimension)

获取图表系列的数据源类型。

getDimensionValues(dimension)

从图表系列的单个维度中获取值。 这些可以是类别值或数据值,具体取决于指定的维度以及图表系列映射数据的方式。

getDimensionValues(dimension)

从图表系列的单个维度中获取值。 这些可以是类别值或数据值,具体取决于指定的维度以及图表系列映射数据的方式。

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

binOptions

封装直方图和排列图的容器选项。

readonly binOptions: Excel.ChartBinOptions;

属性值

注解

API 集:ExcelApi 1.9

boxwhiskerOptions

封装箱形图的选项。

readonly boxwhiskerOptions: Excel.ChartBoxwhiskerOptions;

属性值

注解

API 集:ExcelApi 1.9

bubbleScale

这可以是从 0(零)到 300 的整数值,表示默认大小的百分比。 该属性仅适用于气泡图。

bubbleScale: number;

属性值

number

注解

API 集:ExcelApi 1.9

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" | "ColumnClusteredEx" | "ColumnStackedEx" | "ColumnStacked100Ex" | "LineEx" | "LineStackedEx" | "LineStacked100Ex" | "PieEx" | "DoughnutEx" | "BarClusteredEx" | "BarStackedEx" | "BarStacked100Ex" | "AreaEx" | "AreaStackedEx" | "AreaStacked100Ex" | "XYScatterEx" | "BubbleEx";

属性值

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" | "ColumnClusteredEx" | "ColumnStackedEx" | "ColumnStacked100Ex" | "LineEx" | "LineStackedEx" | "LineStacked100Ex" | "PieEx" | "DoughnutEx" | "BarClusteredEx" | "BarStackedEx" | "BarStacked100Ex" | "AreaEx" | "AreaStackedEx" | "AreaStacked100Ex" | "XYScatterEx" | "BubbleEx"

注解

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

gradientMaximumColor

指定区域地图图表系列最大值的颜色。

gradientMaximumColor: string;

属性值

string

注解

API 集:ExcelApi 1.9

gradientMaximumType

指定区域地图图表系列的最大值的类型。

gradientMaximumType: Excel.ChartGradientStyleType | "ExtremeValue" | "Number" | "Percent";

属性值

Excel.ChartGradientStyleType | "ExtremeValue" | "Number" | "Percent"

注解

API 集:ExcelApi 1.9

gradientMaximumValue

指定区域映射图表系列的最大值。

gradientMaximumValue: number;

属性值

number

注解

API 集:ExcelApi 1.9

gradientMidpointColor

指定区域地图图表系列的中点值的颜色。

gradientMidpointColor: string;

属性值

string

注解

API 集:ExcelApi 1.9

gradientMidpointType

指定区域地图图表系列的中点值的类型。

gradientMidpointType: Excel.ChartGradientStyleType | "ExtremeValue" | "Number" | "Percent";

属性值

Excel.ChartGradientStyleType | "ExtremeValue" | "Number" | "Percent"

注解

API 集:ExcelApi 1.9

gradientMidpointValue

指定区域地图图表系列的中点值。

gradientMidpointValue: number;

属性值

number

注解

API 集:ExcelApi 1.9

gradientMinimumColor

指定区域地图图表系列最小值的颜色。

gradientMinimumColor: string;

属性值

string

注解

API 集:ExcelApi 1.9

gradientMinimumType

指定区域映射图表系列最小值的类型。

gradientMinimumType: Excel.ChartGradientStyleType | "ExtremeValue" | "Number" | "Percent";

属性值

Excel.ChartGradientStyleType | "ExtremeValue" | "Number" | "Percent"

注解

API 集:ExcelApi 1.9

gradientMinimumValue

指定区域映射图表系列的最小值。

gradientMinimumValue: number;

属性值

number

注解

API 集:ExcelApi 1.9

gradientStyle

指定区域地图图表的系列渐变样式。

gradientStyle: Excel.ChartGradientStyle | "TwoPhaseColor" | "ThreePhaseColor";

属性值

Excel.ChartGradientStyle | "TwoPhaseColor" | "ThreePhaseColor"

注解

API 集:ExcelApi 1.9

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();
});

invertColor

指定一系列中负数据点的填充颜色。

invertColor: string;

属性值

string

注解

API 集:ExcelApi 1.9

invertIfNegative

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

invertIfNegative: boolean;

属性值

boolean

注解

API 集:ExcelApi 1.8

mapOptions

封装区域地图图表的选项。

readonly mapOptions: Excel.ChartMapOptions;

属性值

注解

API 集:ExcelApi 1.9

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

parentLabelStrategy

指定树状图的系列父标签策略区域。

parentLabelStrategy: Excel.ChartParentLabelStrategy | "None" | "Banner" | "Overlapping";

属性值

Excel.ChartParentLabelStrategy | "None" | "Banner" | "Overlapping"

注解

API 集:ExcelApi 1.9

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

showConnectorLines

指定连接线是否在瀑布图中显示。

showConnectorLines: boolean;

属性值

boolean

注解

API 集:ExcelApi 1.9

showLeaderLines

指定是否为系列中的每个数据标签显示引线。

showLeaderLines: boolean;

属性值

boolean

注解

API 集:ExcelApi 1.9

示例

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

// The following code disables leader lines for chart data labels.
await Excel.run(async (context) => {
  const sheet = context.workbook.worksheets.getItem(sheetName);
  const chart = sheet.charts.getItemAt(0);
  const series = chart.series.getItemAt(0);
  const dataLabels = series.dataLabels;
  
  // Disable leader lines.
  dataLabels.showLeaderLines = false;
  
  await context.sync();
});

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

splitValue

指定分隔饼图或条饼图两个部分的阈值。

splitValue: number;

属性值

number

注解

API 集:ExcelApi 1.9

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

xErrorBars

表示图表系列的误差线对象。

readonly xErrorBars: Excel.ChartErrorBars;

属性值

注解

API 集:ExcelApi 1.9

yErrorBars

表示图表系列的误差线对象。

readonly yErrorBars: Excel.ChartErrorBars;

属性值

注解

API 集:ExcelApi 1.9

方法详细信息

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();
});

getDimensionDataSourceString(dimension)

获取图表系列数据源的字符串表示形式。 字符串表示可以是单元格地址等信息。

getDimensionDataSourceString(dimension: Excel.ChartSeriesDimension): OfficeExtension.ClientResult<string>;

参数

dimension
Excel.ChartSeriesDimension

数据来源轴的维度。

返回

注解

API 集:ExcelApi 1.15

示例

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

// This function retrieves the data source information of a chart series in the Sample worksheet.
await Excel.run(async (context) => {
  const sheet = context.workbook.worksheets.getItem("Sample");

  // Get the first chart series from the first chart on the worksheet.
  const seriesCollection = sheet.charts.getItemAt(0).series;
  const series = seriesCollection.getItemAt(0);

  // Get the series data source string and type values. 
  const dataSourceString = series.getDimensionDataSourceString("Values");
  const dataSourceType = series.getDimensionDataSourceType("Values");

  series.load("name");
  await context.sync();
  
  // Log the data source information to the console.
  console.log(series.name + " data source string: " + dataSourceString.value);
  console.log(series.name + " data source type: " + dataSourceType.value);
});

getDimensionDataSourceString(dimension)

获取图表系列数据源的字符串表示形式。 字符串表示可以是单元格地址等信息。

getDimensionDataSourceString(dimension: "Categories" | "Values" | "XValues" | "YValues" | "BubbleSizes"): OfficeExtension.ClientResult<string>;

参数

dimension

"Categories" | "Values" | "XValues" | "YValues" | "BubbleSizes"

数据来源轴的维度。

返回

注解

API 集:ExcelApi 1.15

getDimensionDataSourceType(dimension)

获取图表系列的数据源类型。

getDimensionDataSourceType(dimension: Excel.ChartSeriesDimension): OfficeExtension.ClientResult<Excel.ChartDataSourceType>;

参数

dimension
Excel.ChartSeriesDimension

数据来源轴的维度。

返回

注解

API 集:ExcelApi 1.15

示例

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

// This function retrieves the data source information of a chart series in the Sample worksheet.
await Excel.run(async (context) => {
  const sheet = context.workbook.worksheets.getItem("Sample");

  // Get the first chart series from the first chart on the worksheet.
  const seriesCollection = sheet.charts.getItemAt(0).series;
  const series = seriesCollection.getItemAt(0);

  // Get the series data source string and type values. 
  const dataSourceString = series.getDimensionDataSourceString("Values");
  const dataSourceType = series.getDimensionDataSourceType("Values");

  series.load("name");
  await context.sync();
  
  // Log the data source information to the console.
  console.log(series.name + " data source string: " + dataSourceString.value);
  console.log(series.name + " data source type: " + dataSourceType.value);
});

getDimensionDataSourceType(dimension)

获取图表系列的数据源类型。

getDimensionDataSourceType(dimension: "Categories" | "Values" | "XValues" | "YValues" | "BubbleSizes"): OfficeExtension.ClientResult<Excel.ChartDataSourceType>;

参数

dimension

"Categories" | "Values" | "XValues" | "YValues" | "BubbleSizes"

数据来源轴的维度。

返回

注解

API 集:ExcelApi 1.15

getDimensionValues(dimension)

从图表系列的单个维度中获取值。 这些可以是类别值或数据值,具体取决于指定的维度以及图表系列映射数据的方式。

getDimensionValues(dimension: Excel.ChartSeriesDimension): OfficeExtension.ClientResult<string[]>;

参数

dimension
Excel.ChartSeriesDimension

数据来源轴的维度。

返回

注解

API 集:ExcelApi 1.12

示例

// 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) => {
  const sheet = context.workbook.worksheets.getItem("Sample");

  // The sample chart is of type `Excel.ChartType.bubble`.
  const bubbleChart = sheet.charts.getItem("Product Chart");

  // Get the first series in the chart.
  const firstSeries = bubbleChart.series.getItemAt(0);

  // Get the values for the dimensions we're interested in.
  const bubbleSize = firstSeries.getDimensionValues(Excel.ChartSeriesDimension.bubbleSizes);
  const xValues = firstSeries.getDimensionValues(Excel.ChartSeriesDimension.xvalues);
  const yValues = firstSeries.getDimensionValues(Excel.ChartSeriesDimension.yvalues);
  const category = firstSeries.getDimensionValues(Excel.ChartSeriesDimension.categories);

  await context.sync();

  // Log the information.
  console.log(`Series ${category.value} - X: ${xValues.value}, Y: ${yValues.value}, Bubble: ${bubbleSize.value}`);
});

getDimensionValues(dimension)

从图表系列的单个维度中获取值。 这些可以是类别值或数据值,具体取决于指定的维度以及图表系列映射数据的方式。

getDimensionValues(dimension: "Categories" | "Values" | "XValues" | "YValues" | "BubbleSizes"): OfficeExtension.ClientResult<string[]>;

参数

dimension

"Categories" | "Values" | "XValues" | "YValues" | "BubbleSizes"

数据来源轴的维度。

返回

注解

API 集:ExcelApi 1.12

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): 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-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;

返回