Hello again,
I’ve been playing for a while with your application and I think I reached a behaviour similar to what you are trying to achieve.
I ended using Rectangle tools, since they already can show an arrow to any point you wish, in pixels.
I’m using some global arrays to store the start point of the arrows that are actually an index of the series (markStartIndex) and another array to store the position of the rectangle tool. The end point of the arrow is internally calculated, relative to the position of the rectangle tool and the start point of the arrow.
Dim markEndPos(2) As TeePoint2D
Dim markStartIndex(2) As Integer
Dim draggingRect As Integer
Private Sub Command1_Click(Index As Integer)
TChart1.Series(Index).Active = Not TChart1.Series(Index).Active
TChart1.Tools.Items(Index).Active = Not TChart1.Tools.Items(Index).Active
Select Case TChart1.Series(Index).Active
Case False
Label1(Index).Caption = "Disabled"
Case True
Label1(Index).Caption = "Enabled"
End Select
End Sub
Private Sub Command2_Click(Index As Integer)
With TChart1.Tools.Items(Index).asRectangle
.AllowDrag = Not .AllowDrag
Select Case .AllowDrag
Case True
Label2(Index).Caption = "UnPined"
Case False
Label2(Index).Caption = "Pined"
End Select
End With
End Sub
Private Sub Form_Load()
Dim dline(2) As Integer
TChart1.Series(0).Title = "My series 0"
TChart1.Series(0).AddXY 0, 0, "", vbBlue
TChart1.Series(0).AddXY 100, 10, "", vbBlue
TChart1.Series(0).AddXY 300, 12, "", vbBlue
TChart1.Series(0).AddXY 600, 8, "", vbBlue
TChart1.Series(0).AddXY 1200, 16, "", vbBlue
TChart1.Series(0).AddXY 3600, 22, "", vbBlue
TChart1.Series(1).Title = "My series 1"
TChart1.Series(1).AddXY 0, 0, "", vbRed
TChart1.Series(1).AddXY 120, 2000, "", vbRed
TChart1.Series(1).AddXY 320, 6000, "", vbRed
TChart1.Series(1).AddXY 620, 12000, "", vbRed
TChart1.Series(1).AddXY 1220, 1000, "", vbRed
TChart1.Series(1).AddXY 3600, 2700, "", vbRed
Label1(0).Caption = "Enabled"
Label1(1).Caption = "Enabled"
Label2(0).Caption = "Pined"
Label2(1).Caption = "UnPined"
TChart1.Environment.InternalRepaint
TChart1.Tools.Add tcRectangle
With TChart1.Tools.Items(0).asRectangle
.AutoSize = True
.Text = TChart1.Series(0).Title
.AllowResize = False
.AllowDrag = False
.Callout.Arrow.Visible = True
.Callout.Arrow.Color = vbCyan
markStartIndex(0) = 2
markEndPos(0).X = 500
markEndPos(0).Y = 18
End With
TChart1.Tools.Add tcRectangle
With TChart1.Tools.Items(1).asRectangle
.AutoSize = True
.Text = TChart1.Series(1).Title
.AllowResize = False
.AllowDrag = True
.Callout.Arrow.Visible = True
.Callout.Arrow.Color = vbMagenta
markStartIndex(1) = 3
markEndPos(1).X = 820
markEndPos(1).Y = 16000
End With
draggingRect = -1
recalcPositions
End Sub
Private Sub recalcPositions()
Dim startYPix, endYPix, startXPix, endXPix As Integer
TChart1.Repaint
If TChart1.Series(0).Active Then
With TChart1.Series(0)
startXPix = .CalcXPos(markStartIndex(0))
endXPix = .CalcXPosValue(markEndPos(0).X)
startYPix = .CalcYPos(markStartIndex(0))
endYPix = .CalcYPosValue(markEndPos(0).Y)
End With
With TChart1.Tools.Items(0).asRectangle
.Callout.XPosition = startXPix
.Callout.YPosition = startYPix
.Left = endXPix
.Top = endYPix
End With
End If
If TChart1.Series(1).Active Then
With TChart1.Series(1)
startXPix = .CalcXPos(markStartIndex(1))
endXPix = .CalcXPosValue(markEndPos(1).X)
startYPix = .CalcYPos(markStartIndex(1))
endYPix = .CalcYPosValue(markEndPos(1).Y)
End With
With TChart1.Tools.Items(1).asRectangle
.Callout.XPosition = startXPix
.Callout.YPosition = startYPix
.Left = endXPix
.Top = endYPix
End With
End If
End Sub
Private Sub TChart1_OnRectangleToolClick(ByVal Button As TeeChart.EMouseButton, ByVal Shift As TeeChart.EShiftState, ByVal X As Long, ByVal Y As Long)
Dim i As Integer
For i = 0 To TChart1.Tools.Count - 1
If TChart1.Tools.Items(i).ToolType = tcRectangle Then
If TChart1.Tools.Items(i).asRectangle.Clicked(X, Y) Then
draggingRect = i
End If
End If
Next i
End Sub
Private Sub TChart1_OnRectangleToolDragged()
draggingRect = -1
End Sub
Private Sub TChart1_OnRectangleToolDragging()
If draggingRect > -1 Then
With TChart1.Tools.Items(draggingRect).asRectangle
If TChart1.Series(draggingRect).HorizontalAxis = aBottomAxis Or _
TChart1.Series(draggingRect).HorizontalAxis = aBothHorizAxis Then
markEndPos(draggingRect).X = TChart1.Axis.Bottom.CalcPosPoint(.Left)
Else
If TChart1.Series(draggingRect).HorizontalAxis = aTopAxis Then
markEndPos(draggingRect).X = TChart1.Axis.Top.CalcPosPoint(.Left)
End If
End If
If TChart1.Series(draggingRect).VerticalAxis = aLeftAxis Or _
TChart1.Series(draggingRect).VerticalAxis = aBothVertAxis Then
markEndPos(draggingRect).Y = TChart1.Axis.Left.CalcPosPoint(.Top)
Else
If TChart1.Series(draggingRect).VerticalAxis = aRightAxis Then
markEndPos(draggingRect).Y = TChart1.Axis.Right.CalcPosPoint(.Top)
End If
End If
End With
End If
End Sub
Private Sub TChart1_OnScroll()
recalcPositions
End Sub
Private Sub TChart1_OnUndoZoom()
recalcPositions
End Sub
Private Sub TChart1_OnZoom()
recalcPositions
End Sub