This is a migrated thread and some comments may be shown as answers.

How to get mouse coordinate relative to a specific axis?

2 Answers 265 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Unisense
Top achievements
Rank 1
Unisense asked on 10 Jul 2014, 10:45 AM
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 Answers, 1 is accepted

Sort by
0
Accepted
Petar Marchev
Telerik team
answered on 14 Jul 2014, 08:25 AM
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.
 
0
Unisense
Top achievements
Rank 1
answered on 14 Jul 2014, 09:04 AM
Hi Petar,

Okay thanks for the reply - it helped a lot!

Best regards,
Jeppe
Tags
General Discussions
Asked by
Unisense
Top achievements
Rank 1
Answers by
Petar Marchev
Telerik team
Unisense
Top achievements
Rank 1
Share this question
or