If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below. |
|
|
Thread Tools | Display Modes |
#1
|
|||
|
|||
X,Y coordinates on chart
I have to create a char, that when clicked on will return the point of the click. PLEASE, noticed that I will be clicking anywhere on the plot NO on a SERIES of points. In other words, lets say I have a XY chart with these values: x= 1,2,3,4,5,6,7,8 y= 2,9,4,5,7,2,4,1 If I do an ALEATORY click somewhere on the plot (NOT ON AN ALREADY PLOTTED SERIES!) I will get the values equals or close to the ones shwon above. Thanks! -- lgarcia3 ------------------------------------------------------------------------ lgarcia3's Profile: http://www.excelforum.com/member.php...fo&userid=7488 View this thread: http://www.excelforum.com/showthread...hreadid=513428 |
#2
|
|||
|
|||
X,Y coordinates on chart
You can capture a mouse click event, and determine the X,Y coordinates of
the point. This X and Y are not related to the chart axes, but a little algebra will get you what you need. This X,Y is in the coordinates of the chart object, which is in pixels from the top left of the chart. Convert pixels to points, which are used for chart element dimensions. Determine where the converted X,Y fit within the plot inside area (turning pixels into a percentage of each axis scale), and then convert from this percentage to axis units. This code shows a mouse_down event procedure which captures all of this information. It only works for an XY chart's value X axis, not the date-scale or category axis of a line/area/column chart (but these merely need different algebraic manipulations). Step through it the first couple times to make sure it does what is expected. Private Sub Chart_MouseDown(ByVal Button As Long, ByVal Shift As Long, _ ByVal X As Long, ByVal Y 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 datatemp As Double Dim Xcoordinate As Double Dim Ycoordinate As Double Dim X1 As Double Dim Y1 As Double X1 = X * 75 / ActiveWindow.Zoom Y1 = Y * 75 / ActiveWindow.Zoom 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 datatemp = (X1 - PlotArea_InsideLeft) / PlotArea_InsideWidth * _ (AxisCategory_MaximumScale - AxisCategory_MinimumScale) Xcoordinate = IIf(AxisCategory_Reverse, _ AxisCategory_MaximumScale - datatemp, _ datatemp + AxisCategory_MinimumScale) datatemp = (Y1 - PlotArea_InsideTop) / PlotArea_InsideHeight * _ (AxisValue_MaximumScale - AxisValue_MinimumScale) Ycoordinate = IIf(AxisValue_Reverse, _ datatemp + AxisValue_MinimumScale, _ AxisValue_MaximumScale - datatemp) MsgBox "X = " & Xcoordinate & vbCrLf & "Y = " & Ycoordinate End Sub - Jon ------- Jon Peltier, Microsoft Excel MVP Peltier Technical Services Tutorials and Custom Solutions http://PeltierTech.com/ _______ "lgarcia3" wrote in message ... I have to create a char, that when clicked on will return the point of the click. PLEASE, noticed that I will be clicking anywhere on the plot NO on a SERIES of points. In other words, lets say I have a XY chart with these values: x= 1,2,3,4,5,6,7,8 y= 2,9,4,5,7,2,4,1 If I do an ALEATORY click somewhere on the plot (NOT ON AN ALREADY PLOTTED SERIES!) I will get the values equals or close to the ones shwon above. Thanks! -- lgarcia3 ------------------------------------------------------------------------ lgarcia3's Profile: http://www.excelforum.com/member.php...fo&userid=7488 View this thread: http://www.excelforum.com/showthread...hreadid=513428 |
#3
|
|||
|
|||
X,Y coordinates on chart
Jon, Thanks a million! That is excellent. I was reading your web site. It's very good. Thanks again! -- lgarcia3 ------------------------------------------------------------------------ lgarcia3's Profile: http://www.excelforum.com/member.php...fo&userid=7488 View this thread: http://www.excelforum.com/showthread...hreadid=513428 |
Thread Tools | |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Multiple filter query of form | truepantera | Using Forms | 6 | August 4th, 2005 08:26 AM |
Pie chart on a pie chart (exploded)? | KR | General Discussion | 1 | June 9th, 2005 07:28 PM |
Chart menu visible property | Sandy V | Charts and Charting | 8 | May 17th, 2004 01:39 PM |
Get mouse pointer position in chart coordinates | Jon Peltier | Charts and Charting | 2 | March 19th, 2004 01:43 PM |
Chart Object Name | LB | Charts and Charting | 4 | September 26th, 2003 11:27 PM |