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

Mouse position -> data -> position are not the same values

1 Answer 45 Views
Chart
This is a migrated thread and some comments may be shown as answers.
Martin
Top achievements
Rank 1
Martin asked on 22 Jul 2013, 09:06 AM

hi

I have used your cross-hair example but trying to extend it and having issues

I boiled it down to the code example below

1) Get a mouse position
2) Get the data representing that position
3) For that data, get the mouse position

how can these return different values?

regards
martin

            var plotAreaPanel = sender as ClipPanel;
            var mousePosition = e.GetPosition(plotAreaPanel);
           
            var dataAtMouse = _Chart.DefaultView.ChartArea.AxisX.ConvertPhysicalUnitsToData(mousePosition.X);
            var physicalAtMouse = _Chart.DefaultView.ChartArea.AxisX.ConvertDataUnitsToPhysical(dataAtMouse);

            if (mousePosition.X != physicalAtMouse)
            {
                Debug.Assert(false, "Should never happen");
            }

1 Answer, 1 is accepted

Sort by
0
Petar Kirov
Telerik team
answered on 24 Jul 2013, 02:00 PM
Hi Martin,

This is a known issue. It is logged here in our Public Issue Tracker. Presently you can can workaround it the following way: 
var dataX = this.chart.DefaultView.ChartArea.AxisX.ConvertPhysicalUnitsToData(position.X);
var dataY = this.chart.DefaultView.ChartArea.AxisY.ConvertPhysicalUnitsToData(position.Y);
 
double xMin = _Chart.DefaultView.ChartArea.AxisX.ActualMinValue;
double yMax = _Chart.DefaultView.ChartArea.AxisY.ActualMaxValue;
 
var physicalX = this.chart.DefaultView.ChartArea.AxisX.ConvertDataUnitsToPhysical(dataX - xMin);
var physicalY = this.chart.DefaultView.ChartArea.AxisY.ConvertDataUnitsToPhysical(yMax - dataY);

Please note that, due to the nature of floating-point calculations,  physicalX/Y will be very close to poistion.X/Y but probably will not be equal. The error should be smaller than 10^-3. 

On as side note, you may be interested in reviewing our newer charting solution - RadChartView (represented by the RadCartesianChart, RadPolarChart and RadPieChart classes). The new control was built from the ground-up to provide significantly better performance, easy to use API and support for implicit styles. Additionally RadCartesianChart provides a built-in customizable Crosshair behavior which you can see in this online demo. A sample project demonstrating the feature is also available here in our XAML SDK on GitHub.

I hope you will find the RadChartView suitable for your project.

Regards,
Petar Kirov
Telerik
TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WPF.
Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
Sign up for Free application insights >>
Tags
Chart
Asked by
Martin
Top achievements
Rank 1
Answers by
Petar Kirov
Telerik team
Share this question
or