Excel.ChartDataLabels class

Represents a collection of all the data labels on a chart point.

[ API set: ExcelApi 1.1 ]

Extends
OfficeExtension.ClientObject

Properties

autoText

Represents whether data labels automatically generate appropriate text based on context.

[ API set: ExcelApi 1.8 ]

context

The request context associated with the object. This connects the add-in's process to the Office host application's process.

format

Represents the format of chart data labels, which includes fill and font formatting. Read-only.

[ API set: ExcelApi 1.1 ]

horizontalAlignment

Represents the horizontal alignment for chart data label. See Excel.ChartTextHorizontalAlignment for details. This property is valid only when TextOrientation of data label is 0.

[ API set: ExcelApi 1.8 ]

linkNumberFormat

Represents whether or not the number format is linked to the cells. If true, the number format will change in the labels when it changes in the cells

[ API set: ExcelApi 1.9 ]

numberFormat

Represents the format code for data labels.

[ API set: ExcelApi 1.8 ]

position

DataLabelPosition value that represents the position of the data label. See Excel.ChartDataLabelPosition for details.

[ API set: ExcelApi 1.1 ]

separator

String representing the separator used for the data labels on a chart.

[ API set: ExcelApi 1.1 ]

showBubbleSize

Boolean value representing if the data label bubble size is visible or not.

[ API set: ExcelApi 1.1 ]

showCategoryName

Boolean value representing if the data label category name is visible or not.

[ API set: ExcelApi 1.1 ]

showLegendKey

Boolean value representing if the data label legend key is visible or not.

[ API set: ExcelApi 1.1 ]

showPercentage

Boolean value representing if the data label percentage is visible or not.

[ API set: ExcelApi 1.1 ]

showSeriesName

Boolean value representing if the data label series name is visible or not.

[ API set: ExcelApi 1.1 ]

showValue

Boolean value representing if the data label value is visible or not.

[ API set: ExcelApi 1.1 ]

textOrientation

Represents the text orientation of data labels. The value should be an integer either from -90 to 90, or 180 for vertically-oriented text.

[ API set: ExcelApi 1.8 ]

verticalAlignment

Represents the vertical alignment of chart data label. See Excel.ChartTextVerticalAlignment for details. This property is valid only when TextOrientation of data label is 90, -90 or 180.

[ API set: ExcelApi 1.8 ]

Methods

load(option)

Queues up a command to load the specified properties of the object. You must call "context.sync()" before reading the properties.

load(propertyNames)

Queues up a command to load the specified properties of the object. You must call context.sync() before reading the properties.

load(propertyNamesAndPaths)

Queues up a command to load the specified properties of the object. You must call context.sync() before reading the properties.

set(properties, options)

Sets multiple properties of an object at the same time. You can pass either a plain object with the appropriate properties, or another API object of the same type.

set(properties)

Sets multiple properties on the object at the same time, based on an existing loaded object.

toJSON()

Overrides the JavaScript toJSON() method in order to provide more useful output when an API object is passed to JSON.stringify(). (JSON.stringify, in turn, calls the toJSON method of the object that is passed to it.) Whereas the original Excel.ChartDataLabels object is an API object, the toJSON method returns a plain JavaScript object (typed as Excel.Interfaces.ChartDataLabelsData) that contains shallow copies of any loaded child properties from the original object.

Property Details

autoText

Represents whether data labels automatically generate appropriate text based on context.

[ API set: ExcelApi 1.8 ]

autoText: boolean;

Property Value

boolean

context

The request context associated with the object. This connects the add-in's process to the Office host application's process.

context: RequestContext;

Property Value

format

Represents the format of chart data labels, which includes fill and font formatting. Read-only.

[ API set: ExcelApi 1.1 ]

readonly format: Excel.ChartDataLabelFormat;

Property Value

horizontalAlignment

Represents the horizontal alignment for chart data label. See Excel.ChartTextHorizontalAlignment for details. This property is valid only when TextOrientation of data label is 0.

[ API set: ExcelApi 1.8 ]

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

Property Value

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

linkNumberFormat

Represents whether or not the number format is linked to the cells. If true, the number format will change in the labels when it changes in the cells

[ API set: ExcelApi 1.9 ]

linkNumberFormat: boolean;

Property Value

boolean

numberFormat

Represents the format code for data labels.

[ API set: ExcelApi 1.8 ]

numberFormat: string;

Property Value

string

position

DataLabelPosition value that represents the position of the data label. See Excel.ChartDataLabelPosition for details.

[ API set: ExcelApi 1.1 ]

position: Excel.ChartDataLabelPosition | "Invalid" | "None" | "Center" | "InsideEnd" | "InsideBase" | "OutsideEnd" | "Left" | "Right" | "Top" | "Bottom" | "BestFit" | "Callout";

Property Value

Excel.ChartDataLabelPosition | "Invalid" | "None" | "Center" | "InsideEnd" | "InsideBase" | "OutsideEnd" | "Left" | "Right" | "Top" | "Bottom" | "BestFit" | "Callout"

