Click here to Skip to main content
14,364,290 members
Rate this:
Please Sign up or sign in to vote.
See more:
 I have a chart in my windows form which X-axis linked whit text box, containing names of elements and Y-axis linked whit text-boxes, containing numeric values.
when I debug the form columns (bars) are close together and from 5 columns just one column takes a name.
Also when the same names come in text-boxes the program gives the message " A chart element with the name "......." already exists in the SeriseCollection". how to solve this issue?


I have tried the following code:


What I have tried:

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Try
            Me.Chart1.Series.Clear()
            Me.Chart1.Series.Add(Form3.TextBox6.Text)
            Me.Chart1.Series.Add(Form3.TextBox17.Text)
            Me.Chart1.Series.Add(Form3.TextBox23.Text)
            Me.Chart1.Series.Add(Form3.TextBox29.Text)
            Me.Chart1.Series.Add(Form3.TextBox35.Text)

            Me.Chart1.Series(Form3.TextBox6.Text).Points.AddXY(Form3.TextBox6.Text, Val(Form3.txtpi1.Text))
            Me.Chart1.Series(Form3.TextBox17.Text).Points.AddXY(Form3.TextBox17.Text, Val(Form3.txtpi2.Text))
            Me.Chart1.Series(Form3.TextBox23.Text).Points.AddXY(Form3.TextBox23.Text, Val(Form3.txtpi3.Text))
            Me.Chart1.Series(Form3.TextBox29.Text).Points.AddXY(Form3.TextBox29.Text, Val(Form3.txtpi4.Text))
            Me.Chart1.Series(Form3.TextBox35.Text).Points.AddXY(Form3.TextBox35.Text, Val(Form3.txtpi5.Text))

        Catch ex As Exception
            MessageBox.Show(ex.Message)
        Finally
            Beep()
        End Try
    End Sub
Posted
Updated 27-Oct-19 23:32pm
Comments
Richard MacCutchan 28-Oct-19 4:36am
   
I have deleted your duplicate of this question; please do not repost the same question.

1 solution

Rate this:
Please Sign up or sign in to vote.

Solution 1

Me.Chart1.Series.Add(Form3.TextBox6.Text)
Me.Chart1.Series.Add(Form3.TextBox17.Text)
Me.Chart1.Series.Add(Form3.TextBox23.Text)
Me.Chart1.Series.Add(Form3.TextBox29.Text)
Me.Chart1.Series.Add(Form3.TextBox35.Text)

Suggestion: Use proper names for your textboxes that actually reflect the content of the box. Using the default VS generated names can lead to obscure bugs in future.
   
Comments
Amranullah Hassanzada 28-Oct-19 4:36am
   
these textboxes provide the names of it contains in legend also for every bar a name.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100