vb中用mschrt、picturebox、sroll控制元件畫大資料的折線圖,放大幾倍后前面和后面的資料就不顯示了
代碼如下
Private Sub Form_Load()
Dim cnn As New ADODB.Connection
Dim rs As New ADODB.Recordset
Dim i As Integer
cnn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\DATA.MDB;Persist Security Info=False"
rs.Open "電壓值幀", cnn, adOpenKeyset, adLockOptimistic
ReDim arrValues(1 To rs.RecordCount, 1 To 4) '定義動態陣列
If rs.RecordCount > 0 Then
rs.MoveFirst
Else
Exit Sub
End If
For i = 1 To rs.RecordCount '給陣列賦值
arrValues(i, 1) = " " & rs!時間
arrValues(i, 2) = rs!發電機電壓
arrValues(i, 3) = rs!供電電壓
arrValues(i, 4) = rs!電池電壓
rs.MoveNext
Next i
MSChart1.ChartData = arrValues '資料
'波形圖外觀設定
With MSChart1
.TitleText = "電壓 V"
'設定圖線的外觀
.Plot.SeriesCollection(1).Pen.Width = 40
.Plot.SeriesCollection(1).Pen.Style = VtPenStyleSolid
' '設定XY軸
.Plot.Axis(VtChAxisIdX).ValueScale.Auto = False
.Plot.Axis(VtChAxisIdY).ValueScale.Auto = False
'// 設定最大值
.Plot.Axis(VtChAxisIdX).ValueScale.Maximum = 1000 '設定橫軸標注最大值
.Plot.Axis(VtChAxisIdY).ValueScale.Maximum = 50 '設定縱軸標注最大值
'// 設定最小值
.Plot.Axis(VtChAxisIdY).ValueScale.Minimum = 0
.Plot.Axis(VtChAxisIdX).ValueScale.Minimum = 0
'//
.Plot.Axis(VtChAxisIdX).ValueScale.MajorDivision = 10 'X軸主要網格數量
.Plot.Axis(VtChAxisIdY).ValueScale.MajorDivision = 10 'Y軸主要網格數量
.Plot.Axis(VtChAxisIdX).ValueScale.MinorDivision = 0 'X軸次要網格數量
.Plot.Axis(VtChAxisIdY).ValueScale.MinorDivision = 0 'Y軸次要網格數量
.Plot.Axis(VtChAxisIdX).AxisGrid.MajorPen.Style = VtPenStyleDotted
.Plot.Axis(VtChAxisIdY).AxisGrid.MajorPen.Style = VtPenStyleDotted
MSChart1.Plot.AutoLayout = True
MSChart1.Plot.UniformAxis = False
MSChart1.chartType = VtChChartType2dLine '設定圖形為二維散點圖
End With
MSChart1.Left = Picture1.ScaleLeft
MSChart1.Top = Picture1.ScaleTop
MSChart1.Height = Picture1.ScaleHeight
MSChart1.Width = Picture1.ScaleWidth * 2
HScroll1.Max = 100
HScroll1.Min = 0
HScroll1.Value = 0
HScroll1.SmallChange = 10
HScroll1.LargeChange = 20
End Sub
Private Sub HScroll1_Change()
MSChart1.Left = Picture1.ScaleLeft - (MSChart1.Width - Picture1.ScaleWidth) * HScroll1.Value * 0.01
Form1.Refresh
End Sub
'全部顯示
Private Sub Command1_Click()
MSChart1.Left = Picture1.ScaleLeft
MSChart1.Top = Picture1.ScaleTop
MSChart1.Height = Picture1.ScaleHeight
MSChart1.Width = Picture1.ScaleWidth
HScroll1.Enabled = False
End Sub
'5倍顯示
Private Sub Command2_Click()
MSChart1.Left = Picture1.ScaleLeft
MSChart1.Top = Picture1.ScaleTop
MSChart1.Height = Picture1.ScaleHeight
MSChart1.Width = Picture1.ScaleWidth * 5
HScroll1.Max = 100
HScroll1.Min = 0
HScroll1.Value = 0
HScroll1.SmallChange = 10
HScroll1.LargeChange = 20
HScroll1.Enabled = True
End Sub
'10倍顯示
Private Sub Command3_Click()
MSChart1.Left = Picture1.ScaleLeft
MSChart1.Top = Picture1.ScaleTop
MSChart1.Height = Picture1.ScaleHeight
MSChart1.Width = Picture1.ScaleWidth * 10
HScroll1.Max = 100
HScroll1.Min = 0
HScroll1.Value = 0
HScroll1.SmallChange = 10
HScroll1.LargeChange = 20
HScroll1.Enabled = True
End Sub

轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/86801.html
標籤:控件
