Search code examples
activexteechart

TeeChart For Point having Value as 0


I am plotting a Line Chart, The Problem is in my data some points have zero Value. If I do AddNull For that it don't show the X-axis Value for the same. Can anyone share a example of Using a AddNULL and Add in the same series Impact.

E.g I have a Series having 11 X- Pts, The Series Data is (0,0,0,0,0,10,0,0,0,0,0) The Point with value 10 should be shown at 5th place but in my case it is displayed at Position 0.

enter image description here


Solution

  • I recommend you use method SetNull or AddNullXY to make null, the values you want and set the property TreatNull to DontPaint because the null values aren't visible. I have made a simple code for you, where I use method SetNull to add nulls in your series:

    Private Sub Form_Load()
        TChart1.Aspect.View3D = False
        TChart1.AddSeries scLine
        TChart1.AddSeries scLine
        TChart1.Series(0).asLine.Pointer.Visible = True
        TChart1.Series(1).asLine.Pointer.Visible = True
        Dim i As Integer
         For i = 0 To 19
            TChart1.Series(0).AddXY i, Rnd, "", vbBlue
            If i = 5 Then
                TChart1.Series(1).AddXY i, 10, "", vbRed
            Else
                TChart1.Series(1).AddXY i,0, "", vbRed
            End If
        Next i
    
        For i = 0 To TChart1.Series(1).Count - 1
            If i <> 5 Then
                TChart1.Series(1).SetNull (i)
            End If
        Next i
        TChart1.Series(1).asLine.TreatNulls = tnDontPaint
    End Sub
    

    Could you tell us if previous works as you want?

    Thanks,