按商品统计:
Dim Chart As WinForm.Chart '定义一个图表变量
Dim Series As WinForm.ChartSeries '定义一个图系变量
Dim t As Table = Tables("表B") '定义一个变量t引用数据表
Dim sm As Integer = t.Compute("Sum(金额)") '计算总数量
Chart= Forms("窗口2").Controls("Chart1") ' 引用窗口中的图表
Chart.VisualEffect = True '加上这一行,让你的图表更漂亮
Chart.ChartType = ChartTypeEnum.Pie '图表1类型改为Bar(条形)
Chart.SeriesList.Clear
For Each r As Row In t.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 '图列显示在东方(右方)
按类别统计:
Dim Chart As WinForm.Chart '定义一个图表变量
Dim Series As WinForm.ChartSeries '定义一个图系变量
Dim t As Table = Tables("表B") '定义一个变量t引用数据表
Chart= Forms("窗口2").Controls("Chart1") ' 引用窗口中的图表
Chart.VisualEffect = True '加上这一行,让你的图表更漂亮
Chart.ChartType = ChartTypeEnum.Pie '图表1类型改为Bar(条形)
Dim sum As Double = DataTables("表B").compute("Sum(金额)")
Dim nms As List(of String)= DataTables("表B").GetUniqueValues("","类别")
Chart.SeriesList.Clear
For Each nm As String In nms
Dim je As Double = DataTables("表B").compute("Sum(金额)","类别 = '" & nm & "'")
Series = Chart.SeriesList.Add() '增加一个图系
Series.Length = 1 '一个系列只能包括一个值
Series.Text = nm '设置图系的标题
Series.Y(0) = je '指定值
Series.DataLabelText = Math.Round(je*100/sum,2) & "%" '计算百分比
Next
Chart.LegendVisible = True '显示图列
Chart.LegendCompass= CompassEnum.East '图列显示在东方(右方)