Cursor precision

A forum dedicated to WinForms version of LightningChart Ultimate.

Moderator: Queue Moderators

Post Reply
0uss
Posts: 16
Joined: Mon Apr 18, 2016 5:05 pm

Cursor precision

Post by 0uss » Tue Jan 17, 2017 5:50 pm

Hello everybody,

I have a small problem of accuracy of the cursors. Here is the situation : I have a spectrum and when I use a cursor to get me the nearst point (using a mouse click) the X Axis value is correct but not the Y Axis one. The cursor is not attached to the PEAK value of my linseSerie, The first image shows the unexpected behavior. But when I zoom in (picture 2) the problem is gone. it does this to me each time I have a big number of samples displayed in the graph.

Image

Image

Here is the code I use to put the cursor on the right value. It never shows the correct spot when I don't zoom in.

Code: Select all

void m_chart_MouseClick(object sender, MouseEventArgs e)
        {
            //Find nearest point and show its values 
            try
            {
                double dXValue, dYValue;
                int iNearestIndex;

                if (m_chart.ViewXY.SampleDataSeries[0].SolveNearestSampleByCoord(e.X, e.Y, out dXValue, out dYValue, out iNearestIndex))
                {
                    m_chart.BeginUpdate();
                    LineSeriesCursor cl = m_chart.ViewXY.LineSeriesCursors[0];
                    cl.ValueAtXAxis = dXValue;
                    m_chart.EndUpdate();
                }
            }
            catch (Exception ex)
            { MessageBox.Show(ex.Message);}
        }
And here is the code I use to create the cursor :

Code: Select all

//Create main cursor
            LineSeriesCursor cl = new LineSeriesCursor(m_chart.ViewXY, m_chart.ViewXY.XAxes[0]);
            cl.Behind = true;
            cl.Visible = true;
            cl.LineStyle.Pattern = LinePattern.Dot;
            cl.LineStyle.Color = Color.Blue;
            cl.LineStyle.Width = 1;
            cl.MoveByMouse = true;
            cl.Tag = "main";
            cl.SnapToPoints = true;
            cl.PositionChanged += new LineSeriesCursor.PositionChangedHandler(cl_PositionChanged);
            m_chart.ViewXY.LineSeriesCursors.Add(cl);
I find another thread talking about this problem here : http://forum.arction.com/viewtopic.php? ... oint#p3622

I hope that I can find a solution to get more accurate cursors.
Thank you very much.

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

Re: Cursor precision

Post by ArctionPasi » Thu Jan 19, 2017 3:42 pm

Hello,

when several data points hit the same coordinate in X dimension, like in this case, it shows the tracking point as the middle point of those values.

In this case, when peak solving is required, another approach is needed:
  • Hide the tracking point from cursor: set cursor.Style = VerticalNoTracking.
  • Create a SeriesEventMarker and set its position explicitly when peak is solved: marker.VerticalPosition = AtYValue, and marker.HorizontalPosition = AtXValue, and setting XValue and YValue.
Solve the peak value pretty much like this:
  • int xCoord = (int) Math.Round(xAxis.ValueToCoord (cursor.ValueAtXAxis))
  • loop through data points and call x = (int) Math.Round(xAxis.ValueToCoord(dataPoint.X)) to all (or near cursor position). Pick the data points having same x coordinate and get maximum of them.
LightningChart Support Team, PT

0uss
Posts: 16
Joined: Mon Apr 18, 2016 5:05 pm

Re: Cursor precision

Post by 0uss » Thu Jan 19, 2017 4:14 pm

Thank you very much for the response.

Technically the points doesn't have the same X value. But the cursors tracking points are working with other coordinates.
when several data points hit the same coordinate in X dimension, like in this case, it shows the tracking point as the middle point of those values.
I will try your solution, it seems to be correct.

Thank you again for your help. Will try this out today :)

Post Reply