property Chart.CountVisibleUnits ([Start as Variant], [End as Variant]) as Long
Counts the number of units within the specified range.

 TypeDescription 
   Start as Variant A DATE expression that specifies the starting date, if missing, the StartPrintDate value is used.  
   End as Variant A DATE expression that specifies the ending date, if missing, the EndPrintDate value is used.  
   Long A long expression that specifies the number of units within the specified range.  
Use the CountVisibleUnits property to count the number of units within the specified range. The UnitScale property indicates the time-unit scale being displayed by the chart's header. Use the CountVisibleUnits property to count the number of units so the entire chart is displayed on a specified size. Use the UnitWidth property specifies the width in pixels for the minimal time-unit. Use the CountVisibleUnits property and the ClientWidth property of the eXPrint component (Retrieves the width in pixels, of the drawing area of the printer page) to specify that you need to display the chart on a single page. The StartPrintDate and EndPrintDate property specifies range of dates within the chart is printed. 

When computing the UnitWidth property for printing to a page ( as shown in the following sample ), you can still use the Count property of the Level object to display more units instead one.

The following VB sample changes the UnitWidth property of the eXG2ant's Chart object so, the entire chart is printed to the page:

With Print1
    Dim l As Long
    With G2antt1.Chart
        l = .UnitWidth
        .UnitWidth = (Print1.ClientWidth - .PaneWidth(False)) / .CountVisibleUnits()
    End With
    Set .PrintExt = G2antt1.Object
    .Preview
    G2antt1.Chart.UnitWidth = l
End With

The sample has the disadvantage that once the user changes the Page's setup during Previewing the code is not re-executed, so the chart is displayed as it is on the screen. In order to update the UnitWidth property once the page's setup is changed, we need to handle the Refreshing and Refresh events of the eXPrint component as shown in the following VB sample:

Dim nUnitWidth As Long

Private Sub Print1_Refreshing()
    With G2antt1.Chart
        nUnitWidth = .UnitWidth
        .UnitWidth = (Print1.ClientWidth - .PaneWidth(False)) / .CountVisibleUnits()
    End With
End Sub

Private Sub Print1_Refresh()
    G2antt1.Chart.UnitWidth = nUnitWidth
End Sub

Private Sub Preview_Click()
    With Print1
        Set .PrintExt = G2antt1.Object
        .Preview
    End With
End Sub

The sample changes the UnitWidth property of the Chart during the Refreshing event, so the chart fits to page, and restores the UnitWidth's value when the Refresh event is invoked. 

The following VB/NET sample changes the UnitWidth property so the chart fits to page:

Dim nUnitWidth As Long

Private Sub Exprint1_RefreshingEvent(ByVal sender As System.Object) Handles Exprint1.RefreshingEvent
    With Exg2antt1.Chart
        nUnitWidth = .UnitWidth
        .UnitWidth = (Exprint1.ClientWidth - .get_PaneWidth(False)) / .CountVisibleUnits()
    End With
End Sub

Private Sub Exprint1_RefreshEvent(ByVal sender As System.Object) Handles Exprint1.RefreshEvent
    Exg2antt1.Chart.UnitWidth = nUnitWidth
End Sub

Private Sub Preview_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Preview.Click
    Exprint1.PrintExt = Exg2antt1
    Exprint1.Preview()
End Sub

Send comments on this topic.
1999-2017 Exontrol.COM, Software. All rights reserved.