给你个例子
'用到Microsoft Chart Control 这个控件
'下面代码放到类模块中
'********************
Option Explicit
Public intRows ' 列数,用于设置图表中显示的列数。
Public arrMPGandTank() ' MPG 和每桶升数
Dim txtsql As String
Dim MsgText As String
Dim mrc As ADODB.Recordset
Dim msg As String '信息Public Sub SetupChart()
txtsql = "select * from ZHFXSJB1 where XMXX_ID= " & XMID
Set mrc = ExecuteSQL(txtsql, MsgText)
Do While Not mrc.EOF
mrc.MoveNext
intRows = intRows + 1
Loop
' 配置图表。
With frmFhstt.chtSample
.RowCount = intRows ' 在设置图表数据之前,必须设置行数。
.ColumnCount = 2 ' 两列。第一列显示“每升公里数”,第二列显示使用的升数。
.ColumnLabelCount = 2 'ColumnLabelCount返回或设置与图表关联的数据网格中的列的标签级别数
' 在右上角为这个图设置图例。
' 然后为图例设置坐标。
.Legend.Location.LocationType = VtChLocationTypeRight
'Legend它包含有关小图标的外观及其描述图表系列的伴随文字的信息。
'Location该对象描述文本图表元素的位置
'LocationType返回或设置显示图表元素的标准位置
'VtChLocationTypeTop为图表元素提供了以下位置选项(顶部)
.Legend.VtFont.Style = VtFontStyleBold
'VtFont该对象描述用于显示图表文本的字体
'VtFontStyleBold字体应用粗体属性
.Legend.Location.Rect.Max.Set 7560, 5132
.Legend.Location.Rect.MIN.Set 3004, 4864
'Rect该对象定义坐标点
End With
End SubPublic Sub PopTwoArray(ByRef thisarray)
' 用两个序列组织成任意的数组。第三个元素用于获得日期值。
ReDim thisarray(1 To intRows, 1 To 3)
Dim i As Integer
'ReDim'ReDim用于为动态数组变量重新分配存储空间
txtsql = "select * from ZHFXSJB1 WHERE XMXX_ID=" & XMID
Set mrc = ExecuteSQL(txtsql, MsgText)
i = 1
If mrc.RecordCount > 0 Then
Do While Not mrc.EOF
' 获得 Date 值。
'thisarray(i, 1) = CStr(mrc.Fields(6))
'thisarray(i, 1) = Format(mrc.Fields(2), "##.##")
' 获得值。
thisarray(i, 2) = Format(mrc.Fields(60), "##.##") '自然电位曲线
thisarray(i, 1) = Format(mrc.Fields(62), "##.##") '阴极保护电位曲线
'Format返回 Variant (String),其中含有一个表达式,它是根据格式表达式中的指令来格式化的
mrc.MoveNext
i = i + 1
If i > intRows Then
Exit Do
End If
Loop
Set mrc = Nothing
End If
End SubPublic Sub twoColChart()
' 使用 arrMPGandTank 数组来创建一个两行的图表。
With frmFhstt.chtSample
.ChartData = arrMPGandTank
'ChartData绘制图表最简单的方法就是创建数字型的数组,然后将 ChartData 属性设为该数组
' .Title = "防护势态图"
.ColumnLabelCount = 1
'ColumnLabelCount返回或设置与图表关联的数据网格中的列的标签级别数
.ColumnCount = 2
'ColumnCount返回或设置与图表关联的当前数据网格中的列数
.Column = 1
' .ColumnLabel = "阴极保护电位"
'ColumnLabel返回或设置与图表数据网格中的列关联的标签文本
.Column = 2
' .ColumnLabel = "自然电位"
.Refresh
End With
End Sub
'************************
'用到Microsoft Chart Control 这个控件
'下面代码放到类模块中
'********************
Option Explicit
Public intRows ' 列数,用于设置图表中显示的列数。
Public arrMPGandTank() ' MPG 和每桶升数
Dim txtsql As String
Dim MsgText As String
Dim mrc As ADODB.Recordset
Dim msg As String '信息Public Sub SetupChart()
txtsql = "select * from ZHFXSJB1 where XMXX_ID= " & XMID
Set mrc = ExecuteSQL(txtsql, MsgText)
Do While Not mrc.EOF
mrc.MoveNext
intRows = intRows + 1
Loop
' 配置图表。
With frmFhstt.chtSample
.RowCount = intRows ' 在设置图表数据之前,必须设置行数。
.ColumnCount = 2 ' 两列。第一列显示“每升公里数”,第二列显示使用的升数。
.ColumnLabelCount = 2 'ColumnLabelCount返回或设置与图表关联的数据网格中的列的标签级别数
' 在右上角为这个图设置图例。
' 然后为图例设置坐标。
.Legend.Location.LocationType = VtChLocationTypeRight
'Legend它包含有关小图标的外观及其描述图表系列的伴随文字的信息。
'Location该对象描述文本图表元素的位置
'LocationType返回或设置显示图表元素的标准位置
'VtChLocationTypeTop为图表元素提供了以下位置选项(顶部)
.Legend.VtFont.Style = VtFontStyleBold
'VtFont该对象描述用于显示图表文本的字体
'VtFontStyleBold字体应用粗体属性
.Legend.Location.Rect.Max.Set 7560, 5132
.Legend.Location.Rect.MIN.Set 3004, 4864
'Rect该对象定义坐标点
End With
End SubPublic Sub PopTwoArray(ByRef thisarray)
' 用两个序列组织成任意的数组。第三个元素用于获得日期值。
ReDim thisarray(1 To intRows, 1 To 3)
Dim i As Integer
'ReDim'ReDim用于为动态数组变量重新分配存储空间
txtsql = "select * from ZHFXSJB1 WHERE XMXX_ID=" & XMID
Set mrc = ExecuteSQL(txtsql, MsgText)
i = 1
If mrc.RecordCount > 0 Then
Do While Not mrc.EOF
' 获得 Date 值。
'thisarray(i, 1) = CStr(mrc.Fields(6))
'thisarray(i, 1) = Format(mrc.Fields(2), "##.##")
' 获得值。
thisarray(i, 2) = Format(mrc.Fields(60), "##.##") '自然电位曲线
thisarray(i, 1) = Format(mrc.Fields(62), "##.##") '阴极保护电位曲线
'Format返回 Variant (String),其中含有一个表达式,它是根据格式表达式中的指令来格式化的
mrc.MoveNext
i = i + 1
If i > intRows Then
Exit Do
End If
Loop
Set mrc = Nothing
End If
End SubPublic Sub twoColChart()
' 使用 arrMPGandTank 数组来创建一个两行的图表。
With frmFhstt.chtSample
.ChartData = arrMPGandTank
'ChartData绘制图表最简单的方法就是创建数字型的数组,然后将 ChartData 属性设为该数组
' .Title = "防护势态图"
.ColumnLabelCount = 1
'ColumnLabelCount返回或设置与图表关联的数据网格中的列的标签级别数
.ColumnCount = 2
'ColumnCount返回或设置与图表关联的当前数据网格中的列数
.Column = 1
' .ColumnLabel = "阴极保护电位"
'ColumnLabel返回或设置与图表数据网格中的列关联的标签文本
.Column = 2
' .ColumnLabel = "自然电位"
.Refresh
End With
End Sub
'************************
解决方案 »
- 打印问题
- VB 打开并读取 刚 被写入并关闭的文件
- 这样的一个树控件里生成的一层层的结点,请问如何设计数据表来保存这些结点,以便于下次程序一进去,可以读出来.
- 给高分:关于时间判断的问题请大家帮忙
- 怎样让代码继续执行?
- 开发MIS系统的典型开发环境
- 求助!!用Webbrowser打开一个Word文档,如何把字符串写到这个打开的word中??
- 高分解答!如何使用Graphics.DrawLines方法,在VB下!
- 一个旧VB6.0程序,用的是Access97建的数据库,更新成Access2000的数据库后,不能打开,这么办?
- 如何使用api:getwindowtext编写一个密码登陆程序,用另一个程序可以破译密码????????这样的程序如何编
- 关于vb与access连接的最最基础的问题!!
- 请教
Private Sub cmdGalAndMPG_Click()
' 显示一个组合图。
twoColChart
End SubPrivate Sub Form_Load()
SetupChart ' 配置图表
End Sub