How to get value when line intersects a crossline?

TeeChart for ActiveX, COM and ASP
Post Reply
Jeff
Newbie
Newbie
Posts: 22
Joined: Fri Nov 15, 2002 12:00 am
Location: Virginia, United States

How to get value when line intersects a crossline?

Post by Jeff » Fri Mar 10, 2006 8:50 pm

Hello,

I have a "line" on a teechart and a "Color line" (from the tools tab). I need to get the value when these lines intersect. How do I do that?

Thanks!

Pep
Site Admin
Site Admin
Posts: 3295
Joined: Fri Nov 14, 2003 5:00 am
Contact:

Post by Pep » Mon Mar 20, 2006 8:36 am

Hi Jeff,

you can use the following code :

Code: Select all

Private Sub Form_Load()
 TChart1.Series(0).FillSampleValues 20
 TChart1.Series(1).FillSampleValues 20
End Sub

Private Sub TChart1_OnMouseMove(ByVal Shift As TeeChart.EShiftState, ByVal X As Long, ByVal Y As Long)
 Dim xx, yy, i
 Dim InChart As Boolean

 xpos = X
 ypos = Y

 InChart = True

 With TChart1
  'Optionally use .Aspect.Width3D and Height3D to set Line to plane of Series
  'in a 3D Chart - recommend use of 2D for simplicity
  If X <= .Axis.Left.Position Then
    X = .Axis.Left.Position + 1
    InChart = False
    LastValueY = 0
  End If

  If X > .Axis.Right.Position Then
    X = .Axis.Right.Position - 1
    InChart = False
    LastValueY = .Series(0).Count - 1
  End If

  .Canvas.Brush.Style = bsClear
  .Repaint
  If .SeriesCount > 0 Then
   For s = 0 To .SeriesCount - 1
    If .Series(s).Count > 0 Then
     If InChart = True Then
       For i = .Axis.Top.Position To .Axis.Bottom.Position
        If .Series(s).Clicked(X, i) <> -1 Then
          Exit For
        End If
       Next i
       .Canvas.TextOut 10, 10 + (10 * s), "Series " & s & " Value: " & CInt(.Series(s).YScreenToValue(i))
     Else
      .Canvas.TextOut 10, 10 + (10 * s), "Series " & s & " Value: " & CInt(.Series(s).YValues.Value(LastValueY))
     End If
    End If
   Next s
  End If

  '.Canvas.Pen.Style = psDot
  '.Canvas.Pen.Color = vbWhite
  .Canvas.Pen.Color = vbBlue
  .Canvas.MoveTo X, .Axis.Top.Position
  .Canvas.LineTo X, .Axis.Bottom.Position
 End With
End Sub

Jeff
Newbie
Newbie
Posts: 22
Joined: Fri Nov 15, 2002 12:00 am
Location: Virginia, United States

Post by Jeff » Mon Mar 20, 2006 1:36 pm

Very nice! Thank you!

Post Reply