Dim e As Object = Args(0)
'生成统计表
Dim g As New CrossTableBuilder("统计表1", DataTables("lxtj"))
g.HGroups.AddDef("rq", DateGroupEnum.Year, "年")
g.VGroups.AddDef("xm")
g.Totals.AddDef("je", "金额(万元)")
g.Totals.AddDef("sl", "数量")
g.Build()
'For Each c As Col In Tables("统计表1").cols
'If c.IsNumeric Then
'c.Table.DataTable.ReplaceFor(c.name, 0, c.name & " is null")
'End If
'Next
'============生成图表==============
Dim Chart As WinForm.Chart '定义一个图表变量
Dim Series As WinForm.ChartSeries '定义一个图系变量
Dim t As Table = Tables("统计表1") '定义一个变量t引用数据表
Chart = e.Form.Controls("Chart1") ' 引用窗口中的图表
Chart.ChartType2 = ChartTypeEnum.Bar '图表类型改为Bar(条形)
Chart.SeriesList.Clear() '清除图表原来的图系
Chart.AxisX.Major=1
Chart.AxisY.Major=10
Chart.AxisY2.Major=10
Chart.AxisX.ClearValueLabel
Dim C1Chart1 As C1Chart.C1Chart = CType(Chart.BaseControl,C1Chart.C1Chart)
For Each c As Col In t.Cols
If c.Name <> "年" AndAlso c.Caption.Contains("金额") Then
Series = Chart.SeriesList.Add() '增加一个图系
Series.Text = c.Caption ' Name '设置图系的标题
series.Length = t.Rows.count
For i As Integer = 0 To t.Rows.Count - 1 '指定每个数据点的位置
Series.X(i) = i '指定水平坐标
Series.Y(i) = val(t.Rows(i)(c.name)) '指定垂直坐标
Chart.AxisX.SetValueLabel(i, t.Rows(i)("年")) '指定字符表示
Next
series.DataLabelText = "{#YVAL}"
End If
Next
Chart.SeriesList2.Clear() '清除图表原来的图系
Chart.ChartType = ChartTypeEnum.XYPlot '图表2类型该为线形
Dim idx2 As Integer = 0
For Each c As Col In t.Cols
If c.Name <> "年" AndAlso c.Caption.Contains("数量") Then
Series = Chart.SeriesList2.Add() '增加一个图系
Series.Text = c.Caption ' Name '设置图系的标题
series.Length = t.Rows.count
For i As Integer = 0 To t.Rows.Count - 1 '指定每个数据点的位置
Series.X(i) = i '指定水平坐标
Series.Y(i) = val(t.Rows(i)(c.name)) '指定垂直坐标
Chart.AxisX.SetValueLabel(i, t.Rows(i)("年")) '指定字符表示
Dim Label1 = C1Chart1.ChartLabels.LabelsCollection.AddNewLabel()
With Label1
.Text = c.Caption & "(" & t.Rows(i)(c.name) & ")"
.AttachMethod = C1Chart.AttachMethodEnum.DataIndex
.AttachMethodData.GroupIndex = 1
.AttachMethodData.SeriesIndex = idx2
.AttachMethodData.PointIndex = i
.Compass = 0
.Offset = 5
.Visible = True
End With
Next
idx2 += 1
End If
Next
Chart.AxisX.AnnoWithLabels = True '启用字符标示
Chart.VisualEffect = True '加上这一行,让你的图表更漂亮
Chart.LegendVisible = True '显示图列
Chart.LegendCompass= CompassEnum.South '图列显示在南方(底端)