以文本方式查看主题 - Foxtable(狐表) (http://foxtable.com/bbs/index.asp) -- 专家坐堂 (http://foxtable.com/bbs/list.asp?boardid=2) ---- [求助]统计表导出并生成图表问题2 (http://foxtable.com/bbs/dispbbs.asp?boardid=2&id=176979) |
||||
-- 作者:cqlpjks -- 发布时间:2022/5/5 16:31:00 -- [求助]统计表导出并生成图表问题2 执行结果:
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 导出后生成的图表怎么重叠("物理类","历史类","合计")了,只显示了“合计”栏的图表,如何修改代码?请指教。谢谢! [此贴子已经被作者于2022/5/5 16:32:32编辑过]
|
||||
-- 作者:有点蓝 -- 发布时间:2022/5/5 16:39:00 -- 请上传实例测试,请提供窗口图表控件的测试例子 |
||||
-- 作者:cqlpjks -- 发布时间:2022/5/5 16:56:00 -- 测试事例:
窗口1,“导出并生成图表”按钮
[此贴子已经被作者于2022/5/5 16:58:25编辑过]
|
||||
-- 作者:有点蓝 -- 发布时间:2022/5/5 17:14:00 -- 实际需要什么效果? |
||||
-- 作者:cqlpjks -- 发布时间:2022/5/5 17:22:00 -- 市区目标对比表: 此主题相关图片如下:市区目标对比表.png 只显示了红色部分的“合计”栏的图表,"物理类","历史类"都要显示。
[此贴子已经被作者于2022/5/5 17:22:08编辑过]
|
||||
-- 作者:有点蓝 -- 发布时间:2022/5/5 17:24:00 -- 重叠了,不是没有显示,我要搞清楚实际效果是怎么样的,手绘截图说明一下 |
||||
-- 作者:cqlpjks -- 发布时间:2022/5/6 10:11:00 -- 市区目标对比导出图表结果: 此主题相关图片如下:市区目标对比图表结果.png 统计表中的专科(红色部分)不需要图表显示。
|
||||
-- 作者:有点蓝 -- 发布时间:2022/5/6 10:15:00 -- Dim dhs() As String = {"重点","本科"} |
||||
-- 作者:cqlpjks -- 发布时间:2022/5/6 10:21:00 -- 要求的图表显示是7楼上图。 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 如何修改代码?
|
||||
-- 作者:有点蓝 -- 发布时间:2022/5/6 10:29:00 -- 试试 Series.X(k*nms2.Length*dhs.length+j) = k*nms2.Length*dhs.length+j Series.Y(k*nms2.Length*dhs.length+j) = val(t.Compute("sum(" & nms2(i) & dhs(j) & nms3(r) & ")", "单位 = \'" & xms(k) & "\'")) Chart.AxisX.SetValueLabel(k*nms2.Length*dhs.length+j, xms(k) & nms2(i) & dhs(j)) |