Sample 3 - Null Data Points

' To test this code, the trial or full version of XYChart must be installed on your computer.
' 1. Start a new standard Visual Basic project
' 2. Copy the code below directly into the project
' 3. On the form, place a new XYChart control named XYChart4Ctl1 (default)
' 4. Run the project

Private Sub Form_Load()
    ' Create random chart data
    Dim i As Integer
    Dim ChartData() As Double

    Const NullDataValue As Double = 1.79 * 10 ^ 308

    ' Configure XYChart control
    With XYChart4Ctl1
        .NumProfiles = 1
        .NumYScales = 1
        .NumXScales = 1

        ' Legend
        .Legend.Visible = True
        .Legend.BorderVisible = False
        .Legend.YScaleVisible = False

        .Toolbar.Visible = True

        ' Crosshairs
        .CrossHairs.YCoordInLegend = True
        .CrossHairs.Color = vbBlack
        .CrossHairs.Width = woTwoPoint
        .CrossHairs.HorizontalVisible = False
        .CrossHairs.CoordsBackcolor = RGB(0, 170, 0)

        ' Grids
        .YGrid(1).LineOption = loCustom
        .YGrid(1).LineColor = RGB(0, 170, 0)
        .XGrid(1).LineOption = loCustom
        .XGrid(1).LineColor = .YGrid(1).LineColor

        ' Y Scale
        .YScale(1).Label = ""
        .YScale(1).TicksFont.Color = vbWhite
        .YScale(1).LabelFont.Color = .YScale(1).TicksFont.Color
        .YScale(1).Visible = True
        .YScale(1).ScaleMode = smAuto

        ' X Scale
        .XScale(1).Label = ""
        .XScale(1).TicksFont.Color = vbWhite
        .XScale(1).LabelFont.Color = .XScale(1).TicksFont.Color
        .XScale(1).Visible = True
        .XScale(1).ScaleMode = smAuto

        .BackColor = RGB(64, 64, 192)

        ' Plot
        .Plot.BackColor = RGB(203, 203, 228)
        .Plot.Border.LineOption = loNone
        .Plot.Border.LineWidth = woOnePoint
        .Plot.Border.LineColor = RGB(0, 128, 0)

        ' Profile
        .Profile(1).YScale = 1
        .Profile(1).XScale = 1
        .Profile(1).LineOption = loCustom
        .Profile(1).LineWidth = woTwoPoint
        .Profile(1).LineStyle = soSolid
        .Profile(1).LineColor = RGB(192, 0, 0)
        .Profile(1).MarkerOption = loCustom
        .Profile(1).MarkerStyle = msDiamond
        .Profile(1).MarkerSize = 4
        .Profile(1).MarkerFillcolor = .Profile(1).LineColor
        .Profile(1).MarkerBordercolor = .Profile(1).LineColor
        .Profile(1).Label = "Profile 1"
        .Profile(1).NumSamples = 30

        ' Populate array, then feed into XYChart
        ReDim ChartData(1 To .Profile(1).NumSamples, 1 To 2 * .NumProfiles)
        For i = 1 To .Profile(1).NumSamples
            ChartData(i, 1) = (i - 1) * 1
            If i = 1 Then
                ChartData(i, 2) = 0 ' Force firsy y value to zero
            Else
                If Rnd <= 0.2 Then ' Set random null values 20% of time
                    ChartData(i, 2) = NullDataValue
                Else
                    ChartData(i, 2) = 100 * Rnd
                End If
            End If
        Next i

        .ChartData = ChartData

        .Refresh

    End With

End Sub


' Resize Event
Private Sub Form_Resize()
    With XYChart4Ctl1
        .Left = 0
        .Top = 0
        .Width = Me.ScaleWidth
        .Height = Me.ScaleHeight
        .Refresh
    End With
End Sub