How to update Chart automatically every 60 seconds?

Asked

Viewed 878 times

2

I have a project where I need to update a form every 60 seconds, and in the form there is a function to call Chart (graphic) and when I run the program the form perfectly initializes the graph but when I use the timer calling the function again to refresh the page the chart does not refresh and give an error message:

Could not find a chart widget named Series1 in Seriescollection'. Follows the function:

DIM SQL AS STRING 
SQL = SELECT TELE_MARKENTIG, VENDEDOR, TOTAL FROM PEDIDOS

Dim CArea As ChartArea = New ChartArea()
Dim LG As Legend = New Legend()
Dim Series1 As Series = New Series()
Dim Chart1 = New Chart()
Me.Controls.Add(Chart1)
 CArea.Name = "ChartArea20"
 Chart1.ChartAreas.Add(CArea)
 ''Legend1.Name = "Legend20"
Chart1.Legends.Add(LG)
 Chart1.Location = New System.Drawing.Point(20, 20)
Chart1.Name = "Chart12"
Series1.ChartArea = "ChartArea20"
 ''Series1.Legend = "Legend20"
 Series1.Name = "Vendas"
 Chart1.Series.Add(Series1)
 Chart1.Size = New System.Drawing.Size(300, 175)
'chtVendas.TabIndex = 0
'chtVendas.Text = "Chart1"
CArea.Position.Width = 75
CArea.Position.Height = 100

Chart1.Series("Vendas").XValueMember = "TELE_MARKETING"
Chart1.Series("Vendas").YValueMembers = "TOTAL"
Dim ds As New DataSet
Dim DATAADAPTER As New SqlClient.SqlDataAdapter(SQL, CN)

DATAADAPTER.Fill(ds, "VCTCS")


'''''''''''''''''''''''''''''
'~~> SET DATA SOURCE <~~'
'''''''''''''''''''''''''''''
Chart1.DataSource = ds.Tables("VCTCS")

Chart1.DataBind()

2 answers

1

To resolve the error:

Could not find a graph element named Series1 in Seriescollection'.

I used the following code:

Chart1.Series.Remove(series1)

That is, before calling the chart needed to remove it.

0

Move the following method statements to the class. Most likely objects are being discarded before the timer run, and moving them to the class will prevent this from happening.

Private CArea As ChartArea = New ChartArea()
Private LG As Legend = New Legend()
Private Series1 As Series = New Series()
Private Chart1 = New Chart()
  • Thanks for trying to help. Analyzing the error well I found that I had to remove Chart to solve the problem and I used the following code: Chart1.Series.Remove(Series1)

  • @Rogerio.Ngineer have you found your own solution? Post it as an answer and accept it. This can even help you gain a reputation and leave it out to other people.

  • thanks. thanks. .

Browser other questions tagged

You are not signed in. Login or sign up in order to post.