New guy here, so please go easy on me. I'm working on a project that could use two perpendicular lines to follow the cursor around on a chart. I've gotten it to work to a point, but my problem lies in what I believe to be the scaling of the PlotArea. I define the start/end of both lines as the boundaries of the PlotArea, but it is evident that they don't start directly on the boundaries. Also, as the cursor moves down and to the right, the discrepancy between the cursor and the intersection point of the perpendicular lines becomes larger. What I want to find out is how to make the two lines perfectly "in sync" with the cursor and the PlotArea boundaries. The conceptual workbook is attached in case anyone would want to take a look. Thanks in advance!
My code is placed in the Chart's sheet.
Option Explicit
Public YPosition, XPosition As Variant
Sub Test()
Dim HorizontalLine, VerticalLine As Shape
Dim StartX, StartY, EndX, EndY As Double
With ActiveChart
StartX = .PlotArea.Left + .Axes(xlValue).Width
StartY = .PlotArea.Height + .Axes(xlCategory).Width
EndX = .PlotArea.Width
EndY = .PlotArea.Top
End With
If ActiveChart.Shapes.Count > 1 Then
Do Until ActiveChart.Shapes.Count = 0
ActiveChart.Shapes(1).Delete
Loop
End If
If HorizontalLine = "" Then
With ActiveSheet
Set HorizontalLine = .Shapes.AddLine(StartX, YPosition, EndX, YPosition)
Set VerticalLine = .Shapes.AddLine(XPosition, StartY, XPosition, EndY)
End With
End If
End Sub
Sub Chart_MouseMove(ByVal Button As Long, ByVal Shift As Long, ByVal X As Long, ByVal Y As Long)
Dim ElementID As Long
Dim Arg1 As Long
Dim Arg2 As Long
Me.GetChartElement X, Y, ElementID, Arg1, Arg2
XPosition = X
YPosition = Y
Call Test
End Sub
Bookmarks