Excel.Chart class
Represents a chart object in a workbook. To learn more about the chart object model, see Work with charts using the Excel JavaScript API.
- Extends
Remarks
[Api set: ExcelApi 1.1]
Properties
| axes | Represents chart axes. |
| category |
Specifies a chart category label level enumeration constant, referring to the level of the source category labels. |
| chart |
Specifies the type of the chart. See |
| context | The request context associated with the object. This connects the add-in's process to the Office host application's process. |
| data |
Represents the data labels on the chart. |
| display |
Specifies the way that blank cells are plotted on a chart. |
| format | Encapsulates the format properties for the chart area. |
| height | Specifies the height, in points, of the chart object. |
| id | The unique ID of chart. |
| left | The distance, in points, from the left side of the chart to the worksheet origin. |
| legend | Represents the legend for the chart. |
| name | Specifies the name of a chart object. |
| pivot |
Encapsulates the options for a pivot chart. |
| plot |
Represents the plot area for the chart. |
| plot |
Specifies the way columns or rows are used as data series on the chart. |
| plot |
True if only visible cells are plotted. False if both visible and hidden cells are plotted. |
| series | Represents either a single series or collection of series in the chart. |
| series |
Specifies a chart series name level enumeration constant, referring to the level of the source series names. |
| show |
Specifies whether to display all field buttons on a PivotChart. |
| show |
Specifies whether to show the data labels when the value is greater than the maximum value on the value axis. If the value axis becomes smaller than the size of the data points, you can use this property to set whether to show the data labels. This property applies to 2-D charts only. |
| style | Specifies the chart style for the chart. |
| title | Represents the title of the specified chart, including the text, visibility, position, and formatting of the title. |
| top | Specifies the distance, in points, from the top edge of the object to the top of row 1 (on a worksheet) or the top of the chart area (on a chart). |
| width | Specifies the width, in points, of the chart object. |
| worksheet | The worksheet containing the current chart. |
Methods
| activate() | Activates the chart in the Excel UI. |
| delete() | Deletes the chart object. |
| get |
Gets the data table on the chart. If the chart doesn't allow a data table, it will throw an exception. |
| get |
Gets the data table on the chart. If the chart doesn't allow a data table, then this method returns an object with its |
| get |
Renders the chart as a Base64-encoded image by scaling the chart to fit the specified dimensions. The aspect ratio is preserved as part of the resizing. |
| get |
Renders the chart as a Base64-encoded image by scaling the chart to fit the specified dimensions. The aspect ratio is preserved as part of the resizing. |
| load(options) | Queues up a command to load the specified properties of the object. You must call |
| load(property |
Queues up a command to load the specified properties of the object. You must call |
| load(property |
Queues up a command to load the specified properties of the object. You must call |
| 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. |
| set |
Resets the source data for the chart. |
| set |
Resets the source data for the chart. |
| set |
Positions the chart relative to cells on the worksheet. |
| toJSON() | Overrides the JavaScript |
Events
| on |
Occurs when the chart is activated. |
| on |
Occurs when the chart is deactivated. |
Property Details
axes
Represents chart axes.
readonly axes: Excel.ChartAxes;
Property Value
Remarks
[Api set: ExcelApi 1.1]
categoryLabelLevel
Specifies a chart category label level enumeration constant, referring to the level of the source category labels.
categoryLabelLevel: number;
Property Value
number
Remarks
[Api set: ExcelApi 1.8]
chartType
Specifies the type of the chart. See Excel.ChartType for details.
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";
Property Value
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"
Remarks
[Api set: ExcelApi 1.7]
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
dataLabels
Represents the data labels on the chart.
readonly dataLabels: Excel.ChartDataLabels;
Property Value
Remarks
[Api set: ExcelApi 1.1]
displayBlanksAs
Specifies the way that blank cells are plotted on a chart.
displayBlanksAs: Excel.ChartDisplayBlanksAs | "NotPlotted" | "Zero" | "Interplotted";
Property Value
Excel.ChartDisplayBlanksAs | "NotPlotted" | "Zero" | "Interplotted"
Remarks
[Api set: ExcelApi 1.8]
format
Encapsulates the format properties for the chart area.
readonly format: Excel.ChartAreaFormat;
Property Value
Remarks
[Api set: ExcelApi 1.1]
height
Specifies the height, in points, of the chart object.
height: number;
Property Value
number
Remarks
[Api set: ExcelApi 1.1]
id
The unique ID of chart.
readonly id: string;
Property Value
string
Remarks
[Api set: ExcelApi 1.7]
left
The distance, in points, from the left side of the chart to the worksheet origin.
left: number;
Property Value
number
Remarks
[Api set: ExcelApi 1.1]
legend
Represents the legend for the chart.
readonly legend: Excel.ChartLegend;
Property Value
Remarks
[Api set: ExcelApi 1.1]
name
Specifies the name of a chart object.
name: string;
Property Value
string
Remarks
[Api set: ExcelApi 1.1]
pivotOptions
Encapsulates the options for a pivot chart.
readonly pivotOptions: Excel.ChartPivotOptions;
Property Value
Remarks
[Api set: ExcelApi 1.9]
plotArea
Represents the plot area for the chart.
readonly plotArea: Excel.ChartPlotArea;
Property Value
Remarks
[Api set: ExcelApi 1.8]
plotBy
Specifies the way columns or rows are used as data series on the chart.
plotBy: Excel.ChartPlotBy | "Rows" | "Columns";
Property Value
Excel.ChartPlotBy | "Rows" | "Columns"
Remarks
[Api set: ExcelApi 1.8]
plotVisibleOnly
True if only visible cells are plotted. False if both visible and hidden cells are plotted.
plotVisibleOnly: boolean;
Property Value
boolean
Remarks
[Api set: ExcelApi 1.8]
series
Represents either a single series or collection of series in the chart.
readonly series: Excel.ChartSeriesCollection;
Property Value
Remarks
[Api set: ExcelApi 1.1]
seriesNameLevel
Specifies a chart series name level enumeration constant, referring to the level of the source series names.
seriesNameLevel: number;
Property Value
number
Remarks
[Api set: ExcelApi 1.8]
showAllFieldButtons
Specifies whether to display all field buttons on a PivotChart.
showAllFieldButtons: boolean;
Property Value
boolean
Remarks
[Api set: ExcelApi 1.7]
showDataLabelsOverMaximum
Specifies whether to show the data labels when the value is greater than the maximum value on the value axis. If the value axis becomes smaller than the size of the data points, you can use this property to set whether to show the data labels. This property applies to 2-D charts only.
showDataLabelsOverMaximum: boolean;
Property Value
boolean
Remarks
[Api set: ExcelApi 1.8]
style
Specifies the chart style for the chart.
style: number;
Property Value
number
Remarks
[Api set: ExcelApi 1.8]
title
Represents the title of the specified chart, including the text, visibility, position, and formatting of the title.
readonly title: Excel.ChartTitle;
Property Value
Remarks
[Api set: ExcelApi 1.1]
top
Specifies the distance, in points, from the top edge of the object to the top of row 1 (on a worksheet) or the top of the chart area (on a chart).
top: number;
Property Value
number
Remarks
[Api set: ExcelApi 1.1]
width
Specifies the width, in points, of the chart object.
width: number;
Property Value
number
Remarks
[Api set: ExcelApi 1.1]
worksheet
The worksheet containing the current chart.
readonly worksheet: Excel.Worksheet;
Property Value
Remarks
[Api set: ExcelApi 1.2]
Method Details
activate()
Activates the chart in the Excel UI.
activate(): void;
Returns
void
Remarks
[Api set: ExcelApi 1.9]
delete()
Deletes the chart object.
delete(): void;
Returns
void
Remarks
[Api set: ExcelApi 1.1]
getDataTable()
Gets the data table on the chart. If the chart doesn't allow a data table, it will throw an exception.
getDataTable(): Excel.ChartDataTable;
Returns
Remarks
[Api set: ExcelApi 1.14]
getDataTableOrNullObject()
Gets the data table on the chart. If the chart doesn't allow a data table, then this method returns an object with its isNullObject property set to true. For further information, see *OrNullObject methods and properties.
getDataTableOrNullObject(): Excel.ChartDataTable;
Returns
Remarks
[Api set: ExcelApi 1.14]
getImage(width, height, fittingMode)
Renders the chart as a Base64-encoded image by scaling the chart to fit the specified dimensions. The aspect ratio is preserved as part of the resizing.
getImage(width?: number, height?: number, fittingMode?: Excel.ImageFittingMode): OfficeExtension.ClientResult<string>;
Parameters
- width
-
number
Optional. The desired width of the resulting image.
- height
-
number
Optional. The desired height of the resulting image.
- fittingMode
- Excel.ImageFittingMode
Optional. The method used to scale the chart to the specified dimensions (if both height and width are set).
Returns
OfficeExtension.ClientResult<string>
Remarks
[Api set: ExcelApi 1.2]
getImage(width, height, fittingMode)
Renders the chart as a Base64-encoded image by scaling the chart to fit the specified dimensions. The aspect ratio is preserved as part of the resizing.
getImage(width?: number, height?: number, fittingMode?: "Fit" | "FitAndCenter" | "Fill"): OfficeExtension.ClientResult<string>;
Parameters
- width
-
number
Optional. The desired width of the resulting image.
- height
-
number
Optional. The desired height of the resulting image.
- fittingMode
-
"Fit" | "FitAndCenter" | "Fill"
Optional. The method used to scale the chart to the specified dimensions (if both height and width are set).
Returns
OfficeExtension.ClientResult<string>
Remarks
[Api set: ExcelApi 1.2]
load(options)
Queues up a command to load the specified properties of the object. You must call context.sync() before reading the properties.
load(options?: Excel.Interfaces.ChartLoadOptions): Excel.Chart;
Parameters
Provides options for which properties of the object to load.
Returns
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.Chart;
Parameters
- propertyNames
-
string | string[]
A comma-delimited string or an array of strings that specify the properties to load.
Returns
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.Chart;
Parameters
- propertyNamesAndPaths
-
{ select?: string; expand?: string; }
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.ChartUpdateData, options?: OfficeExtension.UpdateOptions): void;
Parameters
- properties
- Excel.Interfaces.ChartUpdateData
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
set(properties)
Sets multiple properties on the object at the same time, based on an existing loaded object.
set(properties: Excel.Chart): void;
Parameters
- properties
- Excel.Chart
Returns
void
setData(sourceData, seriesBy)
Resets the source data for the chart.
setData(sourceData: Range, seriesBy?: Excel.ChartSeriesBy): void;
Parameters
- sourceData
- Excel.Range
The range object corresponding to the source data.
- seriesBy
- Excel.ChartSeriesBy
Specifies the way columns or rows are used as data series on the chart. Can be one of the following: Auto (default), Rows, and Columns. See Excel.ChartSeriesBy for details.
Returns
void
Remarks
[Api set: ExcelApi 1.1]
setData(sourceData, seriesBy)
Resets the source data for the chart.
setData(sourceData: Range, seriesBy?: "Auto" | "Columns" | "Rows"): void;
Parameters
- sourceData
- Excel.Range
The range object corresponding to the source data.
- seriesBy
-
"Auto" | "Columns" | "Rows"
Specifies the way columns or rows are used as data series on the chart. Can be one of the following: Auto (default), Rows, and Columns. See Excel.ChartSeriesBy for details.
Returns
void
Remarks
[Api set: ExcelApi 1.1]
setPosition(startCell, endCell)
Positions the chart relative to cells on the worksheet.
setPosition(startCell: Range | string, endCell?: Range | string): void;
Parameters
- startCell
-
Excel.Range | string
The start cell. This is where the chart will be moved to. The start cell is the top-left or top-right cell, depending on the user's right-to-left display settings.
- endCell
-
Excel.Range | string
Optional. The end cell. If specified, the chart's width and height will be set to fully cover up this cell/range.
Returns
void
Remarks
[Api set: ExcelApi 1.1]
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's passed to it.) Whereas the original Excel.Chart object is an API object, the toJSON method returns a plain JavaScript object (typed as Excel.Interfaces.ChartData) that contains shallow copies of any loaded child properties from the original object.
toJSON(): Excel.Interfaces.ChartData;
Returns
Event Details
onActivated
Occurs when the chart is activated.
readonly onActivated: OfficeExtension.EventHandlers<Excel.ChartActivatedEventArgs>;
Event Type
Remarks
[Api set: ExcelApi 1.8]
onDeactivated
Occurs when the chart is deactivated.
readonly onDeactivated: OfficeExtension.EventHandlers<Excel.ChartDeactivatedEventArgs>;
Event Type
Remarks
[Api set: ExcelApi 1.8]