Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do i determine msChart control coordinates?

Status
Not open for further replies.

MortJC

Programmer
Joined
Dec 2, 2002
Messages
3
Location
AU
I'm trying to determine point a mouse cursor it sitting at in terms of the charts scale. E.g. if the x scale goes from the 1-dec to the 30-dec and the y scale goes from 0 to 1000 and the user place their mouse in the center of the graph I would expect to get approx 15-dec,500 as the coordinates.

I'm guess it will be some mousemove event code but I cannot find any mschart properties that will help me convert the mouse x,y coordinates into graph coordinates.

Any Clues?
 
' Take look at following sample
' In ChartSheet Module insert the following code:

Private Sub Chart_MouseMove( _
ByVal Button As Long, ByVal Shift As Long, _
ByVal x As Long, ByVal y As Long)
' --------------------------------------------------
' My Chart-Name = "Chart6" !!!
' My Chart contains only one series: "Series(1)"
'
Dim x_value As Single
Dim x1 As Integer, x2 As Integer
Dim y1 As Integer, y2 As Integer
Dim dblTemp As Double

Dim x_status As String, y_status
Dim ValuesArr(), XValuesArr()
Dim sngSeries As Single, sngY As Single
Dim intSeriesCount As Integer
Dim AxesMin As Single, AxesMax As Single
Dim i As Integer, k As Single, l As Single

' PlotArea margins
Const LeftMarg As Integer = 79 ' Left Margin
Const RightMarg As Integer = 893 ' Right Margin
Const TopMarg As Integer = 88 ' x1 = Top Margin
Const BotMarg As Integer = 531 ' x2 = Botton Margin

' x_value = 2 / 0

With Charts("Chart6").Axes(xlValue)
AxesMin = .MinimumScale ' y1 = Min (0)
AxesMax = .MaximumScale ' y2 = Max (10)
End With

' --------------------------------------------------------
' dblTemp = (x2_ - x1_) / (y2_ - y1_)
dblTemp = (AxesMax - AxesMin) / (TopMarg - BotMarg)
' x = sngTemp * (x - y1) + x1
If y >= TopMarg And y <= BotMarg Then
y_status = dblTemp * (y - TopMarg) + AxesMax
Else
y_status = &quot;&quot;
End If
' --------------------------------------------------------

ValuesArr() = Charts(&quot;Chart6&quot;).SeriesCollection(1).Values
XValuesArr() = Charts(&quot;Chart6&quot;).SeriesCollection(1).XValues
intSeriesCount = UBound(XValuesArr)

x_value = (RightMarg - LeftMarg) / intSeriesCount
' --------------------------------------------------------
sngSeries = (x - LeftMarg) / x_value
Select Case sngSeries
Case 0 To 1: x_status = XValuesArr(1)
Case 1 To 2: x_status = XValuesArr(2)
Case 2 To 3: x_status = XValuesArr(3)
Case 3 To 4: x_status = XValuesArr(4)
Case 4 To 5: x_status = XValuesArr(5)
Case 5 To 6: x_status = XValuesArr(6)
Case Else: x_status = &quot;&quot;
End Select
' --------------------------------------------------------
On Error Resume Next
Application.StatusBar = x_status & &quot; - &quot; & _
&quot;value = &quot; & Round(y_status, 2)
If Err <> 0 Then Application.StatusBar = False
End Sub

' andrija.vrcan@dalmacijacement.hr
 
Thanks avrcan.

A very good example. However my question relates to the MSChart control and I think you example is for Excel. I could do something similar with the MSChart control however I have no way of determining accurately the plot area, due to the ability to resize the form.

In the end I wrote my own control. I must say I am very please with the results as it gives me complete control over the properties and methods are available. My control isn't as complex as the Microsoft one but then I didn't need 95% of what it offered.

Thanks again for your posting.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top