Edit

Share via


ExcelScript.ChartLegend interface

Represents the legend in a chart.

Remarks

Examples

/**
 * This sample configures the chart legend.
 * This assumes the active worksheet has a chart.
 */
function main(workbook: ExcelScript.Workbook) {
  // Get the first chart on the active worksheet.
  const sheet = workbook.getActiveWorksheet();
  const chart = sheet.getCharts()[0];
  
  // Configure the legend.
  const legend = chart.getLegend();
  legend.setPosition(ExcelScript.ChartLegendPosition.bottom);
  legend.setVisible(true);
}

Methods

getFormat()

Represents the formatting of a chart legend, which includes fill and font formatting.

getHeight()

Specifies the height, in points, of the legend on the chart. Value is null if the legend is not visible.

getLeft()

Specifies the left value, in points, of the legend on the chart. Value is null if the legend is not visible.

getLegendEntries()

Represents a collection of legendEntries in the legend.

getOverlay()

Specifies if the chart legend should overlap with the main body of the chart.

getPosition()

Specifies the position of the legend on the chart. See ExcelScript.ChartLegendPosition for details.

getShowShadow()

Specifies if the legend has a shadow on the chart.

getTop()

Specifies the top of a chart legend.

getVisible()

Specifies if the chart legend is visible.

getWidth()

Specifies the width, in points, of the legend on the chart. Value is null if the legend is not visible.

setHeight(height)

Specifies the height, in points, of the legend on the chart. Value is null if the legend is not visible.

setLeft(left)

Specifies the left value, in points, of the legend on the chart. Value is null if the legend is not visible.

setOverlay(overlay)

Specifies if the chart legend should overlap with the main body of the chart.

setPosition(position)

Specifies the position of the legend on the chart. See ExcelScript.ChartLegendPosition for details.

setShowShadow(showShadow)

Specifies if the legend has a shadow on the chart.

setTop(top)

Specifies the top of a chart legend.

setVisible(visible)

Specifies if the chart legend is visible.

setWidth(width)

Specifies the width, in points, of the legend on the chart. Value is null if the legend is not visible.

Method Details

getFormat()

Represents the formatting of a chart legend, which includes fill and font formatting.

getFormat(): ChartLegendFormat;

Returns

getHeight()

Specifies the height, in points, of the legend on the chart. Value is null if the legend is not visible.

getHeight(): number;

Returns

number

getLeft()

Specifies the left value, in points, of the legend on the chart. Value is null if the legend is not visible.

getLeft(): number;

Returns

number

getLegendEntries()

Represents a collection of legendEntries in the legend.

getLegendEntries(): ChartLegendEntry[];

Returns

getOverlay()

Specifies if the chart legend should overlap with the main body of the chart.

getOverlay(): boolean;

Returns

boolean

getPosition()

Specifies the position of the legend on the chart. See ExcelScript.ChartLegendPosition for details.

getPosition(): ChartLegendPosition;

Returns

getShowShadow()

Specifies if the legend has a shadow on the chart.

getShowShadow(): boolean;

Returns

boolean

getTop()

Specifies the top of a chart legend.

getTop(): number;

Returns

number

getVisible()

Specifies if the chart legend is visible.

getVisible(): boolean;

Returns

boolean

getWidth()

Specifies the width, in points, of the legend on the chart. Value is null if the legend is not visible.

getWidth(): number;

Returns

number

setHeight(height)

Specifies the height, in points, of the legend on the chart. Value is null if the legend is not visible.

setHeight(height: number): void;

Parameters

height

number

Returns

void

setLeft(left)

Specifies the left value, in points, of the legend on the chart. Value is null if the legend is not visible.

setLeft(left: number): void;

Parameters

left

number

Returns

void

setOverlay(overlay)

Specifies if the chart legend should overlap with the main body of the chart.

setOverlay(overlay: boolean): void;

Parameters

overlay

boolean

Returns

void

setPosition(position)

Specifies the position of the legend on the chart. See ExcelScript.ChartLegendPosition for details.

setPosition(position: ChartLegendPosition): void;

Parameters

Returns

void

Examples

/**
 * This sample sets the legend position on a chart.
 * This assumes the active worksheet has a chart.
 */
function main(workbook: ExcelScript.Workbook) {
  // Get the first chart on the active worksheet.
  const sheet = workbook.getActiveWorksheet();
  const chart = sheet.getCharts()[0];
  
  // Position the legend on the right side.
  chart.getLegend().setPosition(ExcelScript.ChartLegendPosition.right);
}

setShowShadow(showShadow)

Specifies if the legend has a shadow on the chart.

setShowShadow(showShadow: boolean): void;

Parameters

showShadow

boolean

Returns

void

setTop(top)

Specifies the top of a chart legend.

setTop(top: number): void;

Parameters

top

number

Returns

void

setVisible(visible)

Specifies if the chart legend is visible.

setVisible(visible: boolean): void;

Parameters

visible

boolean

Returns

void

Examples

/**
 * This sample hides the chart legend.
 * This assumes the active worksheet has a chart.
 */
function main(workbook: ExcelScript.Workbook) {
  // Get the first chart on the active worksheet.
  const sheet = workbook.getActiveWorksheet();
  const chart = sheet.getCharts()[0];
  
  // Hide the legend.
  chart.getLegend().setVisible(false);
}

setWidth(width)

Specifies the width, in points, of the legend on the chart. Value is null if the legend is not visible.

setWidth(width: number): void;

Parameters

width

number

Returns

void