CursorTool hit points.

TeeChart for Microsoft Visual Studio .NET, Xamarin Studio (Android, iOS & Forms) & Monodevelop.
Post Reply
vijay
Newbie
Newbie
Posts: 42
Joined: Thu Jul 31, 2008 12:00 am
Contact:

CursorTool hit points.

Post by vijay » Thu Nov 13, 2008 6:54 am

Hi,
I want to display all cursortool hitpoints(with series) in my chart and want to show the X and Y values as annotations.

Is there any support in CursorTool ?

Thanks,
Vijay.

Narcís
Site Admin
Site Admin
Posts: 14730
Joined: Mon Jun 09, 2003 4:00 am
Location: Banyoles, Catalonia
Contact:

Post by Narcís » Thu Nov 13, 2008 11:34 am

Hi Vijay,

Yes, you can do something like this:

Code: Select all

		public Form1()
		{
			InitializeComponent();
			InitializeChart();
		}

		private Steema.TeeChart.Styles.Points points1;
		private Steema.TeeChart.Tools.Annotation annotation1;

		private void InitializeChart()
		{
			tChart1.Aspect.View3D = false;

			points1 = new Points(tChart1.Chart);
			points1.FillSampleValues();

			Steema.TeeChart.Tools.CursorTool cursor1 = new CursorTool(tChart1.Chart);
			cursor1.FollowMouse = true;
			cursor1.Series = points1;
			cursor1.Change += new CursorChangeEventHandler(cursor1_Change);

			annotation1 = new Annotation(tChart1.Chart);
		}

		

		void cursor1_Change(object sender, CursorChangeEventArgs e)
		{
			int index = points1.Clicked(e.x, e.y);

			if (index != -1)
			{
				annotation1.Text = points1.XValues[index].ToString() + " - " +
														points1.YValues[index].ToString();
				annotation1.Shape.CustomPosition = true;
				annotation1.Shape.Left = e.x;
				annotation1.Shape.Top = e.y;
				annotation1.Active = true;
			}
			else
			{
				annotation1.Active = false;
			}
		}
Also notice there's MarksTip tool which already does something like this.

If you want to use a collection of Annotation tools you can do this:

Code: Select all

		public Form1()
		{
			InitializeComponent();
			InitializeChart();
		}

		private Steema.TeeChart.Styles.Points points1;
		private Steema.TeeChart.Tools.Annotation[] annotations;

		private void InitializeChart()
		{
			tChart1.Aspect.View3D = false;

			points1 = new Points(tChart1.Chart);
			points1.FillSampleValues();

			Steema.TeeChart.Tools.CursorTool cursor1 = new CursorTool(tChart1.Chart);
			cursor1.FollowMouse = true;
			cursor1.Series = points1;
			cursor1.Change += new CursorChangeEventHandler(cursor1_Change);

			annotations = new Annotation[points1.Count];

			for (int i = 0; i < annotations.Length; i++)
			{
				annotations[i] = new Steema.TeeChart.Tools.Annotation(tChart1.Chart);
				annotations[i].Active = false;
			}
		}		

		void cursor1_Change(object sender, CursorChangeEventArgs e)
		{
			int index = points1.Clicked(e.x, e.y);

			if (index != -1)
			{
				annotations[index].Text = points1.XValues[index].ToString() + " - " +
														points1.YValues[index].ToString();
				annotations[index].Shape.CustomPosition = true;
				annotations[index].Shape.Left = e.x;
				annotations[index].Shape.Top = e.y;
				annotations[index].Active = true;
			}
		}
Hope this helps!
Best Regards,
Narcís Calvet / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Image Image Image Image Image Image
Instructions - How to post in this forum

vijay
Newbie
Newbie
Posts: 42
Joined: Thu Jul 31, 2008 12:00 am
Contact:

Post by vijay » Thu Nov 13, 2008 11:56 am

Hi Narcís,
Thank you for your help.

I have a number of series in my chart and i cannot associate CursorTool with any series.

And i tried and found the series hit points by,
DateTime tmp;
int index = tChart.Series[0].XValues.IndexOf(Math.Round(e.XValue, 0));
if (index >= 0)
{
tmp = DateTime.FromOADate(tChart.Series[0].YValues[index]);
}
and displayed the values using a RectangleTool.
But what i actually required is to display those values in something like a draggable marker.
Is it possible to implement DragMarks tool like support? So that i can drag those markers.

Thanks,
Vijay

Narcís
Site Admin
Site Admin
Posts: 14730
Joined: Mon Jun 09, 2003 4:00 am
Location: Banyoles, Catalonia
Contact:

Post by Narcís » Thu Nov 13, 2008 12:01 pm

Hi Vijay,

Ok, in that case, RectangleTool already supports dragging:

Code: Select all

			rectangle1.AllowDrag = true;
Best Regards,
Narcís Calvet / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Image Image Image Image Image Image
Instructions - How to post in this forum

vijay
Newbie
Newbie
Posts: 42
Joined: Thu Jul 31, 2008 12:00 am
Contact:

Post by vijay » Thu Nov 13, 2008 12:17 pm

That i Tried,
But to connect that hit point i want to draw line.
What method will be the best way for that.
I tried with drawlinetool. but not working?

Narcís
Site Admin
Site Admin
Posts: 14730
Joined: Mon Jun 09, 2003 4:00 am
Location: Banyoles, Catalonia
Contact:

Post by Narcís » Thu Nov 13, 2008 12:23 pm

Hi Vijay,

You can use RectangleTool's Callout and Arrow properties as shown for Annotation tool in the examples here:

http://www.teechart.net/support/viewtopic.php?t=8568
http://www.teechart.net/support/viewtopic.php?t=5786

Hope this helps!
Best Regards,
Narcís Calvet / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Image Image Image Image Image Image
Instructions - How to post in this forum

vijay
Newbie
Newbie
Posts: 42
Joined: Thu Jul 31, 2008 12:00 am
Contact:

Post by vijay » Fri Nov 14, 2008 6:36 am

Hi,
I tried a lot to draw a line between my rectangle tool and the cursor tool hit point. But i don know how to do that. I tried with rectangletool.Callout, but no way :(

Narcís
Site Admin
Site Admin
Posts: 14730
Joined: Mon Jun 09, 2003 4:00 am
Location: Banyoles, Catalonia
Contact:

Post by Narcís » Fri Nov 14, 2008 8:36 am

Hi vijay,

Try this:

Code: Select all

		public Form1()
		{
			InitializeComponent();
			InitializeChart();
		}

		private Steema.TeeChart.Styles.Points points1;
		private Steema.TeeChart.Tools.RectangleTool rectangle1;

		private void InitializeChart()
		{
			tChart1.Aspect.View3D = false;

			points1 = new Steema.TeeChart.Styles.Points(tChart1.Chart);
			points1.FillSampleValues();

			Steema.TeeChart.Tools.CursorTool cursor1 = new Steema.TeeChart.Tools.CursorTool(tChart1.Chart);
			cursor1.FollowMouse = true;
			cursor1.Series = points1;
			cursor1.Change += new Steema.TeeChart.Tools.CursorChangeEventHandler(cursor1_Change);

			rectangle1 = new Steema.TeeChart.Tools.RectangleTool(tChart1.Chart);
			rectangle1.AutoSize = true;
		}

		void cursor1_Change(object sender, Steema.TeeChart.Tools.CursorChangeEventArgs e)
		{
			int index = points1.Clicked(e.x, e.y);

			if (index != -1)
			{
				rectangle1.Text = points1.XValues[index].ToString() + " - " +
																			points1.YValues[index].ToString();
				rectangle1.Shape.CustomPosition = true;
				rectangle1.Shape.Left = e.x + 30;
				rectangle1.Shape.Top = e.y - 30;
				//rectangle1.Callout.Visible = true; //This plots arrow's pointer.
				rectangle1.Callout.Arrow.Visible = true;
				rectangle1.Callout.Arrow.Color = Color.Black;
				rectangle1.Callout.XPosition = e.x;
				rectangle1.Callout.YPosition = e.y;
				rectangle1.Active = true;
			}
			else
			{
				rectangle1.Active = false;
			}
		}
Best Regards,
Narcís Calvet / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Image Image Image Image Image Image
Instructions - How to post in this forum

vijay
Newbie
Newbie
Posts: 42
Joined: Thu Jul 31, 2008 12:00 am
Contact:

Post by vijay » Fri Nov 14, 2008 9:02 am

Thanks Narcís,
I forgot to set rectangletool.Arrow.Visible=true;


The re-size and zoom operations will detach the rectangle tool from the cursor tool.
does zoom-in event is available in tChart?

Narcís
Site Admin
Site Admin
Posts: 14730
Joined: Mon Jun 09, 2003 4:00 am
Location: Banyoles, Catalonia
Contact:

Post by Narcís » Fri Nov 14, 2008 9:05 am

Hi vijay,

Yes, but you'll need to update Rectangle's positions in the Zoomed, UndoneZoom and Scroll events. For example:

http://www.teechart.net/support/viewtopic.php?t=8568
Best Regards,
Narcís Calvet / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Image Image Image Image Image Image
Instructions - How to post in this forum

Post Reply