TeeChart for Microsoft Visual Studio .NET, Xamarin Studio (Android, iOS & Forms) & Monodevelop.
-
rperkins
- Newbie
- Posts: 58
- Joined: Wed May 26, 2004 4:00 am
Post
by rperkins » Fri Aug 31, 2007 8:01 pm
Hello everyone. I have the trial version of the TeeChart .Net controls (getting ready to switch from VCL) and have run into a problem. I have a chart with a series and a CursorTool that I want to use to select the nearest point in the series. If I turn the Snap property to true, it works fine with the vertical line snapping to the nearest series as I move the cursor across the chart. But when I set Snap to false and programmatically call chartTool1.SnapToPoint(), nothing happens and the return value of SnapToPoint is always -1.
Here's the function I wrote to do this.
Code: Select all
private void tChart_MouseUp(object sender, MouseEventArgs e)
{
// use: handle when the user lets go of the mouse button
// inputs:
// returns:
// none
// if the user is not zooming and using the left button, snap-to and select the nearest data point
if ((!zooming)&&(e.Button == MouseButtons.Left))
{
cursorTool1.SnapToPoint();
lblSelectedDate.Text = cursorTool1.XValue.ToString();
colorLine3.Value = cursorTool1.XValue;
}
else
{
cursorTool1.Active = true;
zooming = false;
}
Can anyone think of what I might be doing wrong?
Thanks,
Randall
-
Narcís
- Site Admin
- Posts: 14730
- Joined: Mon Jun 09, 2003 4:00 am
- Location: Banyoles, Catalonia
-
Contact:
Post
by Narcís » Mon Sep 03, 2007 7:54 am
Hi Randall,
Have you set CursorTool's series? As SnapToPoint can only be used when series property is not null, otherwise the result will be always -1.
-
rperkins
- Newbie
- Posts: 58
- Joined: Wed May 26, 2004 4:00 am
Post
by rperkins » Tue Sep 04, 2007 3:05 pm
Hello Narcis,
Yes, I do have the CursorTool series set to one of the point series on the chart. I've tried setting it other series on the same chart with the same result. I also set the CursorTool's series property in the code just before calling the SnapToPoint method and it doesn't seem to have any effect either.
Again, setting the CursorTool's Snap property to true seems to work fine. From there if set Snap to false and call SnapToPoint(), it does nothing and returns a -1.
Any other ideas what I may be doing (or not doing)?
Thanks,
Randy
-
Narcís
- Site Admin
- Posts: 14730
- Joined: Mon Jun 09, 2003 4:00 am
- Location: Banyoles, Catalonia
-
Contact:
Post
by Narcís » Tue Sep 04, 2007 3:23 pm
Hi Randy,
Thanks for the information. Could you please send us a simple example project we can run "as-is" to reproduce the problem here?
You can either post your files at news://
www.steema.net/steema.public.attachments newsgroup or at our
upload page.
Thanks in advance.
-
rperkins
- Newbie
- Posts: 58
- Joined: Wed May 26, 2004 4:00 am
Post
by rperkins » Tue Sep 04, 2007 4:15 pm
Hello again Narcis,
I created a simple application in Visual Studio 2005 that demonstrates the problem I'm having and uploaded it to your upload page. In the application, I'm displaying the current XValue of the CursorTool as it's moving, the XValue after calling SnapToPoint and the return value of the SnapToPoint method.
Thank you again,
Randy
-
Narcís
- Site Admin
- Posts: 14730
- Joined: Mon Jun 09, 2003 4:00 am
- Location: Banyoles, Catalonia
-
Contact:
Post
by Narcís » Wed Sep 05, 2007 7:45 am
Hi Randy,
Thanks for the example project. Sorry, my bad, now I've checked that at the SnapToPoint implementation it only works when Snap=true. In that case, you can set Snap=true call SnapToPoint and set Snap=false again. Something like this:
Code: Select all
private void tChart1_Click(object sender, EventArgs e)
{
// use: show the x value and the return value when SnapToPoint is called
cursorTool1.Snap = true;
int returnVal = cursorTool1.SnapToPoint();
lblReturn.Text = returnVal.ToString();
lblAfter.Text = cursorTool1.XValue.ToString();
// mark the cursorTool.XValue to highlight
colorLine1.Value = cursorTool1.XValue;
cursorTool1.Snap = false;
}
-
rperkins
- Newbie
- Posts: 58
- Joined: Wed May 26, 2004 4:00 am
Post
by rperkins » Wed Sep 05, 2007 2:07 pm
Hi Narcis,
That works perfectly. Thank you so much for all of your help with this issue.
Have a great day,
Randy
-
Narcís
- Site Admin
- Posts: 14730
- Joined: Mon Jun 09, 2003 4:00 am
- Location: Banyoles, Catalonia
-
Contact:
Post
by Narcís » Wed Sep 05, 2007 2:09 pm
Hi Randy,
You're very welcome! I'm glad to hear that helped.
Thanks and have a nice day too.