Possible to persist Marks Tip?

TeeChart for ActiveX, COM and ASP
Post Reply
Craig
Newbie
Newbie
Posts: 25
Joined: Sat Aug 09, 2003 4:00 am
Location: Calgary, Alberta
Contact:

Possible to persist Marks Tip?

Post by Craig » Tue Mar 23, 2004 6:25 pm

I wonder if it is possible to keep the Marks Tip tool displayed indefinitely? As far as I can see, you can only set the initial delay.

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

Post by Pep » Wed Mar 24, 2004 8:24 am

Hi Craig,

you cannot control the amount of time an IMarksTip Tool will display
for. What you can do is create your own Marks Tips using IAnnotation
Tools and use the TeeChart Timer to control how long they appear for.
I've post one example in the steema.public.attachments newsgroups which shows how you can calculate the nearest series point.

Craig
Newbie
Newbie
Posts: 25
Joined: Sat Aug 09, 2003 4:00 am
Location: Calgary, Alberta
Contact:

Post by Craig » Wed Mar 24, 2004 4:52 pm

Sorry Pep, I do not have VB installed, I only use C++, so I cannot look at your example. Maybe you could just tell me what functions/properties I should be looking at.

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

Post by Pep » Thu Apr 01, 2004 9:58 am

Hi Craig,

yes, primarily you must use the OnAfterDraw and OnMouseMove events in conjunction with Canvas techniques. See the code below (apologies for VB code ) :

Code: Select all

Dim CrossActive As Boolean
Dim MouseXCursorPos, MouseYCursorPos As Double

Private Sub Form_Load()
  CrossActive = True
  With TChart1.Series(0)
   ' remove previous existing points from the Series
   .Clear
   ' Fill sample values
   .FillSampleValues 20
  End With
  TChart1.Panel.MarginRight = 18
  TChart1.Panel.MarginBottom = 12
  TChart1.Legend.Visible = False
End Sub

Private Sub tChart1_OnAfterDraw()
  Dim XCursorPos, YCursorPos, XDifUp, XDifDown, YDifUp, YDifDown, XDifin, YDifin, XDifout, YDifout As Double
  Dim XIndex, YIndex, OutYIndex, OutXIndex, i As Integer
  
 With TChart1
  If .SeriesCount > 0 Then
   For i = 0 To .SeriesCount - 1
    If (.Series(i).VerticalAxis = aRightAxis) And (.Series(i).Count > 0) Then
       .Canvas.Font.Color = .Series(i).PointColor(0)
       .Canvas.TextOut .Axis.Right.Position + 10, _
             .Series(i).CalcYPos(0) - (.Canvas.TextHeight("t") / 2), _
             "x=" & Str$(.Series(i).YValues.First)
    End If
   Next i
  End If
 End With
  
  If CrossActive = True Then
   With TChart1
    If (MouseXCursorPos < .Axis.Right.Position) And (MouseXCursorPos > .Axis.Left.Position) And _
       (MouseYCursorPos < .Axis.Bottom.Position) And (MouseYCursorPos > .Axis.Top.Position) Then
     With .Series(0)
      For i = 0 To .Count - 1
        'differences to nearest points
          XDifUp = .CalcXPos(i) - MouseXCursorPos
            If XDifUp < 0 Then XDifUp = XDifUp * -1
          If i > 0 Then
            XDifDown = MouseXCursorPos - .CalcXPos(i - 1)
              If XDifDown < 0 Then XDifDown = XDifDown * -1
          Else
            XDifDown = XDifUp + 1
              If XDifDown < 0 Then XDifDown = XDifDown * -1
          End If
          YDifUp = MouseYCursorPos - .CalcYPos(i)
            If YDifUp < 1 Then YDifUp = YDifUp * -1
          If i > 0 Then
            YDifDown = .CalcYPos(i - 1) - MouseYCursorPos
              If YDifDown < 0 Then YDifDown = YDifDown * -1
          Else
            YDifDown = YDifUp + 1
              If YDifDown < 0 Then YDifDown = YDifDown * -1
          End If
          
         
          If (XDifUp + YDifUp) < (XDifDown + YDifDown) Then
            If Closest > (XDifUp + YDifUp) Or (i = 0) Then
              XOutIndex = i
              Closest = XDifUp + YDifUp
            End If
          Else
            If Closest > (XDifDown + YDifDown) Or (i = 0) Then
              XOutIndex = i - 1
              Closest = XDifDown + YDifDown
            End If
          End If
      Next i
         
      XCursorPos = .CalcXPos(XOutIndex)
      YCursorPos = .CalcYPos(XOutIndex)
      
     End With
     With .Canvas
      .ClipRectangle TChart1.Axis.Left.Position, _
                        TChart1.Axis.Top.Position, _
                        TChart1.Axis.Right.Position, _
                        TChart1.Axis.Bottom.Position
      .Pen.Color = vbWhite
      .MoveTo TChart1.Axis.Left.Position, YCursorPos
      .LineTo TChart1.Axis.Right.Position, YCursorPos
      .MoveTo XCursorPos, TChart1.Axis.Top.Position
      .LineTo XCursorPos, TChart1.Axis.Bottom.Position
      .UnClipRectangle
      .TextOut 10, .Height - 30, "Mouse X: " & Str$(CInt(TChart1.Axis.Bottom.CalcPosPoint(MouseXCursorPos))) & " , Y: " & Str$(CInt(TChart1.Axis.Left.CalcPosPoint(MouseYCursorPos)))
      .TextOut 200, .Height - 30, "Nearest Point X: " & Str$(TChart1.Series(0).XValues.Value(XOutIndex)) & " , Y: " & Str$(TChart1.Series(0).YValues.Value(XOutIndex))
     End With
    End If
   End With
  End If
