CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    May 2005
    Posts
    2

    Getting mouse coordinates in MSChart scale

    Hi all,

    I have the following problem: I want to show the coordinats of the mouse pointer inside a the plot of an XY MSChart diagram, using its scale. I Used the following code

    Code:
    Private Sub chart_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
    Dim xVal As String, yVal As String
    With chart.Plot
        If X - .LocationRect.min.X >= 0 And _
           X - .LocationRect.max.X <= 0 And _
           Y - .LocationRect.min.Y >= 0 And _
           Y - .LocationRect.max.Y <= 0 Then
        'ascissa ed ordinata interne all'area del grafico
            xVal = (.Axis(VtChAxisIdX).ValueScale.Maximum - .Axis(VtChAxisIdX).ValueScale.Minimum) * _
                (X - .LocationRect.min.X) / (.LocationRect.max.X - .LocationRect.min.X) _
                + .Axis(VtChAxisIdX).ValueScale.Minimum
                
            yVal = (.Axis(VtChAxisIdY).ValueScale.Maximum - .Axis(VtChAxisIdY).ValueScale.Minimum) * _
                (Y - .LocationRect.min.Y) / (-.LocationRect.max.Y + .LocationRect.min.Y) _
                + .Axis(VtChAxisIdY).ValueScale.Maximum
                
        Else
            xVal = "N.A."
            yVal = "N.A."
        End If
    End With
    End Sub
    does not work properly, since it introduces approximations. Besides, it is not capable to recognize correctly the condition of mouse pointer out of plot (i.e.: the if clause is wrong). I think that the coordinates of plot area are not given by the LocationRect. Someone can help?

  2. #2
    Join Date
    Dec 2016
    Posts
    1

    Re: Getting mouse coordinates in MSChart scale

    Hi,
    1. You have not accounted for axis area widths when using the plot area to calculate xVal, yVal.
    2. You seem to be using yVal wrong. It would be 0 to max : top to bottom !
    3. Could you say how to could get 1. above from Code !?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured