Page 1 of 1

IndexOutOfRangeException from Series.CalcXPos

Posted: Thu Nov 03, 2005 7:14 pm
by 8125625
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)

Posted: Fri Nov 04, 2005 11:46 am
by narcis
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.

Posted: Fri Nov 04, 2005 4:00 pm
by 8125625
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.

Posted: Tue Nov 08, 2005 4:06 pm
by Chris
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.

Posted: Wed Nov 23, 2005 4:56 pm
by 8125625
Hi,

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

Thanks,

Posted: Thu Nov 24, 2005 12:31 pm
by narcis
Hi anton dizhur,

I don't have to switch, it's just a suggestion. You can hide the label when you want.