|
-
Feb 28th, 2014, 05:02 AM
#1
Thread Starter
Fanatic Member
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?
-
Feb 28th, 2014, 11:14 AM
#2
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
Process control doesn't give you good quality, it gives you consistent quality.
Good quality comes from consistently doing the right things.
Vague general questions have vague general answers. A $100 donation is required for me to help you if you PM me asking for help. Instructions for donating to one of our local charities will be provided.
______________________________ Last edited by kebo : Now. Reason: superfluous typo's
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|