How to update chart automatically every 60 seconds?

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 the chart and when I execute the program, the form perfectly initializes the graph. I use the timer calling the function again to refresh the page the graph does not update and give an error message:

  

Could not find a chart element named Series1 in SeriesCollection '. Here is 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()
    
asked by anonymous 07.02.2014 / 03:41

2 answers

1

To resolve the error:

  

A chart element named Series1 in SeriesCollection 'could not be found.

I used the following code:

Chart1.Series.Remove(series1)

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

    
14.02.2014 / 16:17
0

Move the following method declarations to the class. Most likely the objects are being dropped before the timer is 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()
    
07.02.2014 / 20:29