End Sub

Private Sub TChart1_OnMouseMove(ByVal Shift As TeeChart.EShiftState, ByVal X As Long, ByVal Y As Long)
Dim XCursorPos, YCursorPos As Double
  If TChart1.Series(0).Count > 0 Then
    CrossActive = True
    MouseXCursorPos = X
   MouseYCursorPos = Y
    TChart1.Repaint
  End If
End Sub

Craig
Newbie
Newbie
Posts: 25
Joined: Sat Aug 09, 2003 4:00 am
Location: Calgary, Alberta
Contact:

Post by Craig » Fri Apr 02, 2004 3:53 pm

Thanks Pep, but I had a slightly different solution. I used the Nearest Point Tool along with the Annotation tool. In 'OnMouseEnterSeries', I set the Nearest Point tool to the current series, then in 'OnNearestToolChange', I set the Annotation text based on the current point and set its position and everything and set it active. Then 'OnMouseLeaveSeries', I disable it. So it looks and acts exactly like the Marks Tip, except I have more control over the text and it stays on the screen.

Thanks for your help.

MTB
Newbie
Newbie
Posts: 30
Joined: Tue Mar 11, 2003 5:00 am
Location: USA
Contact:

more feedback on alternate solution

Post by MTB » Tue Jun 01, 2004 6:59 pm

I too was having trouble with keeping MarksTips displayed. Whenever I have a TeeChart in a dockable window that is undocked, the MarksTips are removed instantly, so they appear not to work at all. I assume this is related to some automatic and frequent refreshing that is going on.

It turns out that Craig's solution worked very well for me. I implemented a replacement for the MarksTips using the Annotation tool and 'OnNearestToolChange' and I created an effect that looks identical to MarksTips but solves my problem and gives me more control.

Unless Steema sees a problem with this approach, I would highly recommend it. It sounds like it worked well for Craig, and I know it is working well for me.

BTW, I'm using the dotnet version of TeeChart.

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

Post by Pep » Wed Jun 02, 2004 7:36 am

Hi,

great, it's a good solution too.

Post Reply