Dim tjnj As String = 2019
Dim tjlb As String = "二诊"
Dim dwls() As String = {"分数线","全区合计"}
Dim dlg As New SaveFileDialog '定义一个新的SaveFileDialog
dlg.Filter= "Excel文件|*.xls" '设置筛选器
If dlg.ShowDialog = DialogResult.Ok Then '如果用户单击了确定按钮
'生成图表
Dim Chart As New ChartBuilder '定义一个图表变量
Dim Series As WinForm.ChartSeries '定义一个图系变量
Dim t As Table = Tables(tjnj &"级"& tjlb & "市区目标对比") '定义一个变量t引用数据表
Chart.ChartType = ChartTypeEnum.Bar '图表类型改为Bar(条形)
Chart.SeriesList.Clear() '清除图表原来的图系
Dim xms() As String = {"分数线","全区合计","梁平中学","红旗中学","梁平一中","西大实中","屏锦中学","袁驿中学","福禄中学"}
Dim nms2() As String = {"物理类","历史类","合计"}
Dim dhs() As String = {"重点","本科","专科"}
Dim nms3() As String = {"区级","市级"}
For r As Integer = 0 To nms3.Length - 1 '横坐标开始列位置,从区级开始
Series = Chart.SeriesList.Add() '增加一个图系
Series.Text = nms3(r) '设置图系的标题
series.length = xms.Length * nms2.Length * dhs.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 dhs.Length - 1
Series.X(k*nms2.Length+j) = k*nms2.Length+j
Series.Y(k*nms2.Length+j) = val(t.Compute("sum(" & nms2(i) & dhs(j) & nms3(r) & ")", "单位 = '" & xms(k) & "'"))
Chart.AxisX.SetValueLabel(k*dhs.Length+j, xms(k) & nms2(i) & dhs(j))
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 '图列显示在南方(底端)
Chart.AxisX.Text = "类别:" & tjlb
chart.LegendText = "图例:市区级"
Chart.BarClusterWidth = 80
Chart.AxisY.Text = "重点人数"
Chart.PrintWidth = 360
Chart.PrintHeight = 180
'保存文件
t.SaveExcel(dlg.FileName, tjnj &"级"& tjlb & "市区目标对比") '保存文件
Dim b As New XLS.Book(dlg.FileName)
Dim s As XLS.Sheet = b.Sheets(tjnj &"级"& tjlb & "市区目标对比")
s(t.rows.Count + 3,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,2).Text.EndsWith(Hj) Then '如果指定列(sheet(i,2)第3列单位中含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)
'DataTables.Delete( tjnj &"级"& tjlb & "市区目标对比")
End If
导出后生成的图表怎么重叠("物理类","历史类","合计")了,只显示了“合计”栏的图表,如何修改代码?请指教。谢谢!