用vb6.0的mschart控件与数据库连接画曲线图
OnErrorResumeNextDimiAsIntegerDimconnAsNewADODB.ConnectionDimrsAsNewADODB.RecordsetSe...
On Error Resume Next
Dim i As Integer
Dim conn As New ADODB.Connection
Dim rs As New ADODB.Recordset
Set conn = New ADODB.Connection
Set rs = New ADODB.Recordset
conn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "C:\Documents and Settings\Administrator\桌面\vb程序\tgthtn.mdb"
conn.Open
rs.Open "select * from tgthtn", conn, adOpenKeyset, adLockOptimistic
' Set MSChart1.DataSource = rs
With MSChart1
.chartType = 3
.Plot.Axis(VtChAxisIdY).ValueScale.Auto = False
.Plot.Axis(VtChAxisIdY).ValueScale.Maximum = 100
.Plot.Axis(VtChAxisIdY).ValueScale.Minimum = 0
.Plot.Axis(VtChAxisIdY).ValueScale.MinorDivision = 1
.ColumnCount = 3
.Plot.Axis(VtChAxisIdX).ValueScale.Auto = True
.Plot.Axis(VtChAxisIdX).ValueScale.MinorDivision = 1
.Plot.Axis(VtChAxisIdX, 0).AxisTitle = "时间"
.Plot.Axis(VtChAxisIdY, 0).AxisTitle = "温度"
.Plot.Axis(VtChAxisIdX, 0).AxisTitle.VtFont.Size = 15
.Plot.Axis(VtChAxisIdY, 0).AxisTitle.VtFont.Size = 15
.Title.Text = "供暖运行曲线图"
.Title.Font.Size = 25
.ShowLegend = True
For i = 1 To .Plot.SeriesCollection.Count
.Plot.SeriesCollection(i).DataPoints(-1).DataPointLabel.LocationType = VtChLabelLocationTypeAbovePoint
Next
If rs.RecordCount > 0 Then
rs.MoveFirst
Else
Exit Sub
End If
For i = 0 To rs.RecordCount - 1
.Column = 1 '室温曲线所在列
.RowCount = rs.RecordCount
.Row = i + 1
.RowLabel = CStr(rs("时间"))
.Data = rs("tn")
.ColumnLabel = "室温"
'//供水温度显示
.Column = 2 '供水温度曲线所在列
.Data = rs("tg")
.ColumnLabel = "供水温度"
'//回水温度显示
.Column = 3 '回水温度曲线所在列
.Data = rs("th")
.ColumnLabel = "回水温度"
rs.MoveNext
Next
End With
End Sub
Private Sub Command2_Click() '下列示例设置图表查看距离和轴分段间距。
' Change the chart type to 3D Bar.
MSChart1.chartType = VtChChartType3dBar
With MSChart1.Plot
' Changes 3d bar chart's viewing.
.DepthToHeightRatio = 2
.WidthToHeightRatio = 2
' Changes the spacing between divisions on the
' X-Axis.
.xGap = 0
' Changes the spacing between divisions on the
' Z-Axis.
.zGap = 0.8
End With
End Sub
从网上找了个程序自己改了改,数据库如图,运行时横坐标显示R1、R2、R3、R4、R5,曲线的数值也不对,应该是没有和数据库连接成功,哪位高手帮我看看哪里出错了,万分感谢!
建立了form窗体后,添加了mschart控件和两个command控件,需要怎样设置他们的属性呢? 展开
Dim i As Integer
Dim conn As New ADODB.Connection
Dim rs As New ADODB.Recordset
Set conn = New ADODB.Connection
Set rs = New ADODB.Recordset
conn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "C:\Documents and Settings\Administrator\桌面\vb程序\tgthtn.mdb"
conn.Open
rs.Open "select * from tgthtn", conn, adOpenKeyset, adLockOptimistic
' Set MSChart1.DataSource = rs
With MSChart1
.chartType = 3
.Plot.Axis(VtChAxisIdY).ValueScale.Auto = False
.Plot.Axis(VtChAxisIdY).ValueScale.Maximum = 100
.Plot.Axis(VtChAxisIdY).ValueScale.Minimum = 0
.Plot.Axis(VtChAxisIdY).ValueScale.MinorDivision = 1
.ColumnCount = 3
.Plot.Axis(VtChAxisIdX).ValueScale.Auto = True
.Plot.Axis(VtChAxisIdX).ValueScale.MinorDivision = 1
.Plot.Axis(VtChAxisIdX, 0).AxisTitle = "时间"
.Plot.Axis(VtChAxisIdY, 0).AxisTitle = "温度"
.Plot.Axis(VtChAxisIdX, 0).AxisTitle.VtFont.Size = 15
.Plot.Axis(VtChAxisIdY, 0).AxisTitle.VtFont.Size = 15
.Title.Text = "供暖运行曲线图"
.Title.Font.Size = 25
.ShowLegend = True
For i = 1 To .Plot.SeriesCollection.Count
.Plot.SeriesCollection(i).DataPoints(-1).DataPointLabel.LocationType = VtChLabelLocationTypeAbovePoint
Next
If rs.RecordCount > 0 Then
rs.MoveFirst
Else
Exit Sub
End If
For i = 0 To rs.RecordCount - 1
.Column = 1 '室温曲线所在列
.RowCount = rs.RecordCount
.Row = i + 1
.RowLabel = CStr(rs("时间"))
.Data = rs("tn")
.ColumnLabel = "室温"
'//供水温度显示
.Column = 2 '供水温度曲线所在列
.Data = rs("tg")
.ColumnLabel = "供水温度"
'//回水温度显示
.Column = 3 '回水温度曲线所在列
.Data = rs("th")
.ColumnLabel = "回水温度"
rs.MoveNext
Next
End With
End Sub
Private Sub Command2_Click() '下列示例设置图表查看距离和轴分段间距。
' Change the chart type to 3D Bar.
MSChart1.chartType = VtChChartType3dBar
With MSChart1.Plot
' Changes 3d bar chart's viewing.
.DepthToHeightRatio = 2
.WidthToHeightRatio = 2
' Changes the spacing between divisions on the
' X-Axis.
.xGap = 0
' Changes the spacing between divisions on the
' Z-Axis.
.zGap = 0.8
End With
End Sub
从网上找了个程序自己改了改,数据库如图,运行时横坐标显示R1、R2、R3、R4、R5,曲线的数值也不对,应该是没有和数据库连接成功,哪位高手帮我看看哪里出错了,万分感谢!
建立了form窗体后,添加了mschart控件和两个command控件,需要怎样设置他们的属性呢? 展开
2个回答
展开全部
conn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "C:\Documents and Settings\Administrator\桌面\vb程序\tgthtn.mdb"
改为
conn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source="C:\Documents and Settings\Administrator\桌面\vb程序\tgthtn.mdb"
改为
conn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source="C:\Documents and Settings\Administrator\桌面\vb程序\tgthtn.mdb"
更多追问追答
追问
不行啊,修改后运行时提示“缺少语句结束”。
追答
引号错误 多了个引号
conn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Documents and Settings\Administrator\桌面\vb程序\tgthtn.mdb;Persist Security Info=False"
或者这样改
conn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & app.path & "\tgthtn.mdb;Persist Security Info=False"
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询