VB. Chart update-VBForums
Results 1 to 4 of 4

Thread: VB. Chart update

  1. #1

    Thread Starter
    Registered User
    Join Date
    Oct 2013
    Posts
    3

    VB. Chart update

    Hello

    I used combobox to change chart Y.

    Here is my code

    vb.net Code:
    1. Sub InitializeComponent()
    2.         Me.components = New System.ComponentModel.Container()
    3.         Dim ChartArea1 As System.Windows.Forms.DataVisualization.Charting.ChartArea = New System.Windows.Forms.DataVisualization.Charting.ChartArea()
    4.         Dim Legend1 As System.Windows.Forms.DataVisualization.Charting.Legend = New System.Windows.Forms.DataVisualization.Charting.Legend()
    5.         Dim Series1 As System.Windows.Forms.DataVisualization.Charting.Series = New System.Windows.Forms.DataVisualization.Charting.Series()
    6.         Me.ComboBox1 = New System.Windows.Forms.ComboBox()
    7.         Me.Sheet1BindingSource = New System.Windows.Forms.BindingSource(Me.components)
    8.         Me.SampleDB2DataSet = New WindowsApplication13.SampleDB2DataSet()
    9.         Me.Sheet1TableAdapter = New WindowsApplication13.SampleDB2DataSetTableAdapters.sheet1TableAdapter()
    10.         Me.Chart1 = New System.Windows.Forms.DataVisualization.Charting.Chart()
    11.         Me.Button1 = New System.Windows.Forms.Button()
    12.         CType(Me.Sheet1BindingSource, System.ComponentModel.ISupportInitialize).BeginInit()
    13.         CType(Me.SampleDB2DataSet, System.ComponentModel.ISupportInitialize).BeginInit()
    14.         CType(Me.Chart1, System.ComponentModel.ISupportInitialize).BeginInit()
    15.         Me.SuspendLayout()
    16.         '
    17.         'ComboBox1
    18.         '
    19.         Me.ComboBox1.FormattingEnabled = True
    20.         Me.ComboBox1.Items.AddRange(New Object() {"Price", "Quantity"})
    21.         Me.ComboBox1.Location = New System.Drawing.Point(72, 39)
    22.         Me.ComboBox1.Name = "ComboBox1"
    23.         Me.ComboBox1.Size = New System.Drawing.Size(540, 20)
    24.         Me.ComboBox1.TabIndex = 0
    25.         '
    26.         'Sheet1BindingSource
    27.         '
    28.         Me.Sheet1BindingSource.DataMember = "sheet1"
    29.         Me.Sheet1BindingSource.DataSource = Me.SampleDB2DataSet
    30.         '
    31.         'SampleDB2DataSet
    32.         '
    33.         Me.SampleDB2DataSet.DataSetName = "SampleDB2DataSet"
    34.         Me.SampleDB2DataSet.SchemaSerializationMode = System.Data.SchemaSerializationMode.IncludeSchema
    35.         '
    36.         'Sheet1TableAdapter
    37.         '
    38.         Me.Sheet1TableAdapter.ClearBeforeFill = True
    39.         '
    40.         'Chart1
    41.         '
    42.         ChartArea1.Name = "ChartArea1"
    43.         Me.Chart1.ChartAreas.Add(ChartArea1)
    44.         Me.Chart1.DataSource = Me.Sheet1BindingSource
    45.         Legend1.Name = "Legend1"
    46.         Me.Chart1.Legends.Add(Legend1)
    47.         Me.Chart1.Location = New System.Drawing.Point(75, 129)
    48.         Me.Chart1.Name = "Chart1"
    49.         Series1.ChartArea = "ChartArea1"
    50.         Series1.Legend = "Legend1"
    51.         Series1.Name = "Series1"
    52.         Series1.XValueMember = "Name"
    53.        Series1.YValueMembers = ComboBox1.Text
    54.         Me.Chart1.Series.Add(Series1)
    55.         Me.Chart1.Size = New System.Drawing.Size(627, 384)
    56.         Me.Chart1.TabIndex = 1
    57.         Me.Chart1.Text = "Chart1"
    58.         '
    59.         'Button1
    60.         '
    61.         Me.Button1.Location = New System.Drawing.Point(633, 24)
    62.         Me.Button1.Name = "Button1"
    63.         Me.Button1.Size = New System.Drawing.Size(102, 75)
    64.         Me.Button1.TabIndex = 2
    65.         Me.Button1.Text = "Button1"
    66.         Me.Button1.UseVisualStyleBackColor = True
    67.         '
    68.         'Form1
    69.         '
    70.         Me.AutoScaleDimensions = New System.Drawing.SizeF(7.0!, 12.0!)
    71.         Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
    72.         Me.ClientSize = New System.Drawing.Size(764, 571)
    73.         Me.Controls.Add(Me.Button1)
    74.         Me.Controls.Add(Me.Chart1)
    75.         Me.Controls.Add(Me.ComboBox1)
    76.         Me.Name = "Form1"
    77.         Me.Text = "Form1"
    78.         CType(Me.Sheet1BindingSource, System.ComponentModel.ISupportInitialize).EndInit()
    79.         CType(Me.SampleDB2DataSet, System.ComponentModel.ISupportInitialize).EndInit()
    80.         CType(Me.Chart1, System.ComponentModel.ISupportInitialize).EndInit()
    81.         Me.ResumeLayout(False)
    82.  
    83.     End Sub
    84.     Friend WithEvents ComboBox1 As System.Windows.Forms.ComboBox
    85.     Friend WithEvents SampleDB2DataSet As WindowsApplication13.SampleDB2DataSet
    86.     Friend WithEvents Sheet1BindingSource As System.Windows.Forms.BindingSource
    87.     Friend WithEvents Sheet1TableAdapter As WindowsApplication13.SampleDB2DataSetTableAdapters.sheet1TableAdapter
    88.     Friend WithEvents Chart1 As System.Windows.Forms.DataVisualization.Charting.Chart
    89.     Friend WithEvents Button1 As System.Windows.Forms.Button
    90.  
    91. End Class
    92.  
    93.  
    94. In short
    95.  
    96. I changed Yvaluemembers to like this.
    97.  
    98.        Series1.YValueMembers = ComboBox1.Text
    99.  
    100. Although I changed combobox1, chart doesn't updated.
    101.  
    102. So I added this code to combobox1
    103.  
    104. Private Sub ComboBox1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ComboBox1.SelectedIndexChanged
    105.         Chart1.Update()
    106.  
    107.  
    108. End Sub
    But it also doesn't work. anyone know about this?
    Last edited by Hack; Oct 21st, 2013 at 06:55 AM. Reason: Added Code Tags

  2. #2
    Super Moderator Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,335

    Re: VB. Chart update

    Thread Moved To The VB.NET Section
    Please use [Code]your code goes in here[/Code] tags when posting code.
    When you have received an answer to your question, please mark it as resolved using the Thread Tools menu.
    Before posting your question, did you look here?
    Got a question on Linux? Visit our Linux sister site.
    I dont answer coding questions via PM or EMail. Please post a thread in the appropriate forum section.

    Creating A Wizard In VB.NET
    Paging A Recordset
    What is wrong with using On Error Resume Next
    Good Article: Language Enhancements In Visual Basic 2010
    Upgrading VB6 Code To VB.NET
    Microsoft MVP 2005/2006/2007/2008/2009/2010/2011/2012/Defrocked

  3. #3
    Frenzied Member HanneSThEGreaT's Avatar
    Join Date
    Nov 2003
    Location
    Vereeniging, South Africa
    Posts
    1,461

    Re: VB. Chart update

    DO you have columns named Price and Quantity ?
    There was a time, long, long a go when a guy named Hannes du Preez ( Hey! That's me!! ) knew anything and everything concerning programming technologies. Since, he has had a burn-out, got married and had kids ( and puppies - do not forget the puppies ), and our friend Hannes has turned grey, almost bald, and most importantly, his belly grew substantially! He also experienced problems with his hands.
    Now, Hannes said to himself: "Learn new things! If you do not learn new things and accept the changes in technology, you will become stuck in the same gear!"
    So, our friend, Hannes ( the unsung hero - once ) has stumbled upon the awesomeness which is mobile programming, Android, BlackBerry and Windows Phone 8. Thus far, he has done good - he even has a bunch of articles on them - with the hopes that maybe one day, he'll find his dream job.
    Besides trying to program PCs., AVR devices, and mobile devices he likes writing poetry, short stories, novels, songs, and tries his hand at art; even though his wife is a far better painter and sculptor... Moral of the story: Forgive him for not always getting it right, he is after all just human, and he has accepted his faults; but, at least he is trying! Perhaps if he would think asked questions properly through, he'd get all his answers right... Forgive him as well for being grumpy at times, as his neuro-pathways are still a bit scrambled...
    VB.NET MVP 2008 - Present

  4. #4

    Thread Starter
    Registered User
    Join Date
    Oct 2013
    Posts
    3

    Re: VB. Chart update

    Quote Originally Posted by HanneSThEGreaT View Post
    DO you have columns named Price and Quantity ?
    yes sample DB have three fields

    Name, Price, Quantity

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

Survey posted by VBForums.