在VB mschart里面可以一个MSCHART同时显示曲线和状图吗?
2个回答
展开全部
代码及调试结果如下所示
Private Sub Command1_Click()
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 & "\lwl.mdb"
conn.Open
rs.Open "select * from lwl", conn, adOpenKeyset, adLockOptimistic
' Set MSChart1.DataSource = rs
With MSChart1
'// 以线条方式显示
.chartType = 3
'// 把刻录改为手工方式
.Plot.Axis(VtChAxisIdY).ValueScale.Auto = False
'// 设置最大值
.Plot.Axis(VtChAxisIdY).ValueScale.Maximum = 1000
'// 设置最小值
.Plot.Axis(VtChAxisIdY).ValueScale.Minimum = 0
'// 设置每格为 1
.Plot.Axis(VtChAxisIdY).ValueScale.MinorDivision = 1
'// 增加测试数据
.ColumnCount = 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 = 25
'//设置图表标题
.Title.Text = "日期和收入对应折线图"
'// 将图表作为图例的背景。
.ShowLegend = False
'// 标记每个点的值
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
.RowCount = rs.RecordCount
.Row = i + 1
.RowLabel = CStr(rs("日期"))
.Data = rs("收入")
rs.MoveNext
Next
End With
End Sub
Private Sub Command1_Click()
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 & "\lwl.mdb"
conn.Open
rs.Open "select * from lwl", conn, adOpenKeyset, adLockOptimistic
' Set MSChart1.DataSource = rs
With MSChart1
'// 以线条方式显示
.chartType = 3
'// 把刻录改为手工方式
.Plot.Axis(VtChAxisIdY).ValueScale.Auto = False
'// 设置最大值
.Plot.Axis(VtChAxisIdY).ValueScale.Maximum = 1000
'// 设置最小值
.Plot.Axis(VtChAxisIdY).ValueScale.Minimum = 0
'// 设置每格为 1
.Plot.Axis(VtChAxisIdY).ValueScale.MinorDivision = 1
'// 增加测试数据
.ColumnCount = 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 = 25
'//设置图表标题
.Title.Text = "日期和收入对应折线图"
'// 将图表作为图例的背景。
.ShowLegend = False
'// 标记每个点的值
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
.RowCount = rs.RecordCount
.Row = i + 1
.RowLabel = CStr(rs("日期"))
.Data = rs("收入")
rs.MoveNext
Next
End With
End Sub
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
ZESTRON
2024-09-04 广告
2024-09-04 广告
在Dr. O.K. Wack Chemie GmbH,我们高度重视ZESTRON的表界面分析技术。该技术通过深入研究材料表面与界面的性质,为提升产品质量与可靠性提供了有力支持。ZESTRON的表界面分析不仅涵盖了相变化、化学反应、吸附与解吸...
点击进入详情页
本回答由ZESTRON提供
展开全部
Private Sub Form_Load()
Randomize Timer
Dim i As Integer, jls As Integer
Dim Values(1 To 15, 1 To 3)
For i = 1 To 15
Values(i, 1) = "T" & Format(i, "00")
Next i
For i = 1 To 15
Values(i, 2) = Rnd * 100
Values(i, 3) = Rnd * 50
Next i
MSChart1.chartType = VtChChartType2dCombination
MSChart1.Plot.SeriesCollection.Item(1).SeriesType = VtChSeriesType2dLine
MSChart1.Plot.SeriesCollection.Item(2).SeriesType = VtChSeriesType2dBar
MSChart1.ChartData = Values
End Sub
Randomize Timer
Dim i As Integer, jls As Integer
Dim Values(1 To 15, 1 To 3)
For i = 1 To 15
Values(i, 1) = "T" & Format(i, "00")
Next i
For i = 1 To 15
Values(i, 2) = Rnd * 100
Values(i, 3) = Rnd * 50
Next i
MSChart1.chartType = VtChChartType2dCombination
MSChart1.Plot.SeriesCollection.Item(1).SeriesType = VtChSeriesType2dLine
MSChart1.Plot.SeriesCollection.Item(2).SeriesType = VtChSeriesType2dBar
MSChart1.ChartData = Values
End Sub
追问
这个是可以~~~但是我的数据是变化的~~在EXCEL读出,而且读数据系一直向下读的~而我要的和曲线都是同一个数据源的~~即数据一样,想要两种方式显示出来的~~如何编
追答
同一源分别赋给两个系列就可以。
Private Sub Form_Load()
Randomize Timer
Dim i As Integer, jls As Integer
Dim Values(1 To 15, 1 To 3)
For i = 1 To 15
Values(i, 1) = "T" & Format(i, "00")
Next i
For i = 1 To 15
Values(i, 2) = Rnd * 100 '以下两个赋相同的值就行了。
Values(i, 3) = Rnd(0) * 100
Next i
MSChart1.chartType = VtChChartType2dCombination
MSChart1.Plot.SeriesCollection.Item(1).SeriesType = VtChSeriesType2dLine
MSChart1.Plot.SeriesCollection.Item(2).SeriesType = VtChSeriesType2dBar
MSChart1.ChartData = Values
End Sub
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询