Howto calculate point index(es) using definite Xvalue

TeeChart for Microsoft Visual Studio .NET, Xamarin Studio (Android, iOS & Forms) & Monodevelop.
Post Reply
bairog
Newbie
Newbie
Posts: 72
Joined: Fri Jul 07, 2006 12:00 am
Location: Moscow, Russia
Contact:

Howto calculate point index(es) using definite Xvalue

Post by bairog » Fri Apr 24, 2009 11:31 am

I'm looking for function that returns point index(es) having definite Xvalue.
I mean something like

Code: Select all

int[] Indexes TeeChart.Series.CalcIndexForXValue(double XValue)
Is there such a function or I will have to use foreach instead?

BTW I'm using line series if it's matter.
Thank you.

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 Apr 24, 2009 11:40 am

Hi bairog,

You can use IndexOf as I explained here:

http://www.teechart.net/support/viewtop ... ht=indexof
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

bairog
Newbie
Newbie
Posts: 72
Joined: Fri Jul 07, 2006 12:00 am
Location: Moscow, Russia
Contact:

Post by bairog » Fri Apr 24, 2009 4:42 pm

narcis wrote:Hi bairog,
You can use IndexOf as I explained here:
http://www.teechart.net/support/viewtop ... ht=indexof
It is not exactly what I wanted because IndexOf returns only the first point index. If I have for example

Code: Select all

line1.Add(1, 1);
line1.Add(1, 0);
and than use

Code: Select all

line1.XValues.IndexOf(1)
it returns 0.
But I of course expect to get 0 and 1.

So what is the solution?
Thank you.

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

Post by Narcís » Mon Apr 27, 2009 8:40 am

Hi bairog,

In that case you can use FindAll, for example:

Code: Select all

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

		private void InitializeChart()
		{
			Steema.TeeChart.Styles.Line line1 = new Steema.TeeChart.Styles.Line(tChart1.Chart);

			line1.Add(0, 2);
			line1.Add(1, 3);
			line1.Add(1, 4);
			line1.Add(2, 5);

			double[] results = Array.FindAll(line1.XValues.Value, IsOne);
		}

		private static bool IsOne(double d)
		{
			return d == 1;
		}
Or for getting the indices you need to do that:

Code: Select all

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

		private void InitializeChart()
		{
			Steema.TeeChart.Styles.Line line1 = new Steema.TeeChart.Styles.Line(tChart1.Chart);

			line1.Add(0, 2);
			line1.Add(1, 3);
			line1.Add(1, 4);
			line1.Add(2, 5);

			System.Collections.ArrayList results = new System.Collections.ArrayList();

			for (int i = 0; i < line1.Count; i++)
			{
				if (line1.XValues[i] == 1.0)
				{
					results.Add(i);
				}
			}
		}
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