Dim b As New GroupTableBuilder("统计表1",DataTables("person"))
Dim t As DataTable
b.Groups.AddDef("retiredPost","职务") '根据产品分组
b.Totals.AddDef("retiredPost",AggregateEnum.Count,"人数")
t=b.Build(True) '生成统计表
'MainTable = Tables("统计表1") '打开生成的统计表
Dim Chart As WinForm.Chart '定义一个图表变量
Dim Series As WinForm.ChartSeries '定义一个图系变量
Dim sm As Integer = t.Compute("Sum(人数)") '计算总数量
Chart= e.Form.Controls("Chart1") ' 引用窗口中的图表
Chart.SeriesList.Clear() '清除图表原来的图系
Chart.VisualEffect = True '加上这一行,让你的图表更漂亮
Chart.ChartType = ChartTypeEnum.Pie '图表1类型改为Bar(条形)
For i As Integer = 0 To t.dataRows.Count - 1
Dim rs As Integer = val(t.dataRows(i)("人数"))
Series = Chart.SeriesList.Add() '增加一个图系
Series.Length = 1 '一个系列只能包括一个值
Series.Text = t.dataRows(i)("职务") & "(" & rs & ")" '设置图系的标题
Series.Y(0) = rs '指定值
Series.DataLabelText = Math.Round(rs*100/sm,2) & "%" '计算百分比
Next
Series = Chart.SeriesList.Add() '增加一个图系
Series.Length = 1 '一个系列只能包括一个值
Series.Text = "总人数(" & sm & ")" '设置图系的标题
Series.Y(0) = 0 '指定值
Chart.LegendVisible = True '显示图列
Chart.LegendCompass= CompassEnum.East '图列显示在东方(右方)