Page 1 of 1

NearestPoint.Point = -1

Posted: Thu May 12, 2011 2:17 pm
by 15659035
Hi,

What will make NearestPoint.Point equals -1?

In my
Steema.TeeChart.Tools.NearestPoint Change
event handler most of my series works perfect, but for some series NearestPoint.Point always = -1
Also NearestPoint.GetNearestPoint(cursorPosition); returns -1.

My event handler look like this:

Code: Select all

private Steema.TeeChart.Tools.NearestPoint tNearestPoint;
private EventHandler _steemaTeeChartToolsNearestPointEventHandler = null;
_steemaTeeChartToolsNearestPointEventHandler = new EventHandler(tNearestPoint_Change);

tNearestPoint.Change += _steemaTeeChartToolsNearestPointEventHandler;

private void tNearestPoint_Change(object sender, EventArgs e)
{
    try
    {
        if (NearestPointChangeDelegate != null)
        {
            if (tNearestPoint.Point != -1)
            {
                NearestPointChangeEventArgs nearestPointChangeEventArgs = new NearestPointChangeEventArgs(
                    tNearestPoint.Series.XValues[tNearestPoint.Point],
                    tNearestPoint.Series.YValues[tNearestPoint.Point]);

                NearestPointChangeDelegate(this, nearestPointChangeEventArgs);
            }
            else
            {
                Point cursorPosition = ((System.Windows.Forms.Control)Chart).PointToClient(System.Windows.Forms.Cursor.Position);

                int point = tNearestPoint.GetNearestPoint(cursorPosition); //Also always = -1;
            }
        }
    }
    catch (Exception ex)
    {
        Ellab.Debug.GlobalDebug.debugForm.WriteText(ex);
    }
}
Thanks a lot in advance
Christian

Re: NearestPoint.Point = -1

Posted: Fri May 13, 2011 10:10 am
by 10050769
Hello Christian,

I couldn't reproduce your problem using next code:

Code: Select all

  Steema.TeeChart.Styles.Points point,point1;
        Steema.TeeChart.Tools.NearestPoint nearest1;
        private void InitializeChart()
        {
            point = new Steema.TeeChart.Styles.Points(tChart1.Chart);
            point1 = new Steema.TeeChart.Styles.Points(tChart1.Chart);
            nearest1 = new Steema.TeeChart.Tools.NearestPoint(tChart1.Chart);
            point.FillSampleValues();
            nearest1.Series = this.point;
            point1.FillSampleValues();
            nearest1.Change += new EventHandler(nearest1_Change);

        }

        void nearest1_Change(object sender, EventArgs e)
        {
            if (nearest1.Point != -1)
            {
                this.Text = nearest1.Point.ToString();
            }
        }
Please, could you tell us if you can reproduce your problem using previous code? And if your problem doesn't appears in using previous code please send us a simple project that we can reproduce exactly your problem.

Thanks,

Re: NearestPoint.Point = -1

Posted: Mon May 16, 2011 10:25 am
by 15659035
Hi Sandra,

Sorry for the confusion, but my question is simply:
In what conditions will NearestPoint.GetNearestPoint(...) return -1?

Thanks a lot in advance.
Christian

Re: NearestPoint.Point = -1

Posted: Tue May 17, 2011 11:03 am
by yeray
Hello Christian,
CKBN wrote:In what conditions will NearestPoint.GetNearestPoint(...) return -1?
When the series linked to the tool has no points or when the points in the series are out of the axes range.
I don't see any other situation where it could return -1. However, feel free to study the function yourself (you can use RedGate's Reflector to read the TeeChart.dll via reflection if you are not a source code customer).

Re: NearestPoint.Point = -1

Posted: Tue May 17, 2011 11:15 am
by 15659035
Hi Yeray,

Thanks a lot. That gives me some better debug capabilities. I’m sure that the error is in my code. :shock:
Also, thanks for the tip about the RedGate's Reflector tool. I’ll definitely give it a try.

BR,
Christian

Re: NearestPoint.Point = -1

Posted: Tue May 17, 2011 3:37 pm
by yeray
Hi Christian,

I'm happy to hear that :D
If you think you find a bug in TeeChart's code, don't hesitate to let us know.