Chart Object

Description

Represents a chart in a workbook, either an embedded chart (contained in a ChartObject in a Worksheet or DialogSheet object) or a separate chart sheet.

Embedded Charts

The ChartObject, which represents the container for an embedded chart on a worksheet or dialog sheet, is a member of the ChartObjects collection. Use the Add method to create a new empty embedded chart and add it to the collection. Use the Chart property to access the chart contained in the specified ChartObject object. The following example sets the pattern for the chart area in embedded chart one on the worksheet named "Sheet1."


Worksheets("sheet1").ChartObjects(1).Chart. _
    ChartArea.Interior.Pattern = xlLightDown

Chart Sheets

The Chart object, which represents a separate chart sheet, is a member of the Charts collection. The Charts collection contains all the Chart objects that represent chart sheets in a workbook. Use the Add method to create a new chart sheet and add it to the collection. To access a single member of the collection, use the Charts method with the index number or name of the chart sheet as an argument.

The chart index number represents the position of the chart sheet on the tab bar of the workbook. Charts(1) is the first (leftmost) chart in the workbook; Charts(Charts.Count) is the last. All chart sheets are included in the index count, even if they are hidden.

The following example changes the color of series one on chart sheet one.


Charts(1).SeriesCollection(1).Interior.Color = RGB(255, 0, 0)

The chart name is shown on the workbook tab for the chart. You can use the Name property to set or return the chart name.

The following example moves the chart named "Sales" to the end of the active workbook.


Charts("sales").Move after:=Sheets(Sheets.Count)

The Chart object is also a member of the Sheets collection. The Sheets collection contains all of the sheets in the workbook (chart sheets, dialog sheets, modules, and worksheets). To access a single member of the collection, use the Sheets method with the index number or name of the sheet as an argument.

Using ActiveChart

When a chart is the active object, you can use the ActiveChart property to refer to it. A chart sheet is active if the user has selected it or it has been activated with the Activate method. The following example activates chart sheet one and then sets the chart type and title.


Charts(1).Activate
With ActiveChart
    .Type = xlLine
    .HasTitle = True
    .ChartTitle.Text = "January Sales"
End With

An embedded chart is active if the user has selected it or the ChartObject object that contains it has been activated with the Activate method. The following example activates embedded chart one on worksheet one and then sets the chart type and title. Notice that once the embedded chart has been activated, the code in this example is the same as the previous example. Using the ActiveChart property allows you to write Visual Basic code that can refer to either an embedded chart or a chart sheet, whichever is active.


Worksheets(1).ChartObjects(1).Activate
ActiveChart.Type = xlLine
ActiveChart.HasTitle = True
ActiveChart.ChartTitle.Text = "January Sales"

Using ActiveSheet

When a chart sheet is the active sheet, you can use the ActiveSheet property to refer to it. The following example uses the Activate method to activate the chart sheet named "Chart1" and then sets the interior color for series one in the chart.


Charts("chart1").Activate
ActiveSheet.SeriesCollection(1).Interior.ColorIndex = 5

Properties

Application Property, Area3DGroup Property, AutoScaling Property, Bar3DGroup Property, ChartArea Property, ChartTitle Property, Column3DGroup Property, Corners Property, Creator Property, DepthPercent Property, DisplayBlanksAs Property, Elevation Property, Floor Property, GapDepth Property, HasAxis Property, HasLegend Property, HasTitle Property, HeightPercent Property, Index Property, Legend Property, Line3DGroup Property, Name Property, Next Property, OnDoubleClick Property, OnSheetActivate Property, OnSheetDeactivate Property, PageSetup Property, Parent Property, Perspective Property, Pie3DGroup Property, PlotArea Property, PlotVisibleOnly Property, Previous Property, ProtectContents Property, ProtectDrawingObjects Property, RightAngleAxes Property, Rotation Property, SizeWithWindow Property, SubType Property, SurfaceGroup Property, Type Property, Visible Property, Walls Property, WallsAndGridlines2D Property.

Methods

Activate Method, ApplyDataLabels Method, Arcs Method, AreaGroups Method, AutoFormat Method (Chart Object), Axes Method, BarGroups Method, Buttons Method, ChartGroups Method, ChartObjects Method, ChartWizard Method, CheckBoxes Method, CheckSpelling Method, ColumnGroups Method, Copy Method, CopyPicture Method, CreatePublisher Method, Delete Method, Deselect Method, DoughnutGroups Method, DrawingObjects Method, Drawings Method, DropDowns Method, Evaluate Method, GroupBoxes Method, GroupObjects Method, Labels Method, LineGroups Method, Lines Method, ListBoxes Method, Move Method, OLEObjects Method, OptionButtons Method, Ovals Method, Paste Method (Chart Object), Pictures Method, PieGroups Method, PrintOut Method, PrintPreview Method, Protect Method, RadarGroups Method, Rectangles Method, SaveAs Method, ScrollBars Method, Select Method, SeriesCollection Method, SetBackgroundPicture Method, Spinners Method, TextBoxes Method, Unprotect Method, XYGroups Method.