以文本方式查看主题 - Foxtable(狐表) (http://foxtable.net/bbs/index.asp) -- 专家坐堂 (http://foxtable.net/bbs/list.asp?boardid=2) ---- 不显示临时表出错 (http://foxtable.net/bbs/dispbbs.asp?boardid=2&id=120721) |
-- 作者:susu312 -- 发布时间:2018/6/22 14:57:00 -- 不显示临时表出错 源码: Dim dt As DataTable =DataTables("表A") Dim t As DataTable Dim dtb As New DataTableBuilder("统计") dtb.AddDef("年龄段",Gettype(String),32) dtb.AddDef("人数", Gettype(Integer)) t=dtb.Build(True) Dim dr1 As DataRow = DataTables("统计").AddNew() dr1("年龄段") = "20岁-30岁" dr1("人数")=dt.Compute("Count(姓名)", "年龄" & " >= 20 And " & "年龄" & " < 30" ) Dim dr2 As DataRow = DataTables("统计").AddNew() dr2("年龄段") = "30岁-40岁" dr2("人数")=dt.Compute("Count(姓名)", "年龄" & " >= 30 And " & "年龄" & " < 40" ) Dim dr3 As DataRow = DataTables("统计").AddNew() dr3("年龄段") = "40岁-50岁" dr3("人数")=dt.Compute("Count(姓名)", "年龄" & " >= 40 And " & "年龄" & " < 50" ) Dim dr4 As DataRow = DataTables("统计").AddNew() dr4("年龄段") = "50岁-60岁" dr4("人数")=dt.Compute("Count(姓名)", "年龄" & " >= 50 And " & "年龄" & " < 60" ) Dim dr5 As DataRow = DataTables("统计").AddNew() dr5("年龄段") = "60岁以上" dr5("人数") = dt.Compute("Count(姓名)", "年龄" & " >= 60" ) \'MainTable= Tables("统计") 问题:不想生成表,只是借助表中的数据生成饼状图,看指南说把t=dtb.Build(True),但是也不管用,
|
-- 作者:有点甜 -- 发布时间:2018/6/22 15:22:00 -- Dim dt As DataTable =DataTables("表A")
Dim dr4 As DataRow = t.AddNew()
|
-- 作者:susu312 -- 发布时间:2018/6/22 15:35:00 -- 老师,您这样也不行,出不来饼状图,且依然生成临时表了 |
-- 作者:susu312 -- 发布时间:2018/6/22 15:39:00 -- 哇,没问题,好着呢!我编的时候也想到这里了,但是试了下出错了我还以为不行, 老师还是厉害! |
-- 作者:susu312 -- 发布时间:2018/6/22 15:41:00 -- 老师啊,还是不行,生成饼状图的时候,提示不存在名称为“统计”的表 Dim dt As DataTable =DataTables("人员信息") Dim t As DataTable Dim dtb As New DataTableBuilder("统计") dtb.AddDef("年龄段",Gettype(String),32) dtb.AddDef("人数", Gettype(Integer)) t=dtb.Build(True) Dim dr1 As DataRow = t.AddNew() dr1("年龄段") = "20岁-30岁" dr1("人数")=dt.Compute("Count(姓名)", "年龄" & " >= 20 And " & "年龄" & " < 30" ) Dim dr2 As DataRow = t.AddNew() dr2("年龄段") = "30岁-40岁" dr2("人数")=dt.Compute("Count(姓名)", "年龄" & " >= 30 And " & "年龄" & " < 40" ) Dim dr3 As DataRow = t.AddNew() dr3("年龄段") = "40岁-50岁" dr3("人数")=dt.Compute("Count(姓名)", "年龄" & " >= 40 And " & "年龄" & " < 50" ) Dim dr4 As DataRow = t.AddNew() dr4("年龄段") = "50岁-60岁" dr4("人数")=dt.Compute("Count(姓名)", "年龄" & " >= 50 And " & "年龄" & " < 60" ) Dim dr5 As DataRow = t.AddNew() dr5("年龄段") = "60岁以上" dr5("人数") = dt.Compute("Count(姓名)", "年龄" & " >= 60" ) \'\'生成饼状图 Dim Chart As WinForm.Chart \'定义一个图表变量 Dim Series As WinForm.ChartSeries \'定义一个图系变量 Dim t1 As Table = Tables("统计") \'定义一个变量t引用数据表 Dim sm As Integer = t1.Compute("Sum(人数)") \'计算总数量 Chart= Forms("统计窗口").Controls("Chart2") \' 引用窗口中的图表 Chart.SeriesList.Clear() \'清除图表原来的图系 Chart.VisualEffect = True \'加上这一行,让你的图表更漂亮 Chart.ChartType = ChartTypeEnum.Pie \'图表1类型改为Bar(条形) For Each r As Row In t1.Rows Series = Chart.SeriesList.Add() \'增加一个图系 Series.Length = 1 \'一个系列只能包括一个值 Series.Text = r("年龄段") & "(" & r("人数") & ")" \'设置图系的标题 Series.Y(0) = r("人数") \'指定值 Series.DataLabelText = Math.Round(r("人数")*100/sm,2) & "%" \'计算百分比 Next Chart.LegendVisible = True \'显示图列 Chart.LegendCompass= CompassEnum.East \'图列显示在东方(右方) |
-- 作者:有点甜 -- 发布时间:2018/6/22 15:44:00 -- 改成下面代码
\'\'生成饼状图
Dim Chart As WinForm.Chart \'定义一个图表变量
Dim Series As WinForm.ChartSeries \'定义一个图系变量
Dim t1 As dataTable = t \'定义一个变量t引用数据表
Dim sm As Integer = t1.Compute("Sum(人数)") \'计算总数量
Chart= Forms("统计窗口").Controls("Chart2") \' 引用窗口中的图表
Chart.SeriesList.Clear() \'清除图表原来的图系
Chart.VisualEffect = True \'加上这一行,让你的图表更漂亮
Chart.ChartType = ChartTypeEnum.Pie \'图表1类型改为Bar(条形)
For Each r As dataRow In t1.dataRows
Series = Chart.SeriesList.Add() \'增加一个图系
Series.Length = 1 \'一个系列只能包括一个值
Series.Text = r("年龄段") & "(" & r("人数") & ")" \'设置图系的标题
Series.Y(0) = r("人数") \'指定值
Series.DataLabelText = Math.Round(r("人数")*100/sm,2) & "%" \'计算百分比
Next
Chart.LegendVisible = True \'显示图列
Chart.LegendCompass= CompassEnum.East \'图列显示在东方(右方)
|
-- 作者:susu312 -- 发布时间:2018/6/22 15:58:00 -- 老师厉害! |