DrawLine Method

Microsoft Office Web Components Visual Basic

expression.DrawLine(x0, y0, x1, y1)

expression    Required. An expression that returns a ChChartDraw object.

x0   Required Long. Starting pixel coordinate in the X plane.

y0   Required Long. Starting pixel coordinate in the Y plane.

x1   Required Long. Ending pixel coordinate in the X plane.

y1   Required Long. Ending pixel coordinate in the Y plane.

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(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