Results 1 to 5 of 5

Thread: [RESOLVED] Plotting a line chart problem (In user control)

  1. #1

    Thread Starter
    Hyperactive Member pourkascheff's Avatar
    Join Date
    Apr 2020
    Location
    LocalHost
    Posts
    354

    Resolved [RESOLVED] Plotting a line chart problem (In user control)

    Hi all.
    This is an example code which works properly and plots an xy series of dots/lines.
    Code:
    Public Class Form2
        Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
            Label1.Text = Val(Label1.Text) + 1
            Chart1.Series(0).Points.AddXY(Val(Label1.Text), TrackBar1.Value)
        End Sub
    End Class
    Here's the results safe and easy:
    Name:  chart.jpg
Views: 302
Size:  18.2 KB

    However, to show a line chart in a usercontrol same code (In a try catch) will cause following exception:
    "Index was out of range. Must be non-negative and less than size of collection. Parameter name: index" Series1 is OK in term of name, checked.
    "A chart element with the name 'Series1' could not be found in the 'SeriesCollection'." Integer id same as example code.

    * Both way were tried. Nothing achieved.
    Any clues? Is there another way/method to add point in x and y?

  2. #2
    Fanatic Member Delaney's Avatar
    Join Date
    Nov 2019
    Location
    Paris, France
    Posts
    845

    Re: Plotting a line chart problem (In user control)

    can you post the code in the user control ?

    don't you have to put the name of the usercontrol before the name of the control in the code?

    yourusercontrolname.Chart1.series ....
    The best friend of any programmer is a search engine
    "Don't wish it was easier, wish you were better. Don't wish for less problems, wish for more skills. Don't wish for less challenges, wish for more wisdom" (J. Rohn)
    “They did not know it was impossible so they did it” (Mark Twain)

  3. #3

    Thread Starter
    Hyperactive Member pourkascheff's Avatar
    Join Date
    Apr 2020
    Location
    LocalHost
    Posts
    354

    Re: Plotting a line chart problem (In user control)

    Quote Originally Posted by Delaney View Post
    can you post the code in the user control ?
    Yes sir, But it is nothing much:
    Code:
    Public Class ITEM
        Private Sub Label1_TextChanged(sender As Object, e As EventArgs) Handles Label1.TextChanged
            Try
                chartx.Text = Val(chartx.Text) + 1
                Chart1.Series("Series1").Points.AddXY(Val(chartx.Text), Val(Label1.Text))
            Catch ex As Exception
                MsgBox(ex.Message, MsgBoxStyle.Critical)
            End Try
        End Sub
    End Class
    Translasion: Once Label1 value changes, a variable increment will occur and current-value under chartx (represents steps) also shown under x,y.

    Quote Originally Posted by Delaney View Post
    don't you have to put the name of the usercontrol before the name of the control in the code?
    Not sure.

    Quote Originally Posted by Delaney View Post
    yourusercontrolname.Chart1.series ....
    Well, I tried it now, dot after UserControl1 opens a list of properties which none of its controls are not available in it, therefore "UserControl1.Chart1" doesn't exist. I added Chart1 to a TabControl it doesn't make difference right? I'm new to VB.NET behavior/logic.
    Update: "Me.Chart1." does exist tho. But same exceptions will occur.

    * Is it possible that an option (explicit, strict, compare, infer and etc.) rectifies the matter? It seemed easier at first but it's not... : (
    Last edited by pourkascheff; Aug 2nd, 2022 at 12:18 AM.

  4. #4
    Fanatic Member Delaney's Avatar
    Join Date
    Nov 2019
    Location
    Paris, France
    Posts
    845

    Re: Plotting a line chart problem (In user control)

    Ok after checking it comes from the label events. What I guess is that the label event is triggered at some point before the serie is created so you will have to change the philosophy of the filling of the chart. I join my test_sample so you can maybe get some ideas.

    done with VS2017 (FW 4.7.2)

    test_usercontrol.zip
    The best friend of any programmer is a search engine
    "Don't wish it was easier, wish you were better. Don't wish for less problems, wish for more skills. Don't wish for less challenges, wish for more wisdom" (J. Rohn)
    “They did not know it was impossible so they did it” (Mark Twain)

  5. #5

    Thread Starter
    Hyperactive Member pourkascheff's Avatar
    Join Date
    Apr 2020
    Location
    LocalHost
    Posts
    354

    Re: Plotting a line chart problem (In user control)

    Well done sir. It finally worked. Thank you. Manual private sub filling_chart function did the thing. Just forget about interpolation in an event people...

Tags for this Thread

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