Page 1 of 1

asp label access

Posted: Thu Mar 06, 2008 8:40 am
by 9535493
Hello,

pls is it possible to access label set up with:

TChartSpeed.Series(1).AddXY 92 , 1001.07 , "sample label" , RGB(255,0,0)

in mouse event:

Sub TChartSpeed_OnMouseMove(Shift, X, Y)

???

I would like to display this label with yvalues in rectangle with annotation tool.
thanks

Posted: Thu Mar 06, 2008 8:57 am
by yeray
Hi adenin,

If I understand well, you are trying to achieve something very similar than All Features/Tools/Annotation/Annotation Callout example in the new features demo, available at TeeChart's program group.

Posted: Thu Mar 06, 2008 9:14 am
by 9535493
yes, something like that;

I have already found it:

Sub TChartSpeed_OnMouseMove(Shift, X, Y)

mouseOverIndex = TChartSpeed.Series(1).Clicked(X, Y)

If mouseOverIndex <> -1 Then
TChartSpeed.Tools.Items(0).Active=True
TChartSpeed.Tools.Items(0).asAnnotation.Text = "value:" & TChartSpeed.Series(1).YValues.Value(mouseOverIndex) & Chr(13) & "label:" & TChartSpeed.Series(1).PointLabel(mouseOverIndex)
...

Posted: Thu Mar 06, 2008 9:18 am
by yeray
Hi adenin,

I've made an example using two functions in the demo I've pointed to you before. Note that for me, the series index is 0, and for you is 1.

Code: Select all

Private Sub Form_Load()
  With TChart1
    .Aspect.View3D = False
    .Legend.Visible = False
    .AddSeries scPoint
    
    For i = 0 To 49
      .Series(0).AddXY i, Rnd * 1000, "Point number " + Str$(i), RGB(255, 0, 0)
    Next i
    
    .Axis.Bottom.Labels.Style = talValue
    
    With .Tools
      .Add tcAnnotate
      
      With .Items(0).asAnnotation
        .Left = 300
        .Top = 15
        .Text = TChart1.Series(0).PointLabel(0)
      End With
    End With
  End With
End Sub

' Returns Series point index that is nearest to xy position.
Function NearestPoint(ByVal X As Long, ByVal Y As Long) As Long
Dim Difference As Long, tmpDif As Long, i As Long, res As Long
  res = -1
  Difference = -1
  For i = 0 To TChart1.Series(0).Count - 1
    tmpDif = Round(TeeDistance(TChart1.Series(0).CalcXPos(i) - X, _
                               TChart1.Series(0).CalcYPos(i) - Y))

    If (Difference = -1) Or (tmpDif < Difference) Then
      Difference = tmpDif
      res = i
    End If
  Next i
  NearestPoint = res
End Function

Function TeeDistance(ByVal X As Integer, ByVal Y As Integer) As Double
  TeeDistance = Sqr(X ^ 2 + Y ^ 2)
End Function

Private Sub TChart1_OnMouseMove(ByVal Shift As TeeChart.EShiftState, ByVal X As Long, ByVal Y As Long)
Dim i As Integer
  i = NearestPoint(X, Y)
  TChart1.Tools.Items(0).asAnnotation.Text = TChart1.Series(0).PointLabel(i)
End Sub