Page 1 of 1
How to get value when line intersects a crossline?
Posted: Fri Mar 10, 2006 8:50 pm
by 9079179
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!
Posted: Mon Mar 20, 2006 8:36 am
by Pep
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
Posted: Mon Mar 20, 2006 1:36 pm
by 9079179
Very nice! Thank you!