【VB开源代码栏目提醒】:网学会员,鉴于大家对VB开源代码十分关注,论文会员在此为大家搜集整理了“FrmChart.frm”一文,供大家参考学习!
VERSION 5.00
Object = "{65E121D4-0C60-11D2-A9FC-0000F8754DA1}#2.0#0"; "MSCHRT20.OCX"
Object = "{67397AA1-7FB1-11D0-B148-00A0C922E820}#6.0#0"; "MSADODC.OCX"
Begin VB.Form FrmChart
BorderStyle = 1 'Fixed Single
Caption = "员工数据"
ClientHeight = 7170
ClientLeft = 45
ClientTop = 330
ClientWidth = 10455
LinkTopic = "Form1"
MaxButton = 0 'False
MinButton = 0 'False
ScaleHeight = 7170
ScaleWidth = 10455
StartUpPosition = 2 '屏幕中心
Begin MSChart20Lib.MSChart MSChart1
Height = 6495
Left = 240
OleObjectBlob = "FrmChart.frx":0000
TabIndex = 0
Top = 240
Width = 9855
End
Begin MSAdodcLib.Adodc Adodc1
Height = 375
Left = 0
Top = 0
Visible = 0 'False
Width = 2055
_ExtentX = 3625
_ExtentY = 661
ConnectMode = 0
CursorLocation = 3
IsolationLevel = -1
ConnectionTimeout= 15
CommandTimeout = 30
CursorType = 3
LockType = 3
CommandType = 1
CursorOptions = 0
CacheSize = 50
MaxRecords = 0
BOFAction = 0
EOFAction = 0
ConnectStringType= 3
Appearance = 1
BackColor = -2147483643
ForeColor = -2147483640
Orientation = 0
Enabled = -1
Connect = "DSN=newdb"
OLEDBString = ""
OLEDBFile = ""
DataSourceName = "newdb"
OtherAttributes = ""
UserName = "sa"
Pass
word = "sa"
RecordSource = "SELECT Emp_Name, Age, Wage FROM Employee "
Caption = "Adodc1"
BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851}
Name = "宋体"
Size = 9
Charset = 134
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
_Version = 393216
End
End
Attribute VB_Name = "FrmChart"
Attribute
VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
'==声明局部二维数组,10行3列==
Dim arrValues(1 To 10, 1 To 3)
Private Sub Form_Load()
'==声明循环控制变量i==
Dim i As Integer
'==初始化Adodc1==
Adodc1.Refresh
'==依次将Adodc1.Recordset中的数据赋值到arrValues()数组中==
'==每次赋值前都要判断是否到了表的最后一行,以防止越界==
'==使用MoveNext方法将游标移至下一行==
For i = 1 To 10
If Adodc1.Recordset.EOF <> True Then
arrValues(i, 1) = Adodc1.Recordset.Fields(0)
arrValues(i, 2) = Adodc1.Recordset.Fields(1)
arrValues(i, 3) = Adodc1.Recordset.Fields(2)
Adodc1.Recordset.MoveNext
End If
Next i
'==设置图例的文本内容,Plot对象描述图表的绘制区域==
'==SeriesCollection对象表示序列的集体==
'==Plot.SeriesCollection(1)表示序列C1,Plot.SeriesCollection(2)表示序列C2==
'==LegendText表示图例的文本内容==
MSChart1.Plot.SeriesCollection(1).LegendText = "员工年龄"
MSChart1.Plot.SeriesCollection(2).LegendText = "员工工资"
'==将arrValue()数组赋值到ChartData属性,从而以图形方式显示数据==
MSChart1.ChartData = arrValues
End Sub
Private Sub MSChart1_PointSelected(Series As Integer, DataPoint As Integer, _
MouseFlags As Integer, Cancel As Integer)
'==DataPoint的值正好对应arrValues()数组的行号,arrValues(DataPoint, i)是当前数据点的数据==
'==Chr(13)表示回车换行==
'==使用MSChart1.Plot.SeriesCollection(Series).LegendText显示图当前点击的图例名称==
'==利用Series参数的值可以从arrValues()数组中读取当前数据点的值==
MsgBox "员工:" + arrValues(DataPoint, 1) _
+ Chr(13) + MSChart1.Plot.SeriesCollection(Series).LegendText _
+ ":" + Trim(Str(arrValues(DataPoint, Series + 1)))
End Sub