每个button按一次就统计一个表 现在的情况是button1生成图表以后 按button2再生成 就会出现这个绿色标签 但是先生成button2再生成button1就不会
cmd.CommandText=sql
dt=cmd.ExecuteReader
Dim s As String="工作量统计"
Dim g As New GroupTableBuilder(s, dt)
g.Groups.AddDef("制作人")
g.Totals.AddDef("工作量")
g.GrandProportion = True
g.Filter = "[制作人] is not null"
g.Build()
Tables(s).Sort="工作量 desc "
Dim tt As Table=Tables(s)
Dim Chart As WinForm.Chart \'定义一个图表变量
Dim Series As WinForm.ChartSeries \'定义一个图系变量
Chart = f.Controls("Chart2") \' 引用窗口中的图表
Chart.SeriesList.Clear() \'清除图表原来的图系
chart.SeriesList2.Clear()
Chart.AxisX.ClearValueLabel()
\'Chart.VisualEffect = True \'加上这一行,让你的图表更漂亮
Chart.ChartType = ChartTypeEnum.Bar \'图表1类型该为Bar(条形)
Chart.ChartType2 = ChartTypeEnum.XYPlot \'图表2类型该为线形
\'\'Chart.DataSource = s \'设置绑定表
\'\'Chart.AxisX.Major = 2
Chart.SeriesList.Clear() \'清除图表原来的图系
chart.SeriesList2.Clear()
Series = Chart.SeriesList.Add() \'给图表1增加一个图系
Series.Length = tt.Rows.Count
For i As Integer = 0 To tt.Rows.Count - 1 \'指定每个数据点的位置
Series.X(i) = i \'指定水平坐标
Series.Y(i) = tt.Rows(i)("工作量") \'指定垂直坐标
Chart.AxisX.SetValueLabel(i, tt.Rows(i)("制作人"))
Next
Chart.AxisX.AnnoWithLabels = True
Series.DataLabelText = "{#YVAL}"
Series.Text="工作量"
Series.DataLabelBackColor = Color.RED \'蓝底
Series.DataLabelForeColor = Color.White \'白字
\'清除图表原来的图系
Series = Chart.SeriesList2.Add() \'给图表1增加一个图系
Series.Length = tt.Rows.Count
For i As Integer = 0 To tt.Rows.Count - 1 \'指定每个数据点的位置
Series.X(i) = i \'指定水平坐标
Series.Y(i) = tt.Rows(i)("工作量gdr") \'指定垂直坐标
Next
Series.Text="工作量占比"
Dim c1Chart1 = Chart.basecontrol
Dim lbls = c1Chart1.ChartLabels
For i As Integer = 0 To Tables(s).rows.count-1
Dim lbl As C1.Win.C1Chart.Label = lbls.LabelsCollection.AddNewLabel()
lbl.Text = Format(series.y(i), "0.00%")
lbl.AttachMethod = C1.Win.C1Chart.AttachMethodEnum.DataIndex
lbl.AttachMethodData.GroupIndex = 0
lbl.AttachMethodData.SeriesIndex = 0
lbl.AttachMethodData.PointIndex = i
lbl.Style.ForeColor = Color.white
lbl.Style.backcolor= Color.green
lbl.style.font = new font("宋体", 10)
\'\' lbl.Compass = LabelCompassEnum.east
lbl.Visible = True
Next
Dim cm d As new SQLCommand
cmd.Co nnectionName=Functions.Execute("返回数据源")
cmd.Co mmandText=sql
Dim dt As DataTable
dt=cmd.ExecuteReader
Dim s As String="销售统计"
Dim g As New GroupTableBuilder(s, dt)
g.Groups.AddDef("客户简称")
g.Groups.AddDef("客服")
g.Groups.AddDef("业务员")
g.Groups.AddDef("制单日期", DateGroupEnum.Year, "年")
g.Groups.AddDef("制单日期", "月")
g.Totals.AddDef("金额")
g.Build()
Tables(s).Sort="金额 desc "
Dim Chart As WinForm.Chart \'定义一个图表变量
Dim Series As WinForm.ChartSeries \'定义一个图系变量
Dim t As Table = Tables(s) \'定义一个变量t引用数据表
Chart= e.Form.Controls("Chart2") \' 引用窗口中的图表
Chart.AxisX.ClearValueLabel()
Chart.AxisY.ClearValueLabel()
Chart.ChartType = ChartTypeEnum.Pie \'图表1类型改为Bar(条形)
Chart.SeriesList.Clear
Chart.SeriesList2.Clear
For Each r As Row In t.Rows
If r("金额")>0 Then
Series = Chart.SeriesList.Add() \'增加一个图系
Series.Length = 1 \'一个系列只能包括一个值
Series.Text = r("客户简称") & "(" & math.round(r("金额"),2) & ")元" \'设置图系的标题
Series.Y(0) = math.round(r("金额"),2) \'指定值
Series.TooltipText = r("客户简称") & "发货金额:" & math.round(r("金额"),2) & "元"
Series.DataLabelText =math.round(r("金额")/t.Compute("sum(金额)"),4) *100 & "%" \'计算百分比
End If
Next
Series = Chart.SeriesList.Add() \'增加一个图系
Series.Length = 1 \'一个系列只能包括一个值
Dim db As Double=math.round(t.Compute("sum(金额)")/10000,2)
Series.Text = "发货总金额:" & db & "万元" \'设置图系的标题
\'\'Series.Y(0) = db \'指定值
Series.TooltipText = "发货总金额:" & db & "万元"
Chart.LegendVisible = True \'显示图列
Chart.LegendCompass= CompassEnum.East \'图列显示在东方(右方)