Share via


OverrideDefaultElementFormatting Method

You use the OverrideDefaultElementFormatting method to use the drawing format of the current ChChartDraw object to draw a chart. Returns Nothing.

expression**.OverrideDefaultElementFormatting()**

*expression   * Required. An expression that returns a ChChartDraw object.

Remarks

Most chart elements that generate a BeforeRender event initialize the drawing surface by using the default formatting of the Chart component. You can use the OverrideDefaultElementFormatting method in the BeforeRender event procedure to change the default properties of the current ChChartDraw object passed to the BeforeRender event as its drawObject parameter.

Example

The following example uses the OverrideDefaultElementFormatting method to change a property of the ChChartDraw object:

Sub Chartspace_BeforeRender(drawObject As ChChartDraw, chartObject As Object, Cancel As ByRef)
    On Error Resume Next

    ' This format will be applied only to all legends.
    If TypeName(chartObject)="ChLegend" Then
        drawObject.border.weight = 5
        drawObject.border.color = "green"
        drawObject.OverrideDefaultElementFormatting
    End If
    
    ' This format will only be applied to all titles.
    If TypeName(chartObject)="ChTitle" Then
        drawObject.border.weight = 10
        drawObject.border.color = "violet"
        drawObject.OverrideDefaultElementFormatting
    End If
End Sub

Sub Chartspace_AfterRender(drawObject As ChChartDraw, chartObject As Object)
    Select Case TypeName(chartObject)
        Case "ChLegend", "ChTitle"
            ' Chartspace will apply the overrided drawObject format to the Title and Legend objects.
            drawObject.DrawRectangle chartObject.Left, _
                            chartObject.Top, chartObject.right, chartObject.bottom
    End Select
End Sub

Applies to | ChChartDraw Object