1. Trang chủ >
  2. Công Nghệ Thông Tin >
  3. Quản trị mạng >

Figure 21-9. Children of the Chart object

Bạn đang xem bản rút gọn của tài liệu. Xem và tải ngay bản đầy đủ của tài liệu tại đây (5.72 MB, 490 trang )


The Chart object has an Axes collection that contains an Axis object for each axis in the chart. The

Axes method returns either a single axis or the Axes collection for a chart. To return the Axes

collection for a chart, use the syntax:



ChartObject.Axes

To return a specific Axis object, use the syntax:



ChartObject.Axes(Type, AxisGroup)

Here the optional Type parameter specifies the axis to return. It can be one of the following

XlAxisType constants:

Enum XlAxisType

xlCategory = 1

xlValue = 2

xlSeriesAxis = 3

End Enum



Note that xlSeriesAxis is valid only for 3-D charts.

The optional AxisGroup parameter specifies the axis group. It can be one of the following

XlAxisGroup constants:

Enum XlAxisGroup

xlPrimary = 1

xlSecondary = 2

End Enum



' The default



A secondary axis is a second vertical or horizontal axis upon which a second value series (vertical

case) or category series (horizontal case) is plotted (see Figure 21-1). If this argument is omitted,

the primary group is used. Note that 3-D charts have only one axis group.



361



The Chart object has a read-write property named HasAxis that determines whether or not the

chart displays various types of axes. However, it is important to note that this method will fail if

the chart does not yet have the corresponding data series. For instance, if you are creating a chart

from scratch, it might be natural to add the code to create a category axis before adding the

category data that will be plotted against that axis. This not to do (to quote Hamlet)!

In fact, referring to the CreateChart example procedure earlier in the chapter, if we reverse the

data series code and the axes-related code, changing this:

' Add data series using data on the sheet itself

co.Chart.SeriesCollection.Add _

Source:=ActiveSheet.Range("A1:B6"), _

Rowcol:=xlColumns, SeriesLabels:=True, _

Categorylabels:=True

' Add axes

With co.Chart

.HasAxis(xlCategory, xlPrimary) = True

.HasAxis(xlCategory, xlSecondary) = False

.HasAxis(xlValue, xlPrimary) = True

.HasAxis(xlValue, xlSecondary) = False

End With



to this:

' Add axes

With co.Chart

.HasAxis(xlCategory, xlPrimary) = True

.HasAxis(xlCategory, xlSecondary) = False

.HasAxis(xlValue, xlPrimary) = True

.HasAxis(xlValue, xlSecondary) = False

End With

' Add data series using data on the sheet itself

co.Chart.SeriesCollection.Add _

Source:=ActiveSheet.Range("A1:B6"), _

Rowcol:=xlColumns, SeriesLabels:=True, _

Categorylabels:=True



Excel will issue the completely useless error message: "Method 'HasAxis' of object '_Chart' has

failed." (Unfortunately, as is all too often the case, the documentation does not discuss this issue at

all.)

The syntax for the HasAxis property is:



ChartObject.HasAxis(Index1, Index2)

where the parameters, despite their generic names, correspond directly to the Type and

AxisGroup parameters of the Axes method. For instance, the following code displays a primary

category axis and both primary and secondary value axes for the active chart:

With ActiveChart

.HasAxis(xlCategory, xlPrimary) = True

.HasAxis(xlCategory, xlSecondary) = False

.HasAxis(xlValue, xlPrimary) = True

.HasAxis(xlValue, xlSecondary) = True

End With



362



21.6 The Axis Object

Table 21-2 shows the properties and methods of the Axis object. As you can see, Axis objects are

fairly involved in their own right. Fortunately, most of the members in Table 21-2 are selfexplanatory, so we consider them only briefly. Note that most of these members correspond to the

myriad check boxes and edit boxes in the five tabs of the Excel Format Axis dialog box.

Table 21-2. Members of the Axis Object

Application

HasDisplayUnitLabel

MinorTickMark

AxisBetweenCategories

HasMajorGridlines

MinorUnit

AxisGroup

HasMinorGridlines

MinorUnitIsAuto

AxisTitle

HasTitle

MinorUnitScale

BaseUnit

Height

Parent

BaseUnitIsAuto

Left

ReversePlotOrder

Border

MajorGridlines

ScaleType

CategoryNames

MajorTickMark

Select

CategoryType

MajorUnit

TickLabelPosition

Creator

MajorUnitIsAuto

TickLabels

Crosses

MajorUnitScale

TickLabelSpacing

CrossesAt

MaximumScale

TickMarkSpacing

Delete

MaximumScaleIsAuto

Top

DisplayUnit

MinimumScale

Type

DisplayUnitCustom

MinimumScaleIsAuto

Width

DisplayUnitLabel

MinorGridlines



21.6.1 AxisGroup Property

This read-only property returns the group for the specified axis. It can be either xlPrimary (=1)

or xlSecondary (=2).



21.6.2 Axis Titles and Their Formatting

The AxisTitle property returns an AxisTitle object that represents the title of the specified axis.

21.6.2.1 HasTitle property (R/W Boolean)

Before we can format an axis title, we must tell Excel that the axis has a title using the HasTitle

property:

AxisObject.HasTitle = True



The AxisTitle object has several properties, the most prominent of which are the following:

AutoScaleFont

Scales the label text font size is automatically when the chart size changes when this

property is True. The default value is True.



363



Border

Returns a Border object that can be used to set the color, line style, and width of the

border of the axis title.

Caption

Sets the text for the title.

Characters

Returns a Characters object, which is a range of characters in the caption. This allows us

to format a portion of the text in the caption.

Fill

Returns a ChartFillFormat object used to set fill-formatting properties for the axis title.

Font

Returns a Font object that can be used to set the font characteristics of the labels.

HorizontalAlignment and VerticalAlignment

Sets the alignment of axis title text.

Interior

Returns an Interior object that can be used to format the interior of the axis title area.

NumberFormat

Sets the number format code for the labels. This property returns Null if all labels do not

have the same number format. Note that since the format codes are the same as those used

by Excel to format worksheet cells, we can use the macro recorder to get appropriate

format codes.

Orientation

Returns or sets the orientation for the axis title. It can be any one of the following

constants:

Enum XlOrientation

xlUpward = -4171

xlDownward = -4170

xlVertical = -4166

xlHorizontal = -4128

End Enum



Let us take a closer look at the Characters object. A Characters object represents a contiguous

portion of text within a text string. The Characters property returns a Characters object. (Note that

the Characters property also applies to the ChartTitle object and the Range object.)

The syntax of the Characters property is:



364



Xem Thêm
Tải bản đầy đủ (.pdf) (490 trang)

×