Page 1 of 1
Colorgrid and ArgumentException
Posted: Thu Mar 25, 2004 10:33 pm
by 8121111
I'm using VB.NET, .NET Framework v1.0, and latest version of TChart.
Upon attempting to add a point to a colorgrid I receive the following exception:
"An unhandled exception of type 'System.ArgumentException' occurred in system.windows.forms.dll
Additional information: Invalid parameter used."
I believe this is happening on the repaint of the colorgrid - it is not happening on the actual function call of Colorgrid.add().
I have been struggling with trying to figure out what I have been doing wrong or how I have miss-configured the colorgrid. As far as I can tell, only one other person has even mentioned this occurrence.
My question is: Does this sound like a common error? What are values I should check in my debugging? Any information as to what I could be doing wrong would be greatly appreciated.
Thanks,
-Mike
Posted: Fri Mar 26, 2004 12:03 pm
by Pep
Hi Mike,
could you please post the code which you're using to populate the Chart and reproduce the problem ?
Does it works using the following code :
Code: Select all
Random rnd=new Random();
for(int i=0;i<10;i++)
for(int j=0;j<20;j++)
colorGrid1.Add(j,rnd.NextDouble()+3,i,Color.Blue);
Posted: Fri Mar 26, 2004 3:11 pm
by 8121111
The following code throws the ArgumentException:
Code: Select all
Dim rand As New Random()
Dim i As Integer
Dim j As Integer
For i = -20000 To 200000 Step 10000
For j = 0 To 0
ColorGrid1.Add(i, rand.Next(31), j)
Next
Next
...but the following code does not.
Code: Select all
Dim rand As New Random()
Dim i As Integer
Dim j As Integer
For i = -20000 To 200000 Step 10000
For j = 0 To 1
ColorGrid1.Add(i, rand.Next(31), j)
Next
Next
My immediate goal is to make a colorgrid that is 1 by X. To do this, seemingly I must create 2 rows. Which value determines the color of the cell? IMHO this seems a bit non-intuitive if I understand the concept of a colorgrid correctly.
After a bit more analysis I noticed that there is always one less row and column of colored cells than ColorGrid.Add() statements. Could you help me understand how this works? Is the first row and column ignored? Is the average of the 2 (or 4) points in between a cell used to determine the color?
Thanks again,
-Mike
Posted: Fri Mar 26, 2004 8:16 pm
by 8121111
After much experimentation with the Colorgrid (8 hours or so), I think I am finally understanding which questions I need to ask.
First let me make a comment: The documentation for Colorgrids has room for improvement. I would strongly suggest a tutorial on Colorgrids and/or the rest of the Custom3D classes. I can only speak from experience with Colorgrids, but there are definitely some nuances to these classes that are not straightforward (ex: Colorgrid.IrregularGrid and it's effects on the behavior of the Colorgrid).
My question: What about the following code makes the ArgumentException get thrown?
Code: Select all
ColorGrid1.IrregularGrid = True
Dim rand As New Random()
Dim i As Integer
Dim j As Integer
For i = -100000 To 100000 Step 10000
For j = 0 To 1
ColorGrid1.Add(i, i, j)
Next
Threading.Thread.Sleep(1000)
TChart1.Refresh()
Next
-Mike
Posted: Mon Mar 29, 2004 11:33 am
by Chris
Hi Mike,
The code you post works OK using TeeChart for .NET versions 1.1.1499.42325 and 1.1.1544.23908 (the latest available for download) in Visual Studio .NET 2003. Which version of TeeChart are you using?
Posted: Mon Mar 29, 2004 3:02 pm
by 8121111
I created a new solution, created a TChart with the visual editor, placed a colorbar on it, created a button, and placed the code from my last post into the Button.clicked callback method. I left all of the options in the TChart properies/editor box on the default.
The exception occurs on the line: "TChart1.Refresh()".
Version info:
Visual Studio .NET 2002
Microsoft .NET Framework 1.0.3705
TeeChart for .NET 1.0.1499.42325
Exception text:
An unhandled exception of type 'System.ArgumentException' occurred in system.windows.forms.dll
Additional information: Invalid parameter used.
Unhandled Exception: System.ArgumentException: Invalid parameter used.
at System.Drawing.Bitmap..ctor(Int32 width, Int32 height, PixelFormat format)
at System.Drawing.Bitmap..ctor(Int32 width, Int32 height)
at Steema.TeeChart.Styles.ColorGrid.Draw()
at Steema.TeeChart.Styles.Series.DrawSeries()
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.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.SafeNativeMethods.UpdateWindow(IntPtr hWnd)
at System.Windows.Forms.Control.Update()
at System.Windows.Forms.Control.Refresh()
at testforteechart.Form1.Button1_Click(Object sender, EventArgs e) in C:\testforteechart\Form1.vb:line 98
at System.Windows.Forms.Control.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ButtonBase.WndProc(Message& m)
at System.Windows.Forms.Button.WndProc(Message& m)
at System.Windows.Forms.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.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.ComponentManager.SysteThe program '[1900] testforteechart.exe' has exited with code 0 (0x0).
m.Windows.Forms.UnsafeNativeMethods+IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)
at System.Windows.Forms.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.Run(Form mainForm)
at testforteechart.Form1.Main() in C:\testforteechart\Form1.vb:line 1
Posted: Tue Mar 30, 2004 7:51 am
by Chris
HI --
I created a new solution, created a TChart with the visual editor, placed a colorbar on it, created a button, and placed the code from my last post into the Button.clicked callback method.
Mmm ... here we have the difference ... if I use your code in the Form_Load() event I don't get an error, whereas the error you describe appears when the code is used in a Button_Click() event.
In either event, the code will work with the Thread.Sleep and Repaint lines commented out ... what is the functionality of these two lines in your application?
Posted: Tue Mar 30, 2004 2:41 pm
by 8121111
This code was a sample program I created to try to isolate the source of the exception. It simulates how I am actually using the TChart. The values for the cells on the chart are created at a very slow pace (1 value/second at best) and I need to refresh the screen between each value being added.
I have found -what seems to be- the correct way to use a colorgrid using Colorgrid.IrregularGrid. Please correct me if I'm wrong here: Using Colorgrid.IrregularGrid (=true), the client code must add 2 or more points at a time to the Colorgrid so that the points bound a cell. When Colorgrid.IrregularGrid = false, the points added via Colorgrid.add() represent the location of the cell. When Colorgrid.IrregularGrid = true, those same points represent the points in between cells (the corners of the cells).
2 observations lead me to believe this is true. 1) When I turn on marks for the Colorgrid and toggle Colorgrid.IrregularGrid, the marks seem to move from the middle of the cell to the corners. 2) When I add a second Colorgrid.Add() to the example...
Code: Select all
ColorGrid1.IrregularGrid = True
Dim rand As New Random()
Dim i As Integer
Dim j As Integer
For i = -100000 To 100000 Step 10000
For j = 0 To 1
ColorGrid1.Add(i, i, j)
ColorGrid1.Add(i + 10, i, j + 10)
Next
Threading.Thread.Sleep(1000)
TChart1.Refresh()
Next
...the ArgumentException is not thrown.
Is this true? If so, locating something to this effect in the documentation would have saved me a lot of time.
At this point, I am able to use TChart how I need to, but am curious to know if I'm using it the way it was intended to be used.
Thanks for your time,
-Mike