Excel.ChartDataLabel class

表示图表点的数据标签。

扩展

注解

API 集:ExcelApi 1.7

使用方

示例

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

// This function styles substrings within data label text using font formatting.
await Excel.run(async (context) => {
  const sheet = context.workbook.worksheets.getItem(sheetName);
  const chart = sheet.charts.getItemAt(0);
  await context.sync();

  const series = chart.series.getItemAt(0);
  series.load("points");
  await context.sync();

  series.points.load("items");
  await context.sync();

  // Style a substring in the first data label.
  let searchString = "sports";
  let dataLabel = series.points.getItemAt(dataLabelInfo[0].index).dataLabel.load("text");
  await context.sync();
  let substringStart = dataLabel.text.indexOf(searchString);
  let subLabel = dataLabel.getSubstring(substringStart, searchString.length);
  subLabel.font.size = 13;
  subLabel.font.bold = true;

  // Style a substring in the second data label.
  searchString = "'Titanic'";
  dataLabel = series.points.getItemAt(dataLabelInfo[1].index).dataLabel.load("text");
  await context.sync();

  substringStart = dataLabel.text.indexOf(searchString);
  subLabel = dataLabel.getSubstring(substringStart, searchString.length);
  subLabel.font.name = "Calibri";
  subLabel.font.size = 13;
  subLabel.font.italic = true;
  subLabel.font.color = "blue";
  await context.sync();
});

属性

autoText

指定数据标签是否根据上下文自动生成适当的文本。

context

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

format

表示图表数据标签的格式。

formula

该字符串值表示采用 A1 表示法的图表数据标签的公式。

geometricShapeType

指定数据标签的几何形状类型。 有关详细信息,请参阅 Excel.GeometricShapeType。 值为 null 数据标签不是几何形状时。

height

返回图表数据标签的高度,以磅为单位。 如果图表数据标签不可见,则值为 null

horizontalAlignment

表示图表数据标签水平对齐。 有关详细信息,请参阅 Excel.ChartTextHorizontalAlignment。 仅当数据标签为 -90、90 或 180 时, TextOrientation 此属性才有效。

left

表示图表数据标签左边缘到图表区域左边缘的距离,以磅为单位。 如果图表数据标签不可见,则值为 null

linkNumberFormat

指定数字格式是否链接到单元格 (,以便当数字格式在单元格) 中更改时,标签中的数字格式也会更改。

numberFormat

指定数据标签的格式代码。

position

表示数据标签位置的值。 有关详细信息,请参阅 Excel.ChartDataLabelPosition

separator

该字符串表示用于图表中数据标签的分隔符。

showAsStickyCallout

指定数据标签是否显示为标注,并将尾部定位点附加到数据点。 如果 ,标 true注是下列值之一:“AccentCallout1”、“AccentCallout2”、“BorderCallout1”、“BorderCallout2”、“WedgeRectCallout”、“WedgeRRectCallout”或“WedgeEllipseCallout”。 有关更多详细信息,请参阅 GeometricShapeType

showBubbleSize

指定数据标签气泡大小是否可见。

showCategoryName

指定数据标签类别名称是否可见。

showLegendKey

指定数据标签图例键是否可见。

showPercentage

指定数据标签百分比是否可见。

showSeriesName

指定数据标签系列名称是否可见。

showValue

指定数据标签值是否可见。

text

该字符串表示图表上的数据标签文本。

textOrientation

表示图表数据标签的文本朝向的角度。 该值应为 -90 到 90 之间的整数,对于垂直方向的文本,应为整数 180。

top

表示图表数据标签上边缘到图表区域顶部的距离,以磅为单位。 如果图表数据标签不可见,则值为 null

verticalAlignment

表示图表数据标签垂直对齐。 有关详细信息,请参阅 Excel.ChartTextVerticalAlignment。 仅当数据标签为 0 时, TextOrientation 此属性才有效。

width

返回图表数据标签的宽度,以磅为单位。 如果图表数据标签不可见,则值为 null

方法

getSubstring(start, length)

返回数据标签的子字符串。 换行符 '\n' 计为一个字符。

getTailAnchor()

返回显示为粘性标注的数据标签的尾部定位点。

load(options)

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

load(propertyNames)

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

load(propertyNamesAndPaths)

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

set(properties, options)

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

set(properties)

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

setHeight(height)

设置数据标签的高度(以磅为单位)。

setWidth(width)

设置数据标签的宽度(以磅为单位)。

toJSON()

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

属性详细信息

autoText

指定数据标签是否根据上下文自动生成适当的文本。

autoText: boolean;

属性值

boolean

注解

API 集:ExcelApi 1.8

context

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

context: RequestContext;

属性值

format

表示图表数据标签的格式。

readonly format: Excel.ChartDataLabelFormat;

属性值

注解

API 集:ExcelApi 1.8

formula

该字符串值表示采用 A1 表示法的图表数据标签的公式。

formula: string;

属性值

string

注解

API 集:ExcelApi 1.8

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"

注解

API 集:ExcelApi 1.19

height

返回图表数据标签的高度,以磅为单位。 如果图表数据标签不可见,则值为 null

readonly height: number;

属性值

number

注解

API 集:ExcelApi 1.8

horizontalAlignment

表示图表数据标签水平对齐。 有关详细信息,请参阅 Excel.ChartTextHorizontalAlignment。 仅当数据标签为 -90、90 或 180 时, TextOrientation 此属性才有效。

horizontalAlignment: Excel.ChartTextHorizontalAlignment | "Center" | "Left" | "Right" | "Justify" | "Distributed";

