Hello, I am working on a simple program. But I am having trouble with MSChart and my DataGrid which is filled using an ArrayList. The problem is I cannot assign a DataGrid to the Chartdata of the chart. I think it may be my ArrayList but I'm not entirely sure how to fix it. The problem I get is a Bad Function Argument on the line
VB Code:
  1. Chart1.ChartData = ReadingDataGrid

I'm not entirely sure why. Thanks in advance. Bye


VB Code:
  1. Public Class Form1
  2.     Inherits System.Windows.Forms.Form
  3.  
  4. Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  5.  
  6.   Chart()
  7.     End Sub
  8.  
  9.     Sub Chart()
  10.  
  11.  
  12.         Dim patient1 As New Patient
  13.         patient1.ReadingProperty = 1
  14.         patient1.ReadingValueProperty = 50
  15.         myCollection.add(patient1)
  16.         patient1.ReadingProperty = 2
  17.         patient1.ReadingValueProperty = 60
  18.         myCollection.add(patient1)
  19.         patient1.ReadingProperty = 3
  20.         patient1.ReadingValueProperty = 80
  21.         myCollection.add(patient1)
  22.  
  23.         ReadingDataGrid.SetDataBinding(myCollection.myArray, "")
  24.         Chart1.ChartData = ReadingDataGrid
  25.        
  26.  
  27.         'Add a title and legend.
  28.         With Me.Chart1
  29.             .Title.Text = "Sales"
  30.             .Legend.Location.LocationType = _
  31.                MSChart20Lib.VtChLocationType.VtChLocationTypeBottom
  32.             .Legend.Location.Visible = True
  33.         End With
  34.  
  35.         'Add titles to the axes.
  36.         With Me.Chart1.Plot
  37.             .Axis(MSChart20Lib.VtChAxisId.VtChAxisIdX).AxisTitle.Text = "Year"
  38.             .Axis(MSChart20Lib.VtChAxisId.VtChAxisIdY).AxisTitle.Text = "Millions of $"
  39.         End With
  40.  
  41.         'Set custom colors for the bars.
  42.         With Me.Chart1.Plot
  43.             'Yellow for Company A
  44.             ' -1 selects all the datapoints.
  45.             .SeriesCollection(1).DataPoints(-1).Brush.FillColor.Set(250, 250, 0)
  46.             'Purple for Company B
  47.             '.SeriesCollection(2).DataPoints(-1).Brush.FillColor.Set(200, 50, 200)
  48.         End With
  49.  
  50.     End Sub
  51.  
  52. End Class

VB Code:
  1. Public Class CollectionList
  2.  
  3.     Public myArray As ArrayList
  4.  
  5.  
  6.     Public Sub New()
  7.         myArray = New ArrayList
  8.     End Sub
  9.     Public Sub Add(ByRef T As Patient)
  10.         myArray.Add(T)
  11.     End Sub
  12.     Public Sub Remove(ByRef T As Patient)
  13.         myArray.Remove(T)
  14.     End Sub
  15.     Public ReadOnly Property Count() As Integer
  16.         Get
  17.             Return myArray.Count
  18.         End Get
  19.     End Property
  20.     Public Function GetTrack(ByVal index As Integer) As Patient
  21.         Return myArray.Item(index)
  22.     End Function
  23.  
  24. End Class

VB Code:
  1. Public Class Patient
  2.  
  3.     Private Reading As Integer
  4.     Private ReadingValue As Integer
  5.  
  6.     Public Property ReadingProperty() As Integer
  7.         Get
  8.             Return Reading
  9.         End Get
  10.         Set(ByVal Value As Integer)
  11.             Reading = Value
  12.         End Set
  13.     End Property
  14.     Public Property ReadingValueProperty() As Integer
  15.         Get
  16.             Return ReadingValue
  17.         End Get
  18.         Set(ByVal Value As Integer)
  19.             ReadingValue = Value
  20.         End Set
  21.     End Property
  22. End Class