Exception when using ColorGrid

TeeChart for Microsoft Visual Studio .NET, Xamarin Studio (Android, iOS & Forms) & Monodevelop.
Post Reply
Ketil
Newbie
Newbie
Posts: 1
Joined: Tue Sep 19, 2006 12:00 am

Exception when using ColorGrid

Post by Ketil » Thu Sep 28, 2006 5:42 pm

I want to populate a ColorGrid with some measured data and I use the following code to populate it, as described in an earlier post.

Code: Select all

int k = _result.Wall.Length * _result.Wall[0].Length;
double[] x = new double[k];
double[] y = new double[k];
double[] z = new double[k];
int counter = 0;
 for (int m = 0; m < _result.Wall.Length; ++m)
{
      for (int n = 0; n < _result.Wall[m].Length; ++n)
      {
           x[counter] = _result.Alpha[n];
           y[counter] = _result.Wall[m][n];
           z[counter] = _result.WallX[m];
           ++counter;
       }
}
colorGrid.Add(x, y, z);
_graphs[i].Series.Add(colorGrid);
All my arrays contain data points in the range 0 <= x < Double.Max
and data sets are less than 2000 x 2000 points. In fact my current set is only 10 x 10.

When drawing the ColorGrid I get the following exception:
System.IndexOutOfRangeException was unhandled
Message="Index was outside the bounds of the array."
Source="TeeChart"
StackTrace:
at Steema.TeeChart.Styles.ValueList.get_Item(Int32 index)
at Steema.TeeChart.Styles.ColorGrid.DrawGrid(Rectangle r)
at Steema.TeeChart.Styles.ColorGrid.Draw()
at Steema.TeeChart.Styles.Series.DrawSeries()
at Steema.TeeChart.Chart.InternalDraw(Graphics g, Boolean noTools)
at Steema.TeeChart.Chart.InternalDraw(Graphics g)
at Steema.TeeChart.TChart.Draw(Graphics g)
at Steema.TeeChart.TChart.OnPaint(PaintEventArgs pe)
at System.Windows.Forms.Control.PaintWithErrorHandling(PaintEventArgs e, Int16 layer, Boolean disposeEventArgs)
at System.Windows.Forms.Control.WmPaint(Message& m)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.Run(Form mainForm)
at Client.Program.Main(String[] args) in C:\Work\Vanadium\ScalarGauge-C\Client\Program.cs:line 40
at System.AppDomain.nExecuteAssembly(Assembly assembly, String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()

I found the following code in a previous thread.

Code: Select all

Random rnd = new Random();
double[] x = new double[36];
double[] y = new double[36];
double[] z = new double[36];
int count = 0;

for (double m = 0; m < 6; ++m)
{
         for (double n = 0; n < 6; ++n)
         {
                 x[count] = n;
                 z[count] = m;
                 y[count] = rnd.Next(3);
                 ++count;
         }
}
colorGrid.Add(x, y, z);
I have no problems running this...

Can anyone explain what is going wrong?

Marjan
Site Admin
Site Admin
Posts: 745
Joined: Fri Nov 07, 2003 5:00 am
Location: Slovenia
Contact:

Post by Marjan » Fri Sep 29, 2006 8:00 am

Hi.

First thing to do is check if each "row" has the same number of elements i.e. if _result.Wall[m].Length are the same for all m's. Colorgrid will work correctly only if x,y is a 2D grid where all rows have the same number of columns. If this is not the case, you'll have to create missing values (interpolation,...).
Marjan Slatinek,
http://www.steema.com

Adrian
Advanced
Posts: 116
Joined: Thu Jun 23, 2005 4:00 am

Post by Adrian » Fri Nov 10, 2006 6:37 am

Hi there
I'm having the same problem... I understand what is occuring (different number of elements etc.) however I cannot find any way to trap the error. It appears to happen when the chart is being drawn and results in the error being trapped in my highest level error trap. Is there anyway I can trap the error in the window containing the TCHART component.

Also, Can I suggest that the colour grid be modified to allow different numbers of elements...

Cheers.
Adrian Heald
Captell Developments
www.captelldevelopments.com

Adrian
Advanced
Posts: 116
Joined: Thu Jun 23, 2005 4:00 am

Post by Adrian » Fri Nov 10, 2006 7:16 am

On second thoughts I don't know whats happening.

I have some data

X,Y,Z
1,1,1
2,1,2
1,2,3
2,2,4

this works fine I hend up with a 2 X 2 grid with values 1 to 4

If I change my data to
X,Y,Z
10,10,10
20,10,20
10,20,30
20,20,40

it crashes!!!!
Adrian Heald
Captell Developments
www.captelldevelopments.com

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 10, 2006 11:54 am

Hi Adrian,

This is because you need to set IrregularGrid property to true:

Code: Select all

			colorGrid1.IrregularGrid = true;

			colorGrid1.Add(10, 10, 10);
			colorGrid1.Add(10, 20, 20);
			colorGrid1.Add(20, 30, 10);
			colorGrid1.Add(20, 40, 20);	
This property needs to be used when x and z values are not equidistant or its increment is not one.
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

Adrian
Advanced
Posts: 116
Joined: Thu Jun 23, 2005 4:00 am

Post by Adrian » Fri Nov 10, 2006 11:08 pm

Hi there,
I've tried the IrregularGrid = True property.

Firstly if my data is
X,Y,Z
1,1,1
2,1,2
1,2,3
2,2,4

with IrregularGrid = True nothing is drawn on the chart until I set IrregularGrid = False.

Secondly if my data is
X,Y,Z
10,10,10
20,10,20
10,20,30
20,20,40

Nothing is drawn on the chart until I set IrregularGrid = False.
at which time I can see the painting of the chart starting then it crashes and I end up with a red X through the chart surface.

And thirdly the error that is thrown is not trapable.

Any ideas?


The chart doesn't show anything and I have to set IrregularGrid =false.

Secondly
Adrian Heald
Captell Developments
www.captelldevelopments.com

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 Nov 13, 2006 9:38 am

Hi Adrian,

For the first set of data you should use IrregularGrid=false while for the second set of data you should use IrregularGrid=true as shown in my code snippet. My example works fine here using the latest TeeChart version available at the client area. Which TeeChart version are you using?
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

Adrian
Advanced
Posts: 116
Joined: Thu Jun 23, 2005 4:00 am

Post by Adrian » Wed Nov 15, 2006 7:20 am

I'm using version 2.0.2489.20950 which I believe is the latest.

With the second set of data

X,Y,Z
10,10,10
20,10,20
10,20,30
20,20,40

I get
Image

if I have irregular grid turned on... i.e. no image

then if I turn irregular grid off I get

Image
Adrian Heald
Captell Developments
www.captelldevelopments.com

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 » Wed Nov 15, 2006 2:28 pm

Hello Adrian,

I guess we can sum up your issue by saying that this code works:

Code: Select all

private void InitializeChart()
		{
			ColorGrid colorGrid1 = new ColorGrid(tChart1.Chart);

			tChart1.Aspect.View3D = false;
			colorGrid1.IrregularGrid = false;
			int y = 10;
			int z = 0, x = 0;
			for (int i = 1; i <= 2; ++i)
			{
				z = i * 1;
				for (int j = 1; j <= 2; ++j)
				{
					x = j * 1;
					colorGrid1.Add(x, y, z);
					y += 10;
				}
			}
		}
whereas this code doesn't:

Code: Select all

private void InitializeChart()
		{
			ColorGrid colorGrid1 = new ColorGrid(tChart1.Chart);

			tChart1.Aspect.View3D = false;
			colorGrid1.IrregularGrid = false;
			int y = 10;
			int z = 0, x = 0;
			for (int i = 1; i <= 2; ++i)
			{
				z = i * 10;
				for (int j = 1; j <= 2; ++j)
				{
					x = j * 10;
					colorGrid1.Add(x, y, z);
					y += 10;
				}
			}
		}
This is a defect which has been added to our list of defects and as such will be fixed as soon as possible. In the meantime, you can workaround the issue by using the code that does work and changing the labels using the GetAxisLabel() event,
e.g.

Code: Select all

		private void InitializeChart()
		{
			ColorGrid colorGrid1 = new ColorGrid(tChart1.Chart);

			tChart1.Aspect.View3D = false;
			colorGrid1.IrregularGrid = false;
			int y = 10;
			int z = 0, x = 0;
			for (int i = 1; i <= 2; ++i)
			{
				z = i;
				for (int j = 1; j <= 2; ++j)
				{
					x = j;
					colorGrid1.Add(x, y, z);
					y += 10;
				}
			}
		}

		private void tChart1_GetAxisLabel(object sender, Steema.TeeChart.GetAxisLabelEventArgs e)
		{
			Axis axis = sender as Axis;

			if (axis == tChart1.Axes.Bottom || axis == tChart1.Axes.Left)
			{
				string text = e.LabelText;
				double value = Convert.ToDouble(text);
				value *= 10;
				e.LabelText = value.ToString();
			}
		}
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/

Post Reply