How to get mouse coordinate relative to a specific axis?

3 posts, 1 answers
  1. Unisense
    Unisense avatar
    34 posts
    Member since:
    Sep 2012

    Posted 10 Jul 2014 Link to this post

    Hi Telerik,

    I have a problem getting the correct mouse coordinates(lineSeries is a RadCartesianChart). I know how to get the coordinates:

    var mousePosition = e.GetPosition(lineSeries);
    DataTuple tuple = lineSeries.ConvertPointToData(mousePosition);

    double x = (double)tuple.FirstValue;
    double y = (double)tuple.SecondValue;

    But i have 3 axes on my graph and when i extract the mouse coordinates i get the coordinates for the wrong axes. They are defined like this:

    <telerik:RadCartesianChart.HorizontalAxis>
    <telerik:LinearAxis VerticalLocation="Bottom" Title="Concentration(µmol/L)" x:Name="HorizontalAxis"/>
    </telerik:RadCartesianChart.HorizontalAxis>

    <telerik:RadCartesianChart.VerticalAxis>
    <telerik:LinearAxis IsInverse="True" Title="Depth(µm)" x:Name="VerticalAxis"/>
    </telerik:RadCartesianChart.VerticalAxis>

    Haxis = new LinearAxis();
    Haxis.Title = "Rate (nmol cm-3 s-1)";
    Haxis.VerticalLocation = AxisVerticalLocation.Top;
    Haxis.IsInverse = true;

    I get the mouse coordinates for the horizontal axis defined in XAML but i want mouse coordinates for the horizontal axis defined in the C# code.

    So how would i extract mouse coordinates for the correct axes when i have more than two?

    Best regards,
    Jeppe
  2. Answer
    Petar Marchev
    Admin
    Petar Marchev avatar
    968 posts

    Posted 14 Jul 2014 Link to this post

    Hi Jeppe,

    First, you need to use the chart and not the series to get the proper mouse position. Then, you can use the ConvertPointToData overload, which accepts the two axes you need to get the values for, otherwise the chart's axes are used:
    var mousePosition = e.GetPosition(chart1);
    DataTuple tuple = lineSeries.ConvertPointToData(mousePosition, hAxis, vAxis);

    Regards,
    Petar Marchev
    Telerik
     
    Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
     
  3. UI for WPF is Visual Studio 2017 Ready
  4. Unisense
    Unisense avatar
    34 posts
    Member since:
    Sep 2012

    Posted 14 Jul 2014 in reply to Petar Marchev Link to this post

    Hi Petar,

    Okay thanks for the reply - it helped a lot!

    Best regards,
    Jeppe
Back to Top