VB Example Program



' *******************************************************

'                                                       *

'   Description: Visual Basic example building one      *

'            graph with the Charting Tools for Windows  *

'                                                       *

' *******************************************************


Option Explicit

Const NUMP1 = 80

Dim fInit As Integer

Dim X1() As Double

Dim Y1() As Double


Sub DrawP1G1 (pGrDesc As Long, hdc As Integer)

    Dim hObj As Integer, success As Integer

    Dim hAxisX As Integer, hAxisY As Integer

    Dim hDataSet As Integer

    ' define a dataset

    hDataSet =   WGVBDefineDataSet("60 Cycle Noise",

                                    X1(0), Y1(0), NUMP1)

    ' define the plotting area of the graph

    Call WGSetPlotArea(pGrDesc, hdc, .15, .15, .9, .8, C_LIGHTGRAY)

    ' axes to be drawn in solid, black, 1 pixel thick

    Call WGSetLineStyle(pGrDesc, hdc, PS_SOLID, 1, C_BLACK)

    ' set current font to Arial, 12 points, bold

    Call WGSetTextByName(C_BLACK, "Arial", 10, TEXT_BOLD)

    ' analyze the data set and automaticaly scale the

    ' plot area, draw and label the axes

    success = WGAutoAxes(pGrDesc, hdc, hDataSet, AS_ROUNDCLOSE,

                        INTF_ZERO, hAxisX, hAxisY, False, False)

    ' set line style of actual plot to RED

    Call WGSetLineStyle(pGrDesc, hdc, PS_SOLID, 0, C_RED)

    ' plot the data with spline interpolation on

    hObj = WGLinePlot(pGrDesc, hdc, hDataSet, False, True)

    ' write axes titles

    hObj = WGTitleAxis(pGrDesc, hdc, hAxisX, POS_BELOW,

                      "Sample Interval")

    hObj = WGTitleAxis(pGrDesc, hdc, hAxisY, POS_LEFT, "Volts")

    ' set current font to Arial, 16 points, bold, italic

    Call WGSetTextByName(C_GREEN, "Arial", 16,

                         TEXT_BOLD + TEXT_ITAL)

    ' write graph title

    hObj = WGTitleGraph(pGrDesc, hdc, "Input Waveform")

End Sub

Sub Form_Load ()

    Dim i As Integer

    Dim pPageDesc As Long

    For i = 0 To 4150

        TopDesc(i) = 0

    Next

     pPageDesc = WGCreatePage("Page1", EasyGrafForm.hWnd,

                            "Easy Graph","PageMenu", C_LIGHTGRAY,

                             MM_PROPORT, 0, PAGE_CLIENT,

                             0, 0, 0, 0, TopDesc(0))

     Call StartGraphs1(pPageDesc)

     Call WGUpdatePage(pPageDesc)

End Sub

Sub Form_Unload()

    Call WGCleanup(TopDesc(0), True)

    End&127;

End Sub

Sub StartGraphs1 (pPageDesc As Long)

    ReDim X1(NUMP1 - 1) As Double

    ReDim Y1(NUMP1 - 1) As Double

    Dim hdc As Integer,  As Integer

    Dim pGrDesc As Long

    If fInit = True Then

        Randomize

        fInit = False

        For i = 0 To NUMP1 - 1

            X1(i) = i

            Y1(i) = 15 * Cos(M_PI * i / (4 + .3 * Rnd) + 3 * Rnd)

        Next

    End If

    pGrDesc = WGCreateGraph(pPageDesc, .005, .005, .99, .99,

                            C_WHITE, C_RED, 1, TopDesc(0), hdc)

    Call DrawP1G1(pGrDesc, hdc)

End Sub