PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197
VS 2012 Struggling with chartcontrol (binding to List)-VBForums
Results 1 to 2 of 2

Thread: Struggling with chartcontrol (binding to List)

  1. #1

    Thread Starter
    Fanatic Member venerable bede's Avatar
    Join Date
    Sep 2002
    Location
    The mystic land of Geordies
    Posts
    1,018

    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?

    Parksie

  2. #2
    Still learning kebo's Avatar
    Join Date
    Apr 2004
    Location
    Gardnerville,nv
    Posts
    3,708

    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:
    1. Public Class Form1
    2.  
    3.  
    4.     Private Class thisClass
    5.         Private _x As Integer
    6.         Public Property x() As Integer
    7.             Get
    8.                 Return _x
    9.             End Get
    10.             Set(ByVal value As Integer)
    11.                 _x = value
    12.             End Set
    13.         End Property
    14.  
    15.         Private _y As Integer
    16.         Public Property y() As Integer
    17.             Get
    18.                 Return _y
    19.             End Get
    20.             Set(ByVal value As Integer)
    21.                 _y = value
    22.             End Set
    23.         End Property
    24.     End Class
    25.  
    26.  
    27.  
    28.     Dim myList As New List(Of thisClass)
    29.  
    30.     Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    31.  
    32.  
    33.         For i As Integer = 1 To 10
    34.             Dim c As New thisClass
    35.             c.x = i
    36.             c.y = CInt(i ^ 2)
    37.             myList.Add(c)
    38.  
    39.         Next
    40.  
    41.  
    42.         'bind the data to the chart....
    43.  
    44.         With Me.Chart1.Series(0)
    45.             .XValueMember = "x"
    46.             .YValueMembers = "y"
    47.         End With
    48.         Me.Chart1.DataSource = myList
    49.         Me.Chart1.DataBind()
    50.  
    51.  
    52.     End Sub
    53. 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
  •  



Featured


Click Here to Expand Forum to Full Width