Excel.ChartSeries class
代表图表上的系列。
- 扩展
注解
属性
axis |
指定指定系列的组。 |
bin |
封装直方图和排列图的容器选项。 |
boxwhisker |
封装箱形图的选项。 |
bubble |
这可以是从 0(零)到 300 的整数值,表示默认大小的百分比。 该属性仅适用于气泡图。 |
chart |
表示系列的图表类型。 有关详细信息,请参阅 |
context | 与 对象关联的请求上下文。 这会将加载项的进程连接到 Office 主机应用程序的进程。 |
data |
表示系列中的所有数据标签的集合。 |
doughnut |
表示图表系列的圆环孔大小。 仅适用于圆环图和圆环图分解图。 在 |
explosion | 指定饼图或圆环图切片的爆炸值。 如果未分解(切片尖端位于饼图中心),则返回 0(零)。 |
filtered | 指定是否筛选序列。 不适用于曲面图。 |
first |
指定第一个饼图或圆环图切片的角度,以度为单位, (垂直) 顺时针。 只适用于饼图、三维饼图和圆环图。 可以是 0 到 360 之间的值。 |
format | 表示图表系列的格式,包括填充和线条格式。 |
gap |
表示图表系列的间隙宽度。 仅适用于条形图和柱形图,以及折线图和饼图的特定类。 在无效图表上引发无效参数异常。 |
gradient |
指定区域地图图表系列最大值的颜色。 |
gradient |
指定区域地图图表系列最大值的类型。 |
gradient |
指定区域地图图表系列的最大值。 |
gradient |
指定区域地图图表系列的中点值的颜色。 |
gradient |
指定区域地图图表系列的中点值的类型。 |
gradient |
指定区域地图图表系列的中点值。 |
gradient |
指定区域地图图表系列的最小值的颜色。 |
gradient |
指定区域地图图表系列的最小值的类型。 |
gradient |
指定区域地图图表系列的最小值。 |
gradient |
指定区域地图图表的系列渐变样式。 |
has |
指定序列是否具有数据标签。 |
invert |
指定序列中负数据点的填充颜色。 |
invert |
如此 如果 Excel 反转项中的模式时它对应于负数。 |
map |
封装区域地图图表的选项。 |
marker |
指定图表系列的标记背景色。 |
marker |
指定图表系列的标记前景色。 |
marker |
指定图表系列的标记大小。 支持的大小范围为 2 到 72。 如果设置为超出支持范围的大小,此方法将返回 InvalidArgument 错误。 |
marker |
指定图表系列的标记样式。 有关详细信息,请参阅 |
name | 指定图表中序列的名称。 名称的长度不应大于 255 个字符。 |
overlap | 指定条柱的摆放方式。 可以是 -100 到 100 之间的值。 只适用于二维条形图和二维柱形图。 |
parent |
指定树状图的系列父标签策略区域。 |
plot |
指定图表组中图表系列的绘图顺序。 |
points | 返回序列中所有点的集合。 |
second |
以主饼图大小百分比的形式指定饼图或饼图条形图的次要部分的大小。 可以是 5 到 200 之间的值。 |
show |
指定是否在瀑布图中显示连接线。 |
show |
指定是否为系列中的每个数据标签显示前导线。 |
show |
指定序列是否具有阴影。 |
smooth | 指定序列是否平滑。 仅适用于折线图和散点图。 |
split |
指定饼图或饼图条形图的两个部分的拆分方式。 |
split |
指定用于分隔饼图或饼条形图的两个部分的阈值。 |
trendlines | 系列中趋势线的集合。 |
vary |
如果 Excel 为每个数据标记分配不同的颜色或图案,则为 True。 图表必须只包含一个系列。 |
x |
表示图表系列的误差线对象。 |
y |
表示图表系列的误差线对象。 |
方法
delete() | 删除 chart series 对象。 |
load(options) | 将命令加入队列以加载对象的指定属性。 阅读属性前必须先调用 |
load(property |
将命令加入队列以加载对象的指定属性。 阅读属性前必须先调用 |
load(property |
将命令加入队列以加载对象的指定属性。 阅读属性前必须先调用 |
set(properties, options) | 同时设置对象的多个属性。 可以传递具有相应属性的纯对象,也可以传递同一类型的另一个 API 对象。 |
set(properties) | 基于现有的已加载对象,同时对对象设置多个属性。 |
set |
设置图表系列的气泡大小。 仅适用于气泡图。 |
set |
设置图表系列的值。 对于散点图,它指的是 y 轴值。 |
set |
设置图表系列的 x 轴值。 |
toJSON() | 重写 JavaScript |
属性详细信息
axisGroup
指定指定系列的组。
axisGroup: Excel.ChartAxisGroup | "Primary" | "Secondary";
属性值
Excel.ChartAxisGroup | "Primary" | "Secondary"
注解
binOptions
封装直方图和排列图的容器选项。
readonly binOptions: Excel.ChartBinOptions;
属性值
注解
boxwhiskerOptions
封装箱形图的选项。
readonly boxwhiskerOptions: Excel.ChartBoxwhiskerOptions;
属性值
注解
bubbleScale
这可以是从 0(零)到 300 的整数值,表示默认大小的百分比。 该属性仅适用于气泡图。
bubbleScale: number;
属性值
number
注解
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"
注解
context
dataLabels
表示系列中的所有数据标签的集合。
readonly dataLabels: Excel.ChartDataLabels;
属性值
注解
doughnutHoleSize
表示图表系列的圆环孔大小。 仅适用于圆环图和圆环图分解图。 在 InvalidArgument
无效图表上引发错误。
doughnutHoleSize: number;
属性值
number
注解
explosion
filtered
firstSliceAngle
指定第一个饼图或圆环图切片的角度,以度为单位, (垂直) 顺时针。 只适用于饼图、三维饼图和圆环图。 可以是 0 到 360 之间的值。
firstSliceAngle: number;
属性值
number
注解
format
表示图表系列的格式,包括填充和线条格式。
readonly format: Excel.ChartSeriesFormat;
属性值
注解
gapWidth
表示图表系列的间隙宽度。 仅适用于条形图和柱形图,以及折线图和饼图的特定类。 在无效图表上引发无效参数异常。
gapWidth: number;
属性值
number
注解
gradientMaximumColor
gradientMaximumType
指定区域地图图表系列最大值的类型。
gradientMaximumType: Excel.ChartGradientStyleType | "ExtremeValue" | "Number" | "Percent";
属性值
Excel.ChartGradientStyleType | "ExtremeValue" | "Number" | "Percent"
注解
gradientMaximumValue
gradientMidpointColor
gradientMidpointType
指定区域地图图表系列的中点值的类型。
gradientMidpointType: Excel.ChartGradientStyleType | "ExtremeValue" | "Number" | "Percent";
属性值
Excel.ChartGradientStyleType | "ExtremeValue" | "Number" | "Percent"
注解
gradientMidpointValue
gradientMinimumColor
gradientMinimumType
指定区域地图图表系列的最小值的类型。
gradientMinimumType: Excel.ChartGradientStyleType | "ExtremeValue" | "Number" | "Percent";
属性值
Excel.ChartGradientStyleType | "ExtremeValue" | "Number" | "Percent"
注解
gradientMinimumValue
gradientStyle
指定区域地图图表的系列渐变样式。
gradientStyle: Excel.ChartGradientStyle | "TwoPhaseColor" | "ThreePhaseColor";
属性值
Excel.ChartGradientStyle | "TwoPhaseColor" | "ThreePhaseColor"
注解
hasDataLabels
invertColor
invertIfNegative
mapOptions
封装区域地图图表的选项。
readonly mapOptions: Excel.ChartMapOptions;
属性值
注解
markerBackgroundColor
指定图表系列的标记背景色。
markerBackgroundColor: string;
属性值
string
注解
示例
// 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
注解
示例
// 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
注解
示例
// 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"
注解
示例
// 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
overlap
指定条柱的摆放方式。 可以是 -100 到 100 之间的值。 只适用于二维条形图和二维柱形图。
overlap: number;
属性值
number
注解
parentLabelStrategy
指定树状图的系列父标签策略区域。
parentLabelStrategy: Excel.ChartParentLabelStrategy | "None" | "Banner" | "Overlapping";
属性值
Excel.ChartParentLabelStrategy | "None" | "Banner" | "Overlapping"
注解
plotOrder
points
返回序列中所有点的集合。
readonly points: Excel.ChartPointsCollection;
属性值
注解
secondPlotSize
以主饼图大小百分比的形式指定饼图或饼图条形图的次要部分的大小。 可以是 5 到 200 之间的值。
secondPlotSize: number;
属性值
number
注解
showConnectorLines
showLeaderLines
showShadow
smooth
splitType
指定饼图或饼图条形图的两个部分的拆分方式。
splitType: Excel.ChartSplitType | "SplitByPosition" | "SplitByValue" | "SplitByPercentValue" | "SplitByCustomSplit";
属性值
Excel.ChartSplitType | "SplitByPosition" | "SplitByValue" | "SplitByPercentValue" | "SplitByCustomSplit"
注解
splitValue
trendlines
系列中趋势线的集合。
readonly trendlines: Excel.ChartTrendlineCollection;
属性值
注解
varyByCategories
如果 Excel 为每个数据标记分配不同的颜色或图案,则为 True。 图表必须只包含一个系列。
varyByCategories: boolean;
属性值
boolean
注解
xErrorBars
表示图表系列的误差线对象。
readonly xErrorBars: Excel.ChartErrorBars;
属性值
注解
yErrorBars
表示图表系列的误差线对象。
readonly yErrorBars: Excel.ChartErrorBars;
属性值
注解
方法详细信息
delete()
删除 chart series 对象。
delete(): void;
返回
void
注解
示例
// 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;
参数
提供要加载对象的属性的选项。
返回
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
注解
示例
// 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
注解
示例
// 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");
let seriesCollection = sheet.charts.getItemAt(0);
let rangeSelection = sheet.getRange("C2:C7");
let xRangeSelection = sheet.getRange("A1:A7");
// Add a series.
let newSeries = seriesCollection.series.add("Qtr2");
newSeries.setValues(rangeSelection);
newSeries.setXAxisValues(xRangeSelection);
await context.sync();
});
setXAxisValues(sourceData)
设置图表系列的 x 轴值。
setXAxisValues(sourceData: Range): void;
参数
- sourceData
- Excel.Range
对应于 Range
源数据的对象。
返回
void
注解
toJSON()
重写 JavaScript toJSON()
方法,以便在将 API 对象传递给 JSON.stringify()
时提供更有用的输出。
JSON.stringify
(,反过来,调用toJSON
传递给它的 对象的 方法。) 虽然原始 Excel.ChartSeries 对象是 API 对象,但toJSON
该方法返回一个纯 JavaScript 对象, (类型为 Excel.Interfaces.ChartSeriesData
) ,其中包含从原始对象加载的任何子属性的浅表副本。
toJSON(): Excel.Interfaces.ChartSeriesData;