Hello, I am writing the code in order to be able to zoom on chart. It is supposed to change axis scales in order to display only selected area.
So the aim is to get new X and Y axes min and max coordinates. But the coordinates don't make sense. I think it is because the chart object client coordinates units are not points. So please do you have any ideas
this is the code:
Private Sub Chart_MouseDown(ByVal Button As Long, _
ByVal Shift As Long, ByVal X As Long, ByVal Y As Long)
If Shift = 2 And Button = 1 Then
ActiveChart.Deselect
firstX = X
firstY = Y
End If
End Sub
Private Sub Chart_MouseUp(ByVal Button As Long, _
ByVal Shift As Long, ByVal X As Long, ByVal Y As Long)
If Shift = 2 And Button = 1 Then
lastX = X
lastY = Y
ActiveChart.Deselect
intOldMinX = ActiveChart.Axes(xlCategory).MinimumScale
intOldMaxX = ActiveChart.Axes(xlCategory).MaximumScale
intOldMinY = ActiveChart.Axes(xlValue).MinimumScale
intOldMaxY = ActiveChart.Axes(xlValue).MaximumScale
intFirstXAxis = Int((intOldMaxX - intOldMinX) * (firstX - ActiveChart.Axes(xlCategory).Left) / ActiveChart.Axes(xlCategory).Width)
intLastXAxis = Int((intOldMaxX - intOldMinX) * (lastX - ActiveChart.Axes(xlCategory).Left) / ActiveChart.Axes(xlCategory).Width)
intFirstYAxis = Int((intOldMaxY - intOldMinY) * (1 - (firstY - ActiveChart.Axes(xlValue).Top) / ActiveChart.Axes(xlValue).Height))
intLastYAxis = Int((intOldMaxY - intOldMinY) * (1 - (lastY - ActiveChart.Axes(xlValue).Top) / ActiveChart.Axes(xlValue).Height))
End If
End Sub

Coordinate of the mouse pointer in chart object client coordinates
Ravindra Rajaram
Thank you very much for the answer.
I will look in it. Once i get the right coordinates. I can change the minimum and maximum values for both axes in order to display desired area
Sukanya
The X,Y provided as arguments to the mouse event procedures are in pixels, while the chart element dimensions understood by VBA are in points. This thread in Google Groups (actually, from microsoft.public.excel.charting) describes the necessary conversion:
http://groups.google.com/group/microsoft.public.excel.charting/browse_thread/thread/fbf12b6998665262/f48f43d3fdee2b28 lnk=st&q=&rnum=3&hl=en#f48f43d3fdee2b28
Don't forget to take into account axes which may be displayed in reverse order.
What technique are you using to show the user the rectangular area being selected
- Jon
-------
Jon Peltier, Microsoft Excel MVP
Tutorials and Custom Solutions
http://PeltierTech.com
_______
tohams
What is the relation between these values and points