Microsoft Office Tutorials and References
In Depth Information
21.2.3 An Example of Chart Creation
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
Search JabSto ::




Custom Search