Dim tjlb1 As String = e.Form.Controls("类别").text '统计类别
Dim tjlb2 As String = e.Form.Controls("类别2").text '对照类别
Dim tjlbs() As String = {tjlb1,tjlb2}
Dim tjnj1 As String = e.Form.Controls("年级").text '统计年级
Dim tjnj2 As String = tjnj1 - 1 '对照年级
Dim tjnj3 As String = tjnj1 - 2 '对照年级
Dim dlg As New SaveFileDialog '定义一个新的SaveFileDialog
dlg.Filter= "Excel文件|*.xls" '设置筛选器
If dlg.ShowDialog = DialogResult.Ok Then '如果用户单击了确定按钮
'生成图表
Dim xms() As String = {"特殊类分数线","特殊类上线人数","600分及以上","最高分","最高分排名"}
Dim nms2() As String = {"历史类","物理类","合计"}
Dim nms3() As String = {tjnj1,tjnj2,tjnj3}
Dim t As Table = Tables(tjnj3 & "-" & tjnj1 &"级分析对照表") '定义一个变量t引用数据表
Dim Chart As New ChartBuilder '定义一个图表变量
Dim Series As WinForm.ChartSeries '定义一个图系变量
Chart.ChartType = ChartTypeEnum.Bar '图表类型改为Bar(条形)
Chart.SeriesList.Clear() '清除图表原来的图系
'Dim idx As Integer = 0
For r As Integer = 0 To nms3.Length - 1 '横坐标开始列位置
Series = Chart.SeriesList.Add() '增加一个图系
Series.Text = nms3(r) '设置图系的标题
series.length = xms.Length * nms2.Length
For k As Integer = 0 To xms.Length - 1
For i As Integer = 0 To nms2.Length - 1
For j As Integer = 0 To tjlbs.Length - 1
Series.X(k*nms2.Length+i) = k*nms2.Length+i
Series.Y(k*nms2.Length+i) = val(t.Compute("sum(" & nms2(i) & nms3(r) & ")", "统计项目 = '" & xms(k) & "'And 类别 = '" & tjlb1 & "'"))
Chart.AxisX.SetValueLabel(k*nms2.Length+i, xms(k) & nms2(i) )
Next
Next
Next
series.DataLabelCompass = LabelCompassEnum.North
Series.DataLabelText = "{#YVAL}"
Next
Chart.ChartType2 = ChartTypeEnum.Bar '图表类型改为Bar(条形)
Chart.SeriesList2.Clear() '清除图表原来的图系
Series = Chart.SeriesList2.Add() '增加第二个图系
For r As Integer = 0 To nms3.Length - 1 '横坐标开始列位置
Series.Text = nms3(r) '设置图系的标题
series.length = xms.Length * nms2.Length
For k As Integer = 0 To xms.Length - 1
For i As Integer = 0 To nms2.Length - 1
For j As Integer = 0 To tjlbs.Length - 1
Series.X(k*nms2.Length+i) = k*nms2.Length+i
Series.Y(k*nms2.Length+i) = val(t.Compute("sum(" & nms2(i) & nms3(r) & ")", "统计项目 = '" & xms(k) & "'And 类别 = '" & tjlb2 & "'"))
Chart.AxisX.SetValueLabel(k*nms2.Length+i, xms(k) & nms2(i) )
Next
Next
Next
series.DataLabelCompass = LabelCompassEnum.North
Series.DataLabelText = "{#YVAL}"
Next
Chart.AxisX.AnnoWithLabels = True '启用字符标示
Chart.AxisX.AnnoRotation = - 45 'X轴标示逆时针旋转45度
Chart.LegendVisible = True '显示图列
Chart.LegendCompass= CompassEnum.South '图列显示在南方(底端)
For Each tjlb As String In tjlbs
Chart.AxisX.Text = "类别:" & tjlb
Next
chart.LegendText = "图例:年级"
Chart.BarClusterWidth = 80
Chart.AxisY.Text = "分数线 重点人数"
Chart.PrintWidth = 360
Chart.PrintHeight = 180
'保存文件
t.SaveExcel(dlg.FileName, tjnj3 & "-" & tjnj1 &"级分析对照表") '保存文件
Dim b As New XLS.Book(dlg.FileName)
Dim s As XLS.Sheet = b.Sheets(tjnj3 & "-" & tjnj1 &"级分析对照表")
s(t.rows.Count + 2,1).Value = New XLS.Picture(Chart.Image)
Dim Style As Xls.Style = b.NewStyle '新建一个样式
'单元格内容自动换行
Style.WordWrap = XLS.LineStyleEnum.Thin '单元格内容自动换行
'加网格线
Style.AlignHorz = XLS.AlignHorzEnum.Center '居中
Style.AlignVert = XLS.AlignVertEnum.Center '居中
Style.BorderTop = XLS.LineStyleEnum.Thin '上边框
Style.BorderBottom = XLS.LineStyleEnum.Thin '下边框
Style.BorderLeft = XLS.LineStyleEnum.Thin '左边框
Style.BorderRight = XLS.LineStyleEnum.Thin '右边框
'上下左右边框颜色
Style.BorderColorTop = Color.Black '黑色
Style.BorderColorBottom = Color.Black
Style.BorderColorLeft = Color.Black
Style.BorderColorRight = Color.Black
For i As Integer = 0 To s.Rows.count -2
For n As Integer = 0 To s.Cols.count -1
s(i,n).Style = Style
Next
Next
'符合条件的行字体变红加粗
Style = b.NewStyle
Style.ForeColor = Color.Red '样式的字体颜色设为红色
Style.Font = new font("宋体",9,FontStyle.Bold) '宋体,9号,加粗
Style.AlignHorz = XLS.AlignHorzEnum.Center '居中
Style.AlignVert = XLS.AlignVertEnum.Center '居中
Style.BorderTop = XLS.LineStyleEnum.Thin '上边框
Style.BorderBottom = XLS.LineStyleEnum.Thin '下边框
Style.BorderLeft = XLS.LineStyleEnum.Thin '左边框
Style.BorderRight = XLS.LineStyleEnum.Thin '右边框
'上下左右边框颜色
Style.BorderColorTop = Color.Black '黑色
Style.BorderColorBottom = Color.Black
Style.BorderColorLeft = Color.Black
Style.BorderColorRight = Color.Black
For i As Integer = 0 To s.Rows.count -1
Dim Hjs() As String = {"特殊类分数线"}
For Each Hj As String In Hjs
If s(i,0).Text.EndsWith(Hj) Then '如果指定列(sheet(i,1)第2列单位中含Hj字符存在
For n As Integer = 0 To s.Cols.count -1
s(i,n).Style = Style
Next
End If
Next
Next
b.Save(dlg.FileName) '将生成的图表保存为文件.
End If
e.Form.Controls("Label1").Text = "近三届分析对照表已导出并删除!"
我想“一诊”、“二诊”各生成一个图表,如何修改增加第二个图系的代码?请指教。谢谢!