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 05:55 AM. Reason: Added Code Tags

  2. #2
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: VB. Chart update

    Thread Moved To The VB.NET Section

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

    Re: VB. Chart update

    DO you have columns named Price and Quantity ?
    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
  •  



Click Here to Expand Forum to Full Width