This documentation is archived and is not being maintained.

BeforeRender Event

Office 2003

Occurs before the object passed in the chartObject argument has been rendered.

Private Sub Object_BeforeRender(ByVal drawObject As ChChartDraw, ByVal chartObject As Object, Cancel As ByRef)

Object The name of the ChartSpace object that you are trapping this event for.

drawObject    A reference to the ChChartDraw object. Use the DrawType property of the returned object to determine what type of rendering is about to occur.

chartObject    The object that is to be rendered. Use the TypeName function to determine the type of the object.

Cancel Set the Value property of this object to True to cancel the rendering of the object represented by chartObject   .

Remarks

You must set the AllowRenderEvents and AllowPointsRenderEvents properties to True in order to use this event with all chart objects.

Example

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

		


Applies to | ChartSpace Object



Show: