Struggling with chartcontrol (binding to List)
Hi all
I have a collection called results which contains a collection of a class which has an integer called Quantity and a string called Day.
34, "Monday"
45,"Tuesday"
2, Wednesday ...e.t.c
I have been trying all morning to bind this to a windows chart control (bar chart) but for the life of me can't do it.
Can anyone point me in the right direction?
Re: Struggling with chartcontrol (binding to List)
I'm not sure what you have tried, but the following code will bind a List(of class) to a chart using 2 class members(x,y) for the x and y axis. I'm quite certain it will not do what you want directly, but I am not sure what you are trying to achieve. What do you need the chart to look like?
vb Code:
Public Class Form1
Private Class thisClass
Private _x As Integer
Public Property x() As Integer
Get
Return _x
End Get
Set(ByVal value As Integer)
_x = value
End Set
End Property
Private _y As Integer
Public Property y() As Integer
Get
Return _y
End Get
Set(ByVal value As Integer)
_y = value
End Set
End Property
End Class
Dim myList As New List(Of thisClass)
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
For i As Integer = 1 To 10
Dim c As New thisClass
c.x = i
c.y = CInt(i ^ 2)
myList.Add(c)
Next
'bind the data to the chart....
With Me.Chart1.Series(0)
.XValueMember = "x"
.YValueMembers = "y"
End With
Me.Chart1.DataSource = myList
Me.Chart1.DataBind()
End Sub
End Class
kevin