VB中如何使用mschart控件画曲柱形图并连接数据库
我有一个数据库cwgl.mdb。其中sr表有姓名,类型和金额3个字段。要求按姓名统计(就是某个人花了多少钱。都是什么类型)大侠们帮帮忙。。看看代码要怎么写啊。分还可以追加...
我有一个数据库cwgl.mdb。其中sr表有姓名,类型和金额3个字段。要求按姓名统计(就是某个人花了多少钱。都是什么类型)大侠们帮帮忙。。看看代码要怎么写啊。分还可以追加。只要有用就可以
展开
展开全部
'姓名,类型和金额 时间有限,只做了一个 姓名和金额的东西,以供你参考 Chart1我做的是一个饼状图 你改下属性应该可以的
Chart1.Row = 1
Dim i As Integer
For i = 1 To Chart1.ColumnCount
Chart1.Column = i
Chart1.Data = 0
Next
sql = "select 姓名 as 参数,isnull(sum(金额),0) as 金额 from sr表 group by 姓名
If RSchart.State = 1 Then RSchart.Close
RSchart.CursorLocation = adUseClient
RSchart.Open sql, conn, adOpenKeyset, adLockOptimistic
If RSchart.EOF Or RSchart.BOF Then Exit Sub
Chart1.ColumnCount = RSchart.RecordCount
Chart1.Column = 1
While Not RSchart.EOF
Chart1.ColumnLabel = RSchart("参数") & ": " & RSchart("金额")
Chart1.Data = RSchart("金额")
If Chart1.Column < Chart1.ColumnCount Then Chart1.Column = Chart1.Column + 1
RSchart.MoveNext
Wend
Chart1.ShowLegend = True
Chart1.Row = 1
Dim i As Integer
For i = 1 To Chart1.ColumnCount
Chart1.Column = i
Chart1.Data = 0
Next
sql = "select 姓名 as 参数,isnull(sum(金额),0) as 金额 from sr表 group by 姓名
If RSchart.State = 1 Then RSchart.Close
RSchart.CursorLocation = adUseClient
RSchart.Open sql, conn, adOpenKeyset, adLockOptimistic
If RSchart.EOF Or RSchart.BOF Then Exit Sub
Chart1.ColumnCount = RSchart.RecordCount
Chart1.Column = 1
While Not RSchart.EOF
Chart1.ColumnLabel = RSchart("参数") & ": " & RSchart("金额")
Chart1.Data = RSchart("金额")
If Chart1.Column < Chart1.ColumnCount Then Chart1.Column = Chart1.Column + 1
RSchart.MoveNext
Wend
Chart1.ShowLegend = True
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询