Tải bản đầy đủ - 0 (trang)
Figure 21-5. The results of CreateChart

Figure 21-5. The results of CreateChart

Tải bản đầy đủ - 0trang

Dim co As ChartObject

Dim cw As Long, rh As Long

' Get data for positioning chart

cw = Columns(1).Width

rh = Rows(1).Height

' Position chart using column width and row height units

Set co = ActiveSheet.ChartObjects.Add(cw * 3, rh * 0.5, cw * 8, rh

* 20)

' Name it

co.Name = "ChartExample"

' Set chart type

co.Chart.ChartType = xlLine

' Add data series

co.Chart.SeriesCollection.Add _

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

Rowcol:=xlColumns, SeriesLabels:=True, _

Categorylabels:=True

' Add axes

' (This is actually the default setting,

'

but is added here for illustration)

With co.Chart

.HasAxis(xlCategory, xlPrimary) = True

.HasAxis(xlCategory, xlSecondary) = False

.HasAxis(xlValue, xlPrimary) = True

.HasAxis(xlValue, xlSecondary) = False

End With

' Axis title formatting

With co.Chart.Axes(xlCategory)

.HasTitle = True

.AxisTitle.Caption = "Types"

.AxisTitle.Border.Weight = xlMedium

End With

With co.Chart.Axes(xlValue)

.HasTitle = True

With .AxisTitle

.Caption = "Quantity for 1999"

.Font.Size = 6

.Orientation = xlHorizontal

.Characters(14, 4).Font.Italic = True

.Border.Weight = xlMedium

End With

End With

' Change the category names (Types) to lower case

' (On the worksheet they are in upper case)

co.Chart.Axes(xlCategory).CategoryNames = _

Array("a", "b", "c", "d", "e")

' Set the crossing point on the (primary) value axis at 50

co.Chart.Axes(xlValue).CrossesAt = 50

' Horizontal but no vertical gridlines



354



co.Chart.Axes(xlValue).HasMajorGridlines = True

co.Chart.Axes(xlCategory).HasMajorGridlines = False

' Outside Tickmarks on category axis

co.Chart.Axes(xlCategory).MajorTickMark = xlTickMarkCross

' Move tick labels to below chart area

co.Chart.Axes(xlCategory).TickLabelPosition = _

xlTickLabelPositionNextToAxis

' Set chart area fill to solid white

co.Chart.ChartArea.Interior.Color = RGB(255, 255, 255)

' Set plot area fill to gray

co.Chart.PlotArea.Interior.ColorIndex = 15

' Format chart title

With co.Chart.ChartTitle

.Caption = "Great Chart"

.Font.Size = 14

.Font.Bold = True

.Border.Weight = xlThick

End With

End Sub



21.2.4 Z-Order and ChartObject Objects

Before looking at the main properties, methods, and children of the Chart object, we can get one

simple, but important, item out of the way.

Namely, it is possible for two or more embedded charts to overlap, which raises the question of

how to control which chart object appears on the top. Every ChartObject object has an order,

called its z-order, that indicates the object's relative position with respect to an imaginary z-axis

that comes directly out of the monitor at right angles, towards the user, as pictured in Figure 21-6.

Figure 21-6. Illustrating z-order



The ChartObject object has a read-only ZOrder property that is used to return the z-order of the

ChartObject. It also has BringToFront and SendToBack methods for changing the z-order. These

properties can be used to shuffle the order of ChartObject objects.



355



21.3 Chart Types

Each Excel chart has either a standard chart type or a custom chart type. In addition, there are two

types of custom chart types: built-in and user-defined. All chart types are accessible by the user

through the Chart Type dialog box shown in Figure 21-7 (right-click a chart and choose Chart

Type).

Figure 21-7. The Chart Type dialog



21.3.1 ChartType property

The ChartType property is a read-write property that can be set to any one of the XlChartType

constants in Table 21-1.



Type

Area



Bar



Table 21-1. ChartType Constants

Description

Constant(Value)

3D Area

xl3DArea(-4098)

3D Stacked Area

xl3DAreaStacked(78)

3D 100% Stacked Area

xl3DAreaStacked100(79)

Area

xlArea(1)

Stacked Area

xlAreaStacked(76)

100% Stacked Area

xlAreaStacked100(77)

3D Clustered Bar

xl3DBarClustered(60)

3D Stacked Bar

xl3DBarStacked(61)

3D 100% Stacked Bar

xl3DBarStacked100(62)

Clustered Bar

xlBarClustered(57)



356



Cone



Cylinder



Doughnut

Line



Pie



Pyramid



xlBarStacked(58)

xlBarStacked100(59)

xlBubble(15)

xlBubble3DEffect(87)

xl3DColumn(-4100)

xl3DColumnClustered(54)

xl3DColumnStacked(55)

xl3DColumnStacked100(56)

xlColumnClustered(51)

xlColumnStacked(52)

xlColumnStacked100(53)

xlConeBarClustered(102)

xlConeBarStacked(103)

xlConeBarStacked100(104)

xlConeCol(105)

xlConeColClustered(99)

xlConeColStacked(100)

xlConeColStacked100(101)

xlCylinderBarClustered(95)

xlCylinderBarStacked(96)

xlCylinderBarStacked100(97)

xlCylinderCol(98)

xlCylinderColClustered(92)

xlCylinderColStacked(93)

xlCylinderColStacked100(94)

xlDoughnut(-4120)

xlDoughnutExploded(80)

xl3DLine(-4101)

xlLine(4)

xlLineMarkers(65)

xlLineMarkersStacked(66)

xlLineMarkersStacked100(67)

xlLineStacked(63)

xlLineStacked100(64)

xl3DPie(-4102)

xl3DPieExploded(70)

xlBarOfPie(71)

xlPie(5)

xlPieExploded(69)

xlPieOfPie(68)

xlPyramidBarClustered(109)

xlPyramidBarStacked(110)

xlPyramidBarStacked100(111)

xlPyramidCol(112)

xlPyramidColClustered(106)

xlPyramidColStacked(107)



AM

FL

Y



Column



TE



Bubble



Stacked Bar

100% Stacked Bar

Bubble

Bubble with 3D effects

3D Column

3D Clustered Column

3D Stacked Column

3D 100% Stacked Column

Clustered Column

Stacked Column

100% Stacked Column

Clustered Cone Bar

Stacked Cone Bar

100% Stacked Cone Bar

3D Cone Column

Clustered Cone Column

Stacked Cone Column

100% Stacked Cone Column

Clustered Cylinder Bar

Stacked Cylinder Bar

100% Stacked Cylinder Bar

3D Cylinder Column

Clustered Cylinder Column

Stacked Cylinder Column

100% Stacked Cylinder Column

Doughnut

Exploded Doughnut

3D Line

Line

Line with Markers

Stacked Line with Markers

100% Stacked Line with Markers

Stacked Line

100% Stacked Line

3D Pie

Exploded 3D Pie

Bar of Pie

Pie

Exploded Pie

Pie of Pie

Clustered Pyramid Bar

Stacked Pyramid Bar

100% Stacked Pyramid Bar

3D Pyramid Column

Clustered Pyramid Column

Stacked Pyramid Column



357 ®

Team-Fly



Tài liệu bạn tìm kiếm đã sẵn sàng tải về

Figure 21-5. The results of CreateChart

Tải bản đầy đủ ngay(0 tr)

×