Converting screen coordinates into axis values

A forum dedicated to WPF version of LightningChart Ultimate.

Moderator: Arction_LasseP

SupportArchives
Posts: 16
Joined: Tue Mar 26, 2013 11:01 pm

Converting screen coordinates into axis values

Post by SupportArchives » Wed Apr 17, 2013 1:25 pm

I'm using ViewXY cartesian chart. I'd like to get the X and Y axis values under the mouse, not the screen coordinates. How ?

User avatar
ArctionPasi
Posts: 1366
Joined: Tue Mar 26, 2013 10:57 pm
Location: Finland

Re: Converting screen coordinates into axis values

Post by ArctionPasi » Wed Apr 17, 2013 1:30 pm

If you define MouseMove, MouseDown or MouseUp events, you can use the screen coordinates to xAxis.CoordToValue() and yAxis.CoordToValue. They will give you the click value as X and Y axis values.

For example, MouseDown:

Code: Select all

void m_chart_MouseDown(object sender, System.Windows.Input.MouseButtonEventArgs e)
{
            Point pnScreen = e.GetPosition(m_chart);
            double x, y;
            m_chart.ViewXY.XAxes[0].CoordToValue((int)pnScreen.X, out x, false); 
            m_chart.ViewXY.YAxes[0].CoordToValue((int)pnScreen.Y, out y); 

            //x and y have the axis values now
 }
LightningChart Support Team, PT