Home Forums WinForms controls Xceed Chart for WinForms Data Cursors – 2 active at same time?

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • User (Old forums)
    Member
    Post count: 23064
    #19017 |

    I want to achieve the following:

    1. As the user moves the mouse over the chart area, the X and Y coordinates (in data values) are shown in textboxes elsewhere on the page. I’ve done this and it works fine. It uses the OnMouseMove event on the data cursor.

    2. The user can also click and drag between 2 points in the chart, and when the drag ends I want to show the difference in one of the axis values between the two points.  If it’s easier I’d be just as happy to click at two points, rather than click-and-drag.

    It seems to me I need 2 Data Cursor interactivity objects to do this – is that right?  I have tried a couple of approaches and cannot get it to work properly.  What is the “right” way to achieve this, if it can be done?  Thanks.

    Imported from legacy forums. Posted by Steve (had 3841 views)

    User (Old forums)
    Member
    Post count: 23064

    Well, I’ve sort of got this to work.  What I’m doing is disabling the DataCursor object that handles the MouseMove when the second one detects DragStart.  Then on DragEnd I re-enable the first one again.  This works – so far so good.

    But – in order to translate mouse positions to axis values I am using the MapClientPointToModelPlane method, passing it the axes in effect plus points created from the DragStart and DragEnd positions.  The values I am getting back in the Vector objects are not sensible values.

    In the DragStart/DragEnd events I cast the Eventargs argument to DragEventArgs and extract the X and Y values from them.  These are then passed to the MapClientPointToModelPlane method.  In my case it is the X-axis values I am interested in, and my X-axis is using the Logarithmic scalemode – could that be a problem? I’ve tried treating the returned values as logs, but that doesn’t give sensible results either.

    Imported from legacy forums. Posted by Steve (had 542 views)

    User (Old forums)
    Member
    Post count: 23064

    You need to do one more conversion.  Once you get the Model coordinates, you need to convert them to Scale coordinates,

    Use the ConvertModelToScaleCoordinate() method to accomplish this.

    I suggest you read the following topic in our help documentation that explains in details how the different conversions work :

    http://doc.xceedsoft.com/products/XceedChart/Converting_Chart_Coordinates.html

    Specifically, look at the last topic on the page “Converting from model to scale coordinates” to see what is required.

     

    Imported from legacy forums. Posted by André (had 323 views)

    User (Old forums)
    Member
    Post count: 23064

    Thanks Andre, I looked at the article and it all makes very good sense.  But I must be missing something, because I still can’t get meaningful values.  I can see the client X/Y mouse positions being different, but after the 2 conversions, I always end up with the same X-value – to 12 decimal places!  X1 and X2 always end up as 8.4771212547196626 – not even in my X-axis range.
    In my test case my X axis scale runs from 30000000 to 300000000 (30 million to 300 million) and is logarithmic.

    Here is my MouseDown and MouseUp code – note that some of the variables (X1, X2, vec1, vec2) are declared at form level.

    Private Sub chtGraph_MouseDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles chtGraph.MouseDown

    Dim hAxis As Axis, vAxis As Axis, dAxis As Axis
    Dim pt = New Point(e.X, e.Y)

    With chtGraph.Charts(0)
      hAxis = .Axis(StandardAxis.PrimaryX)
      vAxis = .Axis(StandardAxis.PrimaryY)
      dAxis = .Axis(StandardAxis.Depth)
      If .MapClientPointToModelPlane(hAxis, vAxis, dAxis, 0, pt, vec1) Then
        X1 = hAxis.ConvertModelToScaleCoordinate(vec1.x, True)
      Else
        X1 = Double.NaN   ‘ indicate that we couldn’t determine position
      End If
    End With

    End Sub

     

    Private Sub chtGraph_MouseUp(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles chtGraph.MouseUp

    Dim dDiff As Double
    Dim hAxis As Axis, vAxis As Axis, dAxis As Axis

    Cursor = Cursors.Default

    Dim pt = New Point(e.X, e.Y)
    With chtGraph.Charts(0)
      hAxis = .Axis(StandardAxis.PrimaryX)
      vAxis = .Axis(StandardAxis.PrimaryY)
      dAxis = .Axis(StandardAxis.Depth)
      If Not Double.IsNaN(X1) Then    ‘  mousedown position was valid
        If .MapClientPointToModelPlane(hAxis, vAxis, dAxis, 0, pt, vec2) Then
          X2 = hAxis.ConvertModelToScaleCoordinate(vec2.x, True)
          dDiff = Math.Abs(X2 – X1)
          If dDiff <> 0 Then MsgBox(“Frequency difference is “ & dDiff.ToString(“#0.000000”) & “MHz”, MsgBoxStyle.Information, “QDL Viewer”)
        End If
      End If
    End With

    End Sub

    This isn’t identical to the code in the article, but its effect should be the same as far as I can see.  But clearly something is not right – probably something quite obvious! I don’t mind feeling stupid if I can get the result I want.  Thanks.

    Imported from legacy forums. Posted by Steve (had 449 views)

    User (Old forums)
    Member
    Post count: 23064

    I have found the solution. I changed the 2nd arguments to my ConvertModelToScaleCoordinate calls from True to False, and now all is perfect!  This is the ClampToRuler parameter, and I have to confess I do not have a clear understanding of what it is about – it appears elsewhere in method calls and as a property.  But anyway, I now have my result.  Hope this might help someone else too.

    Imported from legacy forums. Posted by Steve (had 4340 views)

Viewing 5 posts - 1 through 5 (of 5 total)
  • You must be logged in to reply to this topic.