IndexOutOfRangeException from Series.CalcXPos

TeeChart for Microsoft Visual Studio .NET, Xamarin Studio (Android, iOS & Forms) & Monodevelop.
Post Reply
anton dizhur
Newbie
Newbie
Posts: 6
Joined: Wed May 26, 2004 4:00 am
Location: New York

IndexOutOfRangeException from Series.CalcXPos

Post by anton dizhur » Thu Nov 03, 2005 7:14 pm

I get the following runtime error with stack trace. My app is handling MouseEnter/Leave events for Bar and Line.

Any idea what is going on?

See the end of this message for details on invoking
just-in-time (JIT) debugging instead of this dialog box.

************** Exception Text **************
System.IndexOutOfRangeException: Index was outside the bounds of the array.
at Steema.TeeChart.Styles.Series.CalcXPos(Int32 index)
at Steema.TeeChart.Styles.CustomPoint.CalcXPos(Int32 valueIndex)
at Steema.TeeChart.Styles.CustomPoint.Clicked(Int32 x, Int32 y)
at Steema.TeeChart.Styles.Custom.Clicked(Int32 x, Int32 y)
at Steema.TeeChart.Styles.Series.CheckMouse(Cursor& c, Int32 x, Int32 y)
at Steema.TeeChart.Chart.CheckMouseSeries(Cursor& c, Int32 X, Int32 Y)
at Steema.TeeChart.Chart.DoMouseMove(Int32 x, Int32 y, Cursor& c)
at Steema.TeeChart.TChart.OnMouseMove(MouseEventArgs e)
at System.Windows.Forms.Control.WmMouseMove(Message& m)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)

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 04, 2005 11:46 am

Hi Anthon,

Could you please send us some code or an example we can run "as-is" to reproduce the problem here? You can post your files at [url]news://www.steema.net/steema.public.attachments[/url] newsgroup.
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

anton dizhur
Newbie
Newbie
Posts: 6
Joined: Wed May 26, 2004 4:00 am
Location: New York

Post by anton dizhur » Fri Nov 04, 2005 4:00 pm

This error happened randomly. Not sure how to reproduce it. I was hoping you can check the implementation to figure out some clue for me.

My app displays six charts. One of them has bar chart and the rest have just lines. We track the MoveEnter/Leave events to show a popup label with the tile of each line (or bar). This is the code segment:

For bar chart:
bar_SellSide.MouseEnter += new EventHandler(bar_MouseEnter);
bar_SellSide.MouseLeave += new EventHandler(bar_MouseLeave);

bar_BuySide.MouseEnter += new EventHandler(bar_MouseEnter);
bar_BuySide.MouseLeave += new EventHandler(bar_MouseLeave);

bar_Benchmark.MouseEnter += new EventHandler(bar_MouseEnter);
bar_Benchmark.MouseLeave += new EventHandler(bar_MouseLeave);

private void bar_MouseLeave(object sender, System.EventArgs e)
{
label1.Visible = false;
}

private void bar_MouseEnter(object sender, System.EventArgs e)
{
try
{
Point cursorLoc = Sector_Info.PointToClient(Cursor.Position);
int idx = ((Steema.TeeChart.Styles.Bar)sender).Clicked(cursorLoc);
string textInfo = ((Steema.TeeChart.Styles.Bar)sender).Labels[idx];

label1.Text = textInfo;
Graphics g = label1.CreateGraphics();
SizeF txtSize = g.MeasureString(textInfo, label1.Font);
label1.Size = new Size ((int)(txtSize.Width + 4), (int)(txtSize.Height + 4));
g.Dispose();

label1.Top = Sector_Info.Top + cursorLoc.Y - label1.Height;
label1.Left = Sector_Info.Left + cursorLoc.X - label1.Width / 2;

label1.BringToFront();
label1.Visible = true;
}
catch (Exception)
{
}
}


For line chart:

line_Beta.MouseEnter += new EventHandler(line_MouseEnter);
line_Beta.MouseLeave += new EventHandler(line_MouseLeave);

line_BuyBeta.MouseEnter += new EventHandler(line_MouseEnter);
line_BuyBeta.MouseLeave += new EventHandler(line_MouseLeave);

line_SellBeta.MouseEnter += new EventHandler(line_MouseEnter);
line_SellBeta.MouseLeave += new EventHandler(line_MouseLeave);

private void line_MouseLeave(object sender, System.EventArgs e)
{
label1.Visible = false;
}

private void line_MouseEnter(object sender, System.EventArgs e)
{
try
{
Point cursorLoc = Beta.PointToClient(Cursor.Position);
string textInfo = ((Steema.TeeChart.Styles.Line)sender).Title;

label1.Text = textInfo;
Graphics g = label1.CreateGraphics();
SizeF txtSize = g.MeasureString(textInfo, label1.Font);
label1.Size = new Size ((int)(txtSize.Width + 4), (int)(txtSize.Height + 4));
g.Dispose();

label1.Top = Beta.Top + cursorLoc.Y - label1.Height;
label1.Left = Beta.Left + cursorLoc.X - label1.Width / 2;

label1.BringToFront();
label1.Visible = true;
}
catch (Exception)
{
}
}


Thanks for the help.

Christopher
Site Admin
Site Admin
Posts: 1349
Joined: Thu Jan 01, 1970 12:00 am
Location: Riudellots de la Selva, Catalonia
Contact:

Post by Christopher » Tue Nov 08, 2005 4:06 pm

Hi,

Having looked at your code with the TeeChart source I think you'd be better off using the following:

Code: Select all

		private void tChart1_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e)
		{
			Point cursorLoc;
			Steema.TeeChart.Styles.Series series;
			string textInfo = "";
			int idx = -1;
			cursorLoc = new Point(e.X, e.Y);

			for(int i = 0; i < tChart1.Series.Count; ++i) 
			{
				series = tChart1[i];
				idx = series.Clicked(cursorLoc); 
				if(idx != -1) 
				{

					if(series is Steema.TeeChart.Styles.Bar) 
						textInfo = ((Steema.TeeChart.Styles.Bar)series)[idx].Label;
					else if(series is Steema.TeeChart.Styles.Line)
						textInfo = ((Steema.TeeChart.Styles.Line)series).Title; 

					label1.Text = textInfo; 
					Graphics g = label1.CreateGraphics(); 
					SizeF txtSize = g.MeasureString(textInfo, label1.Font); 
					label1.Size = new Size ((int)(txtSize.Width + 4), (int)(txtSize.Height + 4)); 
					g.Dispose(); 

					label1.Top = this.Top + cursorLoc.Y - label1.Height; 
					label1.Left = this.Left + cursorLoc.X - label1.Width / 2; 

					label1.BringToFront(); 
					label1.Visible = true; 
				}
			}
		}
You might also consider using an Steema.TeeChart.Tools.Annotation instead of the System.Windows.Forms.Label.
Thank you!

Christopher Ireland (Steema crew)
Please be aware of the newsgroup archives:
http://www.teechart.net/support/search.php
http://groups.google.com
http://codenewsfast.com/

anton dizhur
Newbie
Newbie
Posts: 6
Joined: Wed May 26, 2004 4:00 am
Location: New York

Post by anton dizhur » Wed Nov 23, 2005 4:56 pm

Hi,

Are you saying I have to switch to MouseMove event? When should I hide the label?

Thanks,

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 24, 2005 12:31 pm

Hi anton dizhur,

I don't have to switch, it's just a suggestion. You can hide the label when you want.
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