separator

String representing the separator used for the data labels on a chart.

[ API set: ExcelApi 1.1 ]

separator: string;

Property Value

string

showBubbleSize

Boolean value representing if the data label bubble size is visible or not.

[ API set: ExcelApi 1.1 ]

showBubbleSize: boolean;

Property Value

boolean

showCategoryName

Boolean value representing if the data label category name is visible or not.

[ API set: ExcelApi 1.1 ]

showCategoryName: boolean;

Property Value

boolean

showLegendKey

Boolean value representing if the data label legend key is visible or not.

[ API set: ExcelApi 1.1 ]

showLegendKey: boolean;

Property Value

boolean

showPercentage

Boolean value representing if the data label percentage is visible or not.

[ API set: ExcelApi 1.1 ]

showPercentage: boolean;

Property Value

boolean

showSeriesName

Boolean value representing if the data label series name is visible or not.

[ API set: ExcelApi 1.1 ]

showSeriesName: boolean;

Property Value

boolean

showValue

Boolean value representing if the data label value is visible or not.

[ API set: ExcelApi 1.1 ]

showValue: boolean;

Property Value

boolean

textOrientation

Represents the text orientation of data labels. The value should be an integer either from -90 to 90, or 180 for vertically-oriented text.

[ API set: ExcelApi 1.8 ]

textOrientation: number;

Property Value

number

verticalAlignment

Represents the vertical alignment of chart data label. See Excel.ChartTextVerticalAlignment for details. This property is valid only when TextOrientation of data label is 90, -90 or 180.

[ API set: ExcelApi 1.8 ]

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

Property Value

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

Method Details

load(option)

Queues up a command to load the specified properties of the object. You must call "context.sync()" before reading the properties.

load(option?: Excel.Interfaces.ChartDataLabelsLoadOptions): Excel.ChartDataLabels;

Parameters

Returns

Remarks

In addition to this signature, this method has the following signatures:

load(option?: string | string[]): Excel.ChartDataLabels - Where option is a comma-delimited string or an array of strings that specify the properties to load.

load(option?: { select?: string; expand?: string; }): Excel.ChartDataLabels - Where option.select is a comma-delimited string that specifies the properties to load, and options.expand is a comma-delimited string that specifies the navigation properties to load.

load(option?: { select?: string; expand?: string; top?: number; skip?: number }): Excel.ChartDataLabels - Only available on collection types. It is similar to the preceding signature. Option.top specifies the maximum number of collection items that can be included in the result. Option.skip specifies the number of items that are to be skipped and not included in the result. If option.top is specified, the result set will start after skipping the specified number of items.

load(propertyNames)

Queues up a command to load the specified properties of the object. You must call context.sync() before reading the properties.

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

Parameters

propertyNames
string | string[]

A comma-delimited string or an array of strings that specify the properties to load.

Returns

Examples

// Make Series Name shown in Datalabels and set the position of datalabels to be "top";
Excel.run(function (ctx) { 
    var chart = ctx.workbook.worksheets.getItem("Sheet1").charts.getItem("Chart1");    
    chart.datalabels.showValue = true;
    chart.datalabels.position = "top";
    chart.datalabels.showSeriesName = true;
    return ctx.sync().then(function() {
            console.log("Datalabels Shown");
    });
}).catch(function(error) {
    console.log("Error: " + error);
    if (error instanceof OfficeExtension.Error) {
        console.log("Debug info: " + JSON.stringify(error.debugInfo));
    }
});

load(propertyNamesAndPaths)

Queues up a command to load the specified properties of the object. You must call context.sync() before reading the properties.

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

Parameters

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

Where propertyNamesAndPaths.select is a comma-delimited string that specifies the properties to load, and propertyNamesAndPaths.expand is a comma-delimited string that specifies the navigation properties to load.

Returns

set(properties, options)

Sets multiple properties of an object at the same time. You can pass either a plain object with the appropriate properties, or another API object of the same type.

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

Parameters

properties
Interfaces.ChartDataLabelsUpdateData

A JavaScript object with properties that are structured isomorphically to the properties of the object on which the method is called.

options
OfficeExtension.UpdateOptions

Provides an option to suppress errors if the properties object tries to set any read-only properties.

Returns

void

Remarks

This method has the following additional signature:

set(properties: Excel.ChartDataLabels): void

set(properties)

Sets multiple properties on the object at the same time, based on an existing loaded object.

set(properties: Excel.ChartDataLabels): void;

Parameters

Returns

void

toJSON()

Overrides the JavaScript toJSON() method in order to provide more useful output when an API object is passed to JSON.stringify(). (JSON.stringify, in turn, calls the toJSON method of the object that is passed to it.) Whereas the original Excel.ChartDataLabels object is an API object, the toJSON method returns a plain JavaScript object (typed as Excel.Interfaces.ChartDataLabelsData) that contains shallow copies of any loaded child properties from the original object.

toJSON(): Excel.Interfaces.ChartDataLabelsData;

Returns