Excel.ChartDataLabels class
表示图表点上的所有数据标签的集合。
注解
属性
auto |
指定数据标签是否根据上下文自动生成适当的文本。 |
context | 与 对象关联的请求上下文。 这会将加载项的进程连接到 Office 主机应用程序的进程。 |
format | 指定图表数据标签的格式,其中包括填充和字体格式。 |
geometric |
指定数据标签的几何形状类型。 有关详细信息,请参阅 |
horizontal |
指定图表数据标签的水平对齐方式。 有关详细信息,请参阅 |
leader |
获取一个 对象,该对象表示数据标签的前导线。 |
link |
指定数字格式是否链接到单元格。 如果 |
number |
指定数据标签的格式代码。 |
position | 表示数据标签位置的值。 有关详细信息,请参阅 |
separator | 表示用于图表中数据标签的分隔符的字符串。 |
show |
获取一个值,该值指示数据标签是否显示为带有附加到数据点的尾定位点的标注。 如果 |
show |
指定数据标签气泡大小是否可见。 |
show |
指定数据标签类别名称是否可见。 |
show |
指定一个值,该值指示是否为数据标签显示前导线。
|
show |
指定数据标签图例键是否可见。 |
show |
指定数据标签百分比是否可见。 |
show |
指定数据标签系列名称是否可见。 |
show |
指定数据标签值是否可见。 |
text |
表示文本针对数据标签的方向。 对于垂直方向文本,该值应为 -90 到 90 的整数或整数 180。 |
vertical |
表示图表数据标签垂直对齐。 有关详细信息,请参阅 |
方法
load(options) | 将命令加入队列以加载对象的指定属性。 阅读属性前必须先调用 |
load(property |
将命令加入队列以加载对象的指定属性。 阅读属性前必须先调用 |
load(property |
将命令加入队列以加载对象的指定属性。 阅读属性前必须先调用 |
set(properties, options) | 同时设置对象的多个属性。 可以传递具有相应属性的纯对象,也可以传递同一类型的另一个 API 对象。 |
set(properties) | 基于现有的已加载对象,同时对对象设置多个属性。 |
toJSON() | 重写 JavaScript |
属性详细信息
autoText
context
format
指定图表数据标签的格式,其中包括填充和字体格式。
readonly format: Excel.ChartDataLabelFormat;
属性值
注解
geometricShapeType
指定数据标签的几何形状类型。 有关详细信息,请参阅 Excel.GeometricShapeType
。
null
如果数据标签不是几何形状,则值为 。
geometricShapeType: Excel.GeometricShapeType | "LineInverse" | "Triangle" | "RightTriangle" | "Rectangle" | "Diamond" | "Parallelogram" | "Trapezoid" | "NonIsoscelesTrapezoid" | "Pentagon" | "Hexagon" | "Heptagon" | "Octagon" | "Decagon" | "Dodecagon" | "Star4" | "Star5" | "Star6" | "Star7" | "Star8" | "Star10" | "Star12" | "Star16" | "Star24" | "Star32" | "RoundRectangle" | "Round1Rectangle" | "Round2SameRectangle" | "Round2DiagonalRectangle" | "SnipRoundRectangle" | "Snip1Rectangle" | "Snip2SameRectangle" | "Snip2DiagonalRectangle" | "Plaque" | "Ellipse" | "Teardrop" | "HomePlate" | "Chevron" | "PieWedge" | "Pie" | "BlockArc" | "Donut" | "NoSmoking" | "RightArrow" | "LeftArrow" | "UpArrow" | "DownArrow" | "StripedRightArrow" | "NotchedRightArrow" | "BentUpArrow" | "LeftRightArrow" | "UpDownArrow" | "LeftUpArrow" | "LeftRightUpArrow" | "QuadArrow" | "LeftArrowCallout" | "RightArrowCallout" | "UpArrowCallout" | "DownArrowCallout" | "LeftRightArrowCallout" | "UpDownArrowCallout" | "QuadArrowCallout" | "BentArrow" | "UturnArrow" | "CircularArrow" | "LeftCircularArrow" | "LeftRightCircularArrow" | "CurvedRightArrow" | "CurvedLeftArrow" | "CurvedUpArrow" | "CurvedDownArrow" | "SwooshArrow" | "Cube" | "Can" | "LightningBolt" | "Heart" | "Sun" | "Moon" | "SmileyFace" | "IrregularSeal1" | "IrregularSeal2" | "FoldedCorner" | "Bevel" | "Frame" | "HalfFrame" | "Corner" | "DiagonalStripe" | "Chord" | "Arc" | "LeftBracket" | "RightBracket" | "LeftBrace" | "RightBrace" | "BracketPair" | "BracePair" | "Callout1" | "Callout2" | "Callout3" | "AccentCallout1" | "AccentCallout2" | "AccentCallout3" | "BorderCallout1" | "BorderCallout2" | "BorderCallout3" | "AccentBorderCallout1" | "AccentBorderCallout2" | "AccentBorderCallout3" | "WedgeRectCallout" | "WedgeRRectCallout" | "WedgeEllipseCallout" | "CloudCallout" | "Cloud" | "Ribbon" | "Ribbon2" | "EllipseRibbon" | "EllipseRibbon2" | "LeftRightRibbon" | "VerticalScroll" | "HorizontalScroll" | "Wave" | "DoubleWave" | "Plus" | "FlowChartProcess" | "FlowChartDecision" | "FlowChartInputOutput" | "FlowChartPredefinedProcess" | "FlowChartInternalStorage" | "FlowChartDocument" | "FlowChartMultidocument" | "FlowChartTerminator" | "FlowChartPreparation" | "FlowChartManualInput" | "FlowChartManualOperation" | "FlowChartConnector" | "FlowChartPunchedCard" | "FlowChartPunchedTape" | "FlowChartSummingJunction" | "FlowChartOr" | "FlowChartCollate" | "FlowChartSort" | "FlowChartExtract" | "FlowChartMerge" | "FlowChartOfflineStorage" | "FlowChartOnlineStorage" | "FlowChartMagneticTape" | "FlowChartMagneticDisk" | "FlowChartMagneticDrum" | "FlowChartDisplay" | "FlowChartDelay" | "FlowChartAlternateProcess" | "FlowChartOffpageConnector" | "ActionButtonBlank" | "ActionButtonHome" | "ActionButtonHelp" | "ActionButtonInformation" | "ActionButtonForwardNext" | "ActionButtonBackPrevious" | "ActionButtonEnd" | "ActionButtonBeginning" | "ActionButtonReturn" | "ActionButtonDocument" | "ActionButtonSound" | "ActionButtonMovie" | "Gear6" | "Gear9" | "Funnel" | "MathPlus" | "MathMinus" | "MathMultiply" | "MathDivide" | "MathEqual" | "MathNotEqual" | "CornerTabs" | "SquareTabs" | "PlaqueTabs" | "ChartX" | "ChartStar" | "ChartPlus";
属性值
Excel.GeometricShapeType | "LineInverse" | "Triangle" | "RightTriangle" | "Rectangle" | "Diamond" | "Parallelogram" | "Trapezoid" | "NonIsoscelesTrapezoid" | "Pentagon" | "Hexagon" | "Heptagon" | "Octagon" | "Decagon" | "Dodecagon" | "Star4" | "Star5" | "Star6" | "Star7" | "Star8" | "Star10" | "Star12" | "Star16" | "Star24" | "Star32" | "RoundRectangle" | "Round1Rectangle" | "Round2SameRectangle" | "Round2DiagonalRectangle" | "SnipRoundRectangle" | "Snip1Rectangle" | "Snip2SameRectangle" | "Snip2DiagonalRectangle" | "Plaque" | "Ellipse" | "Teardrop" | "HomePlate" | "Chevron" | "PieWedge" | "Pie" | "BlockArc" | "Donut" | "NoSmoking" | "RightArrow" | "LeftArrow" | "UpArrow" | "DownArrow" | "StripedRightArrow" | "NotchedRightArrow" | "BentUpArrow" | "LeftRightArrow" | "UpDownArrow" | "LeftUpArrow" | "LeftRightUpArrow" | "QuadArrow" | "LeftArrowCallout" | "RightArrowCallout" | "UpArrowCallout" | "DownArrowCallout" | "LeftRightArrowCallout" | "UpDownArrowCallout" | "QuadArrowCallout" | "BentArrow" | "UturnArrow" | "CircularArrow" | "LeftCircularArrow" | "LeftRightCircularArrow" | "CurvedRightArrow" | "CurvedLeftArrow" | "CurvedUpArrow" | "CurvedDownArrow" | "SwooshArrow" | "Cube" | "Can" | "LightningBolt" | "Heart" | "Sun" | "Moon" | "SmileyFace" | "IrregularSeal1" | "IrregularSeal2" | "FoldedCorner" | "Bevel" | "Frame" | "HalfFrame" | "Corner" | "DiagonalStripe" | "Chord" | "Arc" | "LeftBracket" | "RightBracket" | "LeftBrace" | "RightBrace" | "BracketPair" | "BracePair" | "Callout1" | "Callout2" | "Callout3" | "AccentCallout1" | "AccentCallout2" | "AccentCallout3" | "BorderCallout1" | "BorderCallout2" | "BorderCallout3" | "AccentBorderCallout1" | "AccentBorderCallout2" | "AccentBorderCallout3" | "WedgeRectCallout" | "WedgeRRectCallout" | "WedgeEllipseCallout" | "CloudCallout" | "Cloud" | "Ribbon" | "Ribbon2" | "EllipseRibbon" | "EllipseRibbon2" | "LeftRightRibbon" | "VerticalScroll" | "HorizontalScroll" | "Wave" | "DoubleWave" | "Plus" | "FlowChartProcess" | "FlowChartDecision" | "FlowChartInputOutput" | "FlowChartPredefinedProcess" | "FlowChartInternalStorage" | "FlowChartDocument" | "FlowChartMultidocument" | "FlowChartTerminator" | "FlowChartPreparation" | "FlowChartManualInput" | "FlowChartManualOperation" | "FlowChartConnector" | "FlowChartPunchedCard" | "FlowChartPunchedTape" | "FlowChartSummingJunction" | "FlowChartOr" | "FlowChartCollate" | "FlowChartSort" | "FlowChartExtract" | "FlowChartMerge" | "FlowChartOfflineStorage" | "FlowChartOnlineStorage" | "FlowChartMagneticTape" | "FlowChartMagneticDisk" | "FlowChartMagneticDrum" | "FlowChartDisplay" | "FlowChartDelay" | "FlowChartAlternateProcess" | "FlowChartOffpageConnector" | "ActionButtonBlank" | "ActionButtonHome" | "ActionButtonHelp" | "ActionButtonInformation" | "ActionButtonForwardNext" | "ActionButtonBackPrevious" | "ActionButtonEnd" | "ActionButtonBeginning" | "ActionButtonReturn" | "ActionButtonDocument" | "ActionButtonSound" | "ActionButtonMovie" | "Gear6" | "Gear9" | "Funnel" | "MathPlus" | "MathMinus" | "MathMultiply" | "MathDivide" | "MathEqual" | "MathNotEqual" | "CornerTabs" | "SquareTabs" | "PlaqueTabs" | "ChartX" | "ChartStar" | "ChartPlus"
注解
horizontalAlignment
指定图表数据标签的水平对齐方式。 有关详细信息,请参阅 Excel.ChartTextHorizontalAlignment
。 仅当数据标签的 为 0 时, TextOrientation
此属性才有效。
horizontalAlignment: Excel.ChartTextHorizontalAlignment | "Center" | "Left" | "Right" | "Justify" | "Distributed";
属性值
Excel.ChartTextHorizontalAlignment | "Center" | "Left" | "Right" | "Justify" | "Distributed"
注解
leaderLines
获取一个 对象,该对象表示数据标签的前导线。
readonly leaderLines: Excel.ChartLeaderLines;
属性值
注解
linkNumberFormat
指定数字格式是否链接到单元格。 如果 true
为 ,则当单元格中更改时,标签中的数字格式将更改。
linkNumberFormat: boolean;
属性值
boolean
注解
numberFormat
position
表示数据标签位置的值。 有关详细信息,请参阅 Excel.ChartDataLabelPosition
。
position: Excel.ChartDataLabelPosition | "Invalid" | "None" | "Center" | "InsideEnd" | "InsideBase" | "OutsideEnd" | "Left" | "Right" | "Top" | "Bottom" | "BestFit" | "Callout";
属性值
Excel.ChartDataLabelPosition | "Invalid" | "None" | "Center" | "InsideEnd" | "InsideBase" | "OutsideEnd" | "Left" | "Right" | "Top" | "Bottom" | "BestFit" | "Callout"
注解
separator
showAsStickyCallout
获取一个值,该值指示数据标签是否显示为带有附加到数据点的尾定位点的标注。 如果 true
为 ,则标注为以下值之一:“AccentCallout1”、“AccentCallout2”、“BorderCallout1”、“BorderCallout2”、“WedgeRectCallout”、“WedgeRectCallout”或“WedgeEllipseCallout”。 有关更多详细信息,请参阅 GeometricShapeType 。
readonly showAsStickyCallout: boolean;
属性值
boolean
注解
showBubbleSize
showCategoryName
showLeaderLines
指定一个值,该值指示是否为数据标签显示前导线。
true
如果显示前导线,则为 ;否则为 false
。
showLeaderLines: boolean;
属性值
boolean
注解
showLegendKey
showPercentage
showSeriesName
showValue
textOrientation
表示文本针对数据标签的方向。 对于垂直方向文本,该值应为 -90 到 90 的整数或整数 180。
textOrientation: number;
属性值
number
注解
verticalAlignment
表示图表数据标签垂直对齐。 有关详细信息,请参阅 Excel.ChartTextVerticalAlignment
。 仅当数据标签为 -90、90 或 180 时 TextOrientation
,此属性才有效。
verticalAlignment: Excel.ChartTextVerticalAlignment | "Center" | "Bottom" | "Top" | "Justify" | "Distributed";
属性值
Excel.ChartTextVerticalAlignment | "Center" | "Bottom" | "Top" | "Justify" | "Distributed"
注解
方法详细信息
load(options)
将命令加入队列以加载对象的指定属性。 阅读属性前必须先调用 context.sync()
。
load(options?: Excel.Interfaces.ChartDataLabelsLoadOptions): Excel.ChartDataLabels;
参数
提供要加载对象的属性的选项。
返回
load(propertyNames)
将命令加入队列以加载对象的指定属性。 阅读属性前必须先调用 context.sync()
。
load(propertyNames?: string | string[]): Excel.ChartDataLabels;
参数
- propertyNames
-
string | string[]
逗号分隔的字符串或指定要加载的属性的字符串数组。
返回
示例
// Show the series name in data labels and set the position of the data labels to "top".
await Excel.run(async (context) => {
const chart = context.workbook.worksheets.getItem("Sheet1").charts.getItem("Chart1");
chart.dataLabels.showValue = true;
chart.dataLabels.position = Excel.ChartDataLabelPosition.top;
chart.dataLabels.showSeriesName = true;
await context.sync();
console.log("Data labels shown");
});
load(propertyNamesAndPaths)
将命令加入队列以加载对象的指定属性。 阅读属性前必须先调用 context.sync()
。
load(propertyNamesAndPaths?: {
select?: string;
expand?: string;
}): Excel.ChartDataLabels;
参数
- propertyNamesAndPaths
-
{ select?: string; expand?: string; }
propertyNamesAndPaths.select
是一个逗号分隔的字符串,指定要加载的属性,是 propertyNamesAndPaths.expand
一个逗号分隔的字符串,指定要加载的导航属性。
返回
set(properties, options)
同时设置对象的多个属性。 可以传递具有相应属性的纯对象,也可以传递同一类型的另一个 API 对象。
set(properties: Interfaces.ChartDataLabelsUpdateData, options?: OfficeExtension.UpdateOptions): void;
参数
- properties
- Excel.Interfaces.ChartDataLabelsUpdateData
一个 JavaScript 对象,其属性按同构方式构造为调用方法的对象的属性。
- options
- OfficeExtension.UpdateOptions
提供一个选项,用于在 properties 对象尝试设置任何只读属性时禁止显示错误。
返回
void
set(properties)
基于现有的已加载对象,同时对对象设置多个属性。
set(properties: Excel.ChartDataLabels): void;
参数
- properties
- Excel.ChartDataLabels
返回
void
toJSON()
重写 JavaScript toJSON()
方法,以便在将 API 对象传递给 JSON.stringify()
时提供更有用的输出。
JSON.stringify
(,依次调用toJSON
传递给它的 对象的 方法。) 虽然原始Excel.ChartDataLabels
对象是 API 对象,toJSON
但该方法返回一个纯 JavaScript 对象, (类型为 Excel.Interfaces.ChartDataLabelsData
) ,其中包含从原始对象加载的任何子属性的浅表副本。
toJSON(): Excel.Interfaces.ChartDataLabelsData;