属性值

Excel.ChartTextHorizontalAlignment | "Center" | "Left" | "Right" | "Justify" | "Distributed"

注解

API 集:ExcelApi 1.8

left

表示图表数据标签左边缘到图表区域左边缘的距离,以磅为单位。 如果图表数据标签不可见,则值为 null

left: number;

属性值

number

注解

API 集:ExcelApi 1.8

linkNumberFormat

指定数字格式是否链接到单元格 (,以便当数字格式在单元格) 中更改时,标签中的数字格式也会更改。

linkNumberFormat: boolean;

属性值

boolean

注解

API 集:ExcelApi 1.9

numberFormat

指定数据标签的格式代码。

numberFormat: string;

属性值

string

注解

API 集:ExcelApi 1.8

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"

注解

API 集:ExcelApi 1.7

separator

该字符串表示用于图表中数据标签的分隔符。

separator: string;

属性值

string

注解

API 集:ExcelApi 1.7

showAsStickyCallout

指定数据标签是否显示为标注,并将尾部定位点附加到数据点。 如果 ,标 true注是下列值之一:“AccentCallout1”、“AccentCallout2”、“BorderCallout1”、“BorderCallout2”、“WedgeRectCallout”、“WedgeRRectCallout”或“WedgeEllipseCallout”。 有关更多详细信息,请参阅 GeometricShapeType

readonly showAsStickyCallout: boolean;

属性值

boolean

注解

API 集:ExcelApi 1.19

showBubbleSize

指定数据标签气泡大小是否可见。

showBubbleSize: boolean;

属性值

boolean

注解

API 集:ExcelApi 1.7

showCategoryName

指定数据标签类别名称是否可见。

showCategoryName: boolean;

属性值

boolean

注解

API 集:ExcelApi 1.7

showLegendKey

指定数据标签图例键是否可见。

showLegendKey: boolean;

属性值

boolean

注解

API 集:ExcelApi 1.7

showPercentage

指定数据标签百分比是否可见。

showPercentage: boolean;

属性值

boolean

注解

API 集:ExcelApi 1.7

showSeriesName

指定数据标签系列名称是否可见。

showSeriesName: boolean;

属性值

boolean

注解

API 集:ExcelApi 1.7

showValue

指定数据标签值是否可见。

showValue: boolean;

属性值

boolean

注解

API 集:ExcelApi 1.7

text

该字符串表示图表上的数据标签文本。

text: string;

属性值

string

注解

API 集:ExcelApi 1.8

textOrientation

表示图表数据标签的文本朝向的角度。 该值应为 -90 到 90 之间的整数,对于垂直方向的文本,应为整数 180。

textOrientation: number;

属性值

number

注解

API 集:ExcelApi 1.8

top

表示图表数据标签上边缘到图表区域顶部的距离,以磅为单位。 如果图表数据标签不可见,则值为 null

top: number;

属性值

number

注解

API 集:ExcelApi 1.8

verticalAlignment

表示图表数据标签垂直对齐。 有关详细信息,请参阅 Excel.ChartTextVerticalAlignment。 仅当数据标签为 0 时, TextOrientation 此属性才有效。

verticalAlignment: Excel.ChartTextVerticalAlignment | "Center" | "Bottom" | "Top" | "Justify" | "Distributed";

属性值

Excel.ChartTextVerticalAlignment | "Center" | "Bottom" | "Top" | "Justify" | "Distributed"

注解

API 集:ExcelApi 1.8

width

返回图表数据标签的宽度,以磅为单位。 如果图表数据标签不可见,则值为 null

readonly width: number;

属性值

number

注解

API 集:ExcelApi 1.8

方法详细信息

getSubstring(start, length)

返回数据标签的子字符串。 换行符 '\n' 计为一个字符。

getSubstring(start: number, length?: number): Excel.ChartFormatString;

参数

start

number

子字符串在数据标签中从零开始的起始字符位置。

length

number

可选。 子字符串中的字符数。 如果省略长度,则检索从数据标签的开头到结尾的所有字符。

返回

注解

API 集:ExcelApi 1.19

getTailAnchor()

返回显示为粘性标注的数据标签的尾部定位点。

getTailAnchor(): Excel.ChartDataLabelAnchor;

返回

注解

API 集:ExcelApi 1.19

load(options)

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

load(options?: Excel.Interfaces.ChartDataLabelLoadOptions): Excel.ChartDataLabel;

参数

options
Excel.Interfaces.ChartDataLabelLoadOptions

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

返回

load(propertyNames)

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

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

参数

propertyNames

string | string[]

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

返回

load(propertyNamesAndPaths)

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

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

参数

propertyNamesAndPaths

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

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

返回

set(properties, options)

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

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

参数

properties
Excel.Interfaces.ChartDataLabelUpdateData

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

options
OfficeExtension.UpdateOptions

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

返回

void

set(properties)

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

set(properties: Excel.ChartDataLabel): void;

参数

返回

void

setHeight(height)

设置数据标签的高度(以磅为单位)。

setHeight(height: number): void;

参数

height

number

数据标签的高度(以磅为单位)。

返回

void

注解

API 集:ExcelApi 1.19

setWidth(width)

设置数据标签的宽度(以磅为单位)。

setWidth(width: number): void;

参数

width

number

数据标签的宽度(以磅为单位)。

返回

void

注解

API 集:ExcelApi 1.19

toJSON()

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

toJSON(): Excel.Interfaces.ChartDataLabelData;

返回