Private Sub ChartSpace_AfterRender(ByVal drawObject As ChChartDraw, ByVal chartObject As Object)
drawObject A ChChartDraw object. Use the methods and properties of this object to manipulate drawing objects on the chart.
chartObject The object that has just been rendered. Use the TypeName function to determine what type of object has just been rendered.
Remarks
You must set the AllowRenderEvents and AllowPointsRenderEvents properties to True in order to use this event with all chart objects.
Example
This example adds a text string to the upper-left corner of the plot area each time that the chart is redrawn.
Sub ChartSpace1_AfterRender(drawObject, chartObject)
Dim chChart1
Set chChart1 = ChartSpace1.Charts(0)
' After the legend has been rendered, then add the text
' to the chart.
If TypeName(chartObject) = "ChLegend" Then
drawObject.DrawText "2000 Sales", chChart1.PlotArea.Left + 5, _
chChart1.PlotArea.Top
End If
End Sub
This example illustrates how you can use the BeforeRender and AfterRender events together to create custom gridlines. The BeforeRender event cancels the rendering of the gridlines and the AfterRender event draws custom gridlines.
Sub ChartSpace1_BeforeRender(drawObject, chartObject, Cancel)
' Check to see if the next object to be rendered
' is a gridline.
If TypeName(chartObject) = "ChGridlines" Then
' Cancel the rendering of gridlines.
Cancel.Value = True
End If
End Sub
Sub ChartSpace1_AfterRender(drawObject, chartObject)
Dim chChart1
Dim plPlotArea
Dim lLeft
Dim lRight
Dim lHeight
Dim lTop
Dim lIncrement
Dim chConstants
Dim iCtr
Set chConstants = ChartSpace1.Constants
' Set a variable to the first chart in Chartspace1.
Set chChart1 = ChartSpace1.Charts(0)
' Set a variable to the plot area of the chart.
Set plPlotArea = chChart1.PlotArea
' Check to see if the rendered object is a gridline.
If TypeName(chartObject) = "ChGridlines" Then
' The next four lines of code use the extents of
' the plot area to calculate the dimensions of the line
' to be drawn.
lLeft = plPlotArea.Left
lTop = plPlotArea.Top
lRight = plPlotArea.Right
lHeight = plPlotArea.Bottom - lTop
' Determine the increment to use between gridlines.
' Change the divisor to adjust the increment.
lIncrement = lHeight / 10
' The next three lines of code set the properties of the
' line to be drawn.
drawObject.Line.DashStyle = chConstants.chLineRoundDot
drawObject.Line.Color = "Green"
drawObject.Line.Weight = chConstants.owcLineWeightMedium
For iCtr = 1 To 9
' Draw the line.
drawObject.DrawLine lLeft, lTop + iCtr * lIncrement, _
lRight, lTop + iCtr * lIncrement
Next
End If
End Sub