Hello,
I have ran into a problem with some code that I have been using. Currently, the code is in a class module of an embedded chart.
The code was intended to find a data point that was clicked on. Once found, it will move the data point to where the user moved it, in the vertical plane only, using a mousemove subroutine. It seems to work fine on the machine I am using, screen resolution of 1280x1024 pixels at a zoom of 100%. At this zoom level and screen resolution, the embedded chart will fit entirely in the window when the tab of the chart worksheet is selected. However, at various other screen resolutions/zoom levels, the chart doesn't fit entirely in the window. When this happens, the movement control used in the mousemove subroutine doesn't work right. The data point will move, but will move so fast that the autoscaled chart will change it's scale, which in turn will cause that datapoint to move faster through ever increasing chart scales. I have turned the auto chart scaling off but the data point will just move out of veiw of the scale that was there. I am including some of the code that is used. Any suggestions on how to correct this would be greatly appreciated.
Thank-you
Private Sub myChartClass_MouseMove(ByVal Button As Long, _
ByVal Shift As Long, ByVal x As Long, ByVal y As Long)
Dim IDNum As Long
Dim a As Long
Dim b As Long
Dim PlotArea_InsideLeft As Double
Dim PlotArea_InsideTop As Double
Dim PlotArea_InsideWidth As Double
Dim PlotArea_InsideHeight As Double
Dim AxisCategory_MinimumScale As Double
Dim AxisCategory_MaximumScale As Double
Dim AxisCategory_Reverse As Boolean
Dim AxisValue_MinimumScale As Double
Dim AxisValue_MaximumScale As Double
Dim AxisValue_Reverse As Boolean
Dim datatempx As Double
Dim datatempy As Double
Dim Xcoordinate As Double
Dim Ycoordinate As Double
Dim X1 As Double
Dim Y1 As Double
Dim height As Double
ActiveChart.GetChartElement x, y, IDNum, a, b
If IDNum = xlPlotArea Then
If drag1 = True Then
If Button = xlPrimaryButton Then
On Error Resume Next
X1 = x * 75 / ActiveWindow.Zoom
Y1 = y * 75 / ActiveWindow.Zoom
height = ActiveSheet.ChartObjects("Chart 1").height
With ActiveChart
PlotArea_InsideLeft = .PlotArea.InsideLeft + .ChartArea.Left
PlotArea_InsideTop = .PlotArea.InsideTop + .ChartArea.Top
PlotArea_InsideWidth = .PlotArea.InsideWidth
PlotArea_InsideHeight = .PlotArea.InsideHeight
With .Axes(xlCategory)
AxisCategory_MinimumScale = .MinimumScale
AxisCategory_MaximumScale = .MaximumScale
AxisCategory_Reverse = .ReversePlotOrder
End With
With .Axes(xlValue)
AxisValue_MinimumScale = .MinimumScale
AxisValue_MaximumScale = .MaximumScale
AxisValue_Reverse = .ReversePlotOrder
End With
End With
datatempx = (X1 - PlotArea_InsideLeft) / PlotArea_InsideWidth * _
(AxisCategory_MaximumScale - AxisCategory_MinimumScale)
Xcoordinate = IIf(AxisCategory_Reverse, _
AxisCategory_MaximumScale - datatempx, _
datatempx + AxisCategory_MinimumScale)
datatempy = (Y1 - PlotArea_InsideTop) / PlotArea_InsideHeight * _
(AxisValue_MaximumScale - AxisValue_MinimumScale)
Ycoordinate = IIf(AxisValue_Reverse, _
datatempy + AxisValue_MinimumScale, _
AxisValue_MaximumScale - datatempy)
Worksheets("Calc % Spread").Cells(cutcrange, 17).Value = Ycoordinate
End If
End If
End If
End Sub
I have ran into a problem with some code that I have been using. Currently, the code is in a class module of an embedded chart.
The code was intended to find a data point that was clicked on. Once found, it will move the data point to where the user moved it, in the vertical plane only, using a mousemove subroutine. It seems to work fine on the machine I am using, screen resolution of 1280x1024 pixels at a zoom of 100%. At this zoom level and screen resolution, the embedded chart will fit entirely in the window when the tab of the chart worksheet is selected. However, at various other screen resolutions/zoom levels, the chart doesn't fit entirely in the window. When this happens, the movement control used in the mousemove subroutine doesn't work right. The data point will move, but will move so fast that the autoscaled chart will change it's scale, which in turn will cause that datapoint to move faster through ever increasing chart scales. I have turned the auto chart scaling off but the data point will just move out of veiw of the scale that was there. I am including some of the code that is used. Any suggestions on how to correct this would be greatly appreciated.
Thank-you
Private Sub myChartClass_MouseMove(ByVal Button As Long, _
ByVal Shift As Long, ByVal x As Long, ByVal y As Long)
Dim IDNum As Long
Dim a As Long
Dim b As Long
Dim PlotArea_InsideLeft As Double
Dim PlotArea_InsideTop As Double
Dim PlotArea_InsideWidth As Double
Dim PlotArea_InsideHeight As Double
Dim AxisCategory_MinimumScale As Double
Dim AxisCategory_MaximumScale As Double
Dim AxisCategory_Reverse As Boolean
Dim AxisValue_MinimumScale As Double
Dim AxisValue_MaximumScale As Double
Dim AxisValue_Reverse As Boolean
Dim datatempx As Double
Dim datatempy As Double
Dim Xcoordinate As Double
Dim Ycoordinate As Double
Dim X1 As Double
Dim Y1 As Double
Dim height As Double
ActiveChart.GetChartElement x, y, IDNum, a, b
If IDNum = xlPlotArea Then
If drag1 = True Then
If Button = xlPrimaryButton Then
On Error Resume Next
X1 = x * 75 / ActiveWindow.Zoom
Y1 = y * 75 / ActiveWindow.Zoom
height = ActiveSheet.ChartObjects("Chart 1").height
With ActiveChart
PlotArea_InsideLeft = .PlotArea.InsideLeft + .ChartArea.Left
PlotArea_InsideTop = .PlotArea.InsideTop + .ChartArea.Top
PlotArea_InsideWidth = .PlotArea.InsideWidth
PlotArea_InsideHeight = .PlotArea.InsideHeight
With .Axes(xlCategory)
AxisCategory_MinimumScale = .MinimumScale
AxisCategory_MaximumScale = .MaximumScale
AxisCategory_Reverse = .ReversePlotOrder
End With
With .Axes(xlValue)
AxisValue_MinimumScale = .MinimumScale
AxisValue_MaximumScale = .MaximumScale
AxisValue_Reverse = .ReversePlotOrder
End With
End With
datatempx = (X1 - PlotArea_InsideLeft) / PlotArea_InsideWidth * _
(AxisCategory_MaximumScale - AxisCategory_MinimumScale)
Xcoordinate = IIf(AxisCategory_Reverse, _
AxisCategory_MaximumScale - datatempx, _
datatempx + AxisCategory_MinimumScale)
datatempy = (Y1 - PlotArea_InsideTop) / PlotArea_InsideHeight * _
(AxisValue_MaximumScale - AxisValue_MinimumScale)
Ycoordinate = IIf(AxisValue_Reverse, _
datatempy + AxisValue_MinimumScale, _
AxisValue_MaximumScale - datatempy)
Worksheets("Calc % Spread").Cells(cutcrange, 17).Value = Ycoordinate
End If
End If
End If
End Sub