1 Attachment(s)
[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:
Attachment 185423
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?
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 ....
Re: Plotting a line chart problem (In user control)
Quote:
Originally Posted by
Delaney
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
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
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... : (
1 Attachment(s)
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)
Attachment 185439
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...