Customizing Chart Elements > Programming ChartStyles > The ChartStyles Collection |
The ChartStyles collection contains the ChartStyle objects defined for each series. The following methods are defined for the ChartStyles collection:
Add(index) Add a new ChartStyle object to the collection
Remove(index) Remove a ChartStyle object from the collection
Normally, you will not need to add or remove ChartStyle objects from the collection yourself. If a ChartStyle object already exists when its corresponding series is created, the previously created ChartStyle object is used to display the data in this series.
By looping through the ChartStyles collection, you can quickly change the behavior of all of the bars, lines or points in a chart. For example, the following code lightens all of the bars in a chart whenever the mouse is clicked:
Private Sub Chart2D1_Click()
Dim Style As Object
For Each Style in Chart2D1.ChartGroups(1).Styles
Style.Fill.Color = Style.Fill.Color + &H50505
Next Style
End Sub
Note that this only works if the Color property is initially set to an RGB color value (if the most significant bit is set to 0).
Examples
The following statement sets the color of the first bar in a chart to green:
Chart2D1.ChartGroups(1).Styles(1).Fill.Color = RGB(0,128,0)
The following sets the line pattern for the second line in a plot to a dotted line:
Chart2D1.ChartGroups(1).Styles(2).Line.Pattern = oc2dLineDotted
And the following statement sets the symbol style for the third line in a plot to an unfilled circle:
Chart2D1.ChartGroups(1).Styles(3).Symbol.Shape = oc2dShapeCircle