控制Tchart数据库连接自动刷新
时间:2022-05-16 23:25
浏览:0
评论:0
1、我建立的测试数据极其简单
建立数据库连接我就不说了,经过连接,execute后取得RS
2、绑定数据RS
With TChart1.Series(TChart1.SeriesCount - 1) .Title = caption .DataSource = rs If bordercolor = -2 Then ' .Pen.Color = RGB(255, 0, 0) Else '.Pen.Color = bordercolor End If .Pen.Color = trendcolor '.XValues.ValueSource = ItemX .LabelsSource = ItemX .YValues.ValueSource = ItemY .Color = trendcolor If Not IsMissing(cwidth) Then If cwidth = 0 Then cwidth = 2 .Pen.Width = cwidth End If End With
3、拖一个Timer控件,写个定时刷新的,要自动刷新时调用AutoRefreshStart ,参数毫秒,他会执行execute
Private Sub timAutoRefresh_Timer() execute End Sub Public Sub AutoRefreshStart(Optional delay As Variant) On Error Resume Next timAutoRefresh.Enabled = True If delay = "" Then delay = 1000 timAutoRefresh.Interval = delay End Sub Public Sub AutoRefreshStop() On Error Resume Next timAutoRefresh.Enabled = False End Sub
4、在execute中,重新根据sql请求到RS,Connect就不要了,因为没有关闭
重新请求到数据后再绑一下,查找每1个序列,重新绑定数据,刷新图表,数据就会跟着变化
Dim iii For iii = 0 To TChart1.SeriesCount - 1 With TChart1.Series(iii) .DataSource = rs .CheckDataSource .RefreshSeries End With Next