以文本方式查看主题
- Foxtable(狐表) (http://foxtable.com/bbs/index.asp)
-- 专家坐堂 (http://foxtable.com/bbs/list.asp?boardid=2)
---- 求助:图表代码编写 (http://foxtable.com/bbs/dispbbs.asp?boardid=2&id=122306)
|
-- 作者:cxmxjwlmq
-- 发布时间:2018/7/23 0:36:00
-- 求助:图表代码编写
各位老师:窗口2用代码编写图表时,遇到以下三个问题求助:
1、图表怎样显示成百分比?
2、我已经把表dtb.Build(True),怎么还在界面显示?
3、系统中标签数据的字体怎么用代码调用成设置的宋体,5号字?
请各位老师费心!
谢谢!
|
-- 作者:有点甜
-- 发布时间:2018/7/23 9:17:00
--
Dim dtb As New DataTableBuilder("统计") dtb.AddDef("年度", Gettype(String), 32) dtb.AddDef("一月", Gettype(Double)) dtb.AddDef("二月", Gettype(Double)) dtb.AddDef("三月", Gettype(Double)) dtb.AddDef("四月", Gettype(Double)) dtb.AddDef("五月", Gettype(Double)) dtb.AddDef("六月", Gettype(Double)) dtb.AddDef("七月", Gettype(Double)) dtb.AddDef("八月", Gettype(Double)) dtb.AddDef("九月", Gettype(Double)) dtb.AddDef("十月", Gettype(Double)) dtb.AddDef("十一月", Gettype(Double)) dtb.AddDef("十二月", Gettype(Double)) dtb.Build() \'MainTable= Tables("统计") With Tables("统计") .Position = .Rows.Count - 1 End With Dim t As Table = Tables("统计") Dim cr = t.Current Dim nr As Row = t.AddNew(2) If t.Current Is Nothing OrElse t.Current.Index = t.Rows.count-1 Then nr.move(cr.Index+1) End If nr("年度") = "2017下线合格率" nr("一月") = 0.2 nr("二月") = 0.5 nr("三月") = 0.4 nr("四月") = 0.1 nr("五月") = 0.3 nr("六月") = 0.7 nr("七月") = 0.2 nr("八月") = 0.8 nr("九月") = 0.4 nr("十月") = 0.9 nr("十一月") = 0.5 nr("十二月") = 0.3 Dim b As New XLS.Book Dim s As XLS.Sheet = b.Sheets(0) Dim Chart As New ChartBuilder \'定义一个图表变量 Dim Series As WinForm.ChartSeries \'定义一个图系变量 Chart.DataSource = "统计" \'设置绑定表 Chart.ChartType = ChartTypeEnum.XYPlot \'设置图表类型-XYPlot线型(默认,可不设置)-Bar条形 Chart.SeriesList.Clear()
Dim bchart1 = Chart.basecontrol Dim lbls = bChart1.ChartLabels For r As Integer = 0 To t.Rows.count - 1 Series = Chart.SeriesList.Add() \'增加一个图系 Series.Text = t.rows(r)("年度") \'设置图系的标题 Series.Length = t.Cols.Count - 1 \'设置图系的长度 For c As Integer = 1 To t.Cols.count - 1 Series.X(c - 1) = c - 1 Series.Y(c - 1) = t.Rows(r)(c) Chart.AxisX.SetValueLabel(c - 1, t.Cols(c).caption) \'指定字符表示 Dim lbl As C1.Win.C1Chart.Label = lbls.LabelsCollection.AddNewLabel() lbl.Text = Format(val(series.y(c-1)), "0.00%") lbl.AttachMethod = C1.Win.C1Chart.AttachMethodEnum.DataIndex lbl.AttachMethodData.GroupIndex = 0 lbl.AttachMethodData.SeriesIndex = r lbl.AttachMethodData.PointIndex = c-1 lbl.Style.ForeColor = Color.Red lbl.style.font = new font("宋体", 15) lbl.Compass = LabelCompassEnum.South lbl.Visible = True Next Next Chart.PrintWidth = 150 \'图表宽度为150毫米 Chart.PrintHeight = 100 \'图标高度为100毫米 Dim fnt As New Font("宋休",6) \'设置图表中所有的字体 Chart.AxisX.Font = fnt \'X轴调用设定的字体 Chart.AxisY.Font = fnt \'Y轴调用设定的字体 Chart.LegendFont = fnt \'图例调用设定的字体 Chart.HeaderText = "整车下线合格率趋势" \'给图表上标题进行赋值 Chart.AxisX.AnnoRotation = - 0 \'X轴标示逆时针旋转角度 Chart.AxisX.AnnoFormatString = "0月" \'设定X轴第一个,优化X轴 Chart.AxisX.GridMajorVisible = True \'显示主轴X网格线 Chart.AxisY.GridMajorVisible = True \'显示主轴Y网格线 Chart.AxisX.AnnoWithLabels = True \'启用字符标示 Chart.LegendVisible = True \'显示图例 Chart.LegendCompass= CompassEnum.South \'图例显示在南方(底端) \'设置系列线及标志 Chart.SeriesList(0).LineColor = Color.Green Chart.SeriesList(0).LineThickNess= 2 \'给第一个系列的线条宽度 Chart.SeriesList(0).MarkShape = MarkShapeEnum.Dot \'设置数据点标记的形状-圆点 Chart.SeriesList(0).MarkColor = Color.Red \'设置数据点标记的颜色-绿色 Chart.SeriesList(0).MarkSize= 3 \'给数据点标志线条直径 \'Chart.SeriesList(0).DataLabelText = "{#YVAL}" \'显示第一个系列数据标签 \'Chart.SeriesList(0).DataLabelText.Font= fnt \'数据标签的字体\' \'Chart.SeriesList(1).LineColor = Color.Red \'Chart.SeriesList(1).LineThickNess= 2 \'给第一个系列的线条宽度 \'Chart.SeriesList(1).MarkShape = MarkShapeEnum.Dot \'设置数据点标记的形状-圆点 \'Chart.SeriesList(1).MarkColor = Color.Green \'设置数据点标记的颜色-绿色 \'Chart.SeriesList(1).MarkSize= 3 \'给数据点标志线条直径 \'Chart.SeriesList(1).DataLabelText = "{#YVAL}" \'显示第一个系列数据标签
s(t.rows.Count + 6,6).Value = New XLS.Picture((Chart.Image)) \'在表的第十二列第十二行插入图表 t.visible = False b.Save("c:\\reports\\test.xls") Dim Proc As New Process Proc.File = "c:\\reports\\test.xls" Proc.Start()
|
-- 作者:cxmxjwlmq
-- 发布时间:2018/7/24 14:43:00
--
谢谢甜老师费心指教!
追问两个问题:
1、Chart.AxisX.AnnoFormatString = "0月" \'设定X轴第一个,优化X轴 这个代码我想让图系和坐标向右移一格,不让一月拆线点落在Y轴上,但没有作用?
2、Y轴刻度怎么能显示成百分比?
请老师指教!
|
-- 作者:有点甜
-- 发布时间:2018/7/24 15:05:00
--
[此贴子已经被作者于2018/7/24 15:05:05编辑过]
|
-- 作者:有点甜
-- 发布时间:2018/7/24 15:08:00
--
Dim dtb As New DataTableBuilder("统计") dtb.AddDef("年度", Gettype(String), 32) dtb.AddDef("一月", Gettype(Double)) dtb.AddDef("二月", Gettype(Double)) dtb.AddDef("三月", Gettype(Double)) dtb.AddDef("四月", Gettype(Double)) dtb.AddDef("五月", Gettype(Double)) dtb.AddDef("六月", Gettype(Double)) dtb.AddDef("七月", Gettype(Double)) dtb.AddDef("八月", Gettype(Double)) dtb.AddDef("九月", Gettype(Double)) dtb.AddDef("十月", Gettype(Double)) dtb.AddDef("十一月", Gettype(Double)) dtb.AddDef("十二月", Gettype(Double)) dtb.Build() \'MainTable= Tables("统计") With Tables("统计") .Position = .Rows.Count - 1 End With Dim t As Table = Tables("统计") Dim cr = t.Current Dim nr As Row = t.AddNew(2) If t.Current Is Nothing OrElse t.Current.Index = t.Rows.count-1 Then nr.move(cr.Index+1) End If nr("年度") = "2017下线合格率" nr("一月") = 0.2 nr("二月") = 0.5 nr("三月") = 0.4 nr("四月") = 0.1 nr("五月") = 0.3 nr("六月") = 0.7 nr("七月") = 0.2 nr("八月") = 0.8 nr("九月") = 0.4 nr("十月") = 0.9 nr("十一月") = 0.5 nr("十二月") = 0.3 Dim b As New XLS.Book Dim s As XLS.Sheet = b.Sheets(0) Dim Chart As New ChartBuilder \'定义一个图表变量 Dim Series As WinForm.ChartSeries \'定义一个图系变量 Chart.DataSource = "统计" \'设置绑定表 Chart.ChartType = ChartTypeEnum.XYPlot \'设置图表类型-XYPlot线型(默认,可不设置)-Bar条形 Chart.SeriesList.Clear()
Dim bchart1 = Chart.basecontrol Dim lbls = bChart1.ChartLabels For r As Integer = 0 To t.Rows.count - 1 Series = Chart.SeriesList.Add() \'增加一个图系 Series.Text = t.rows(r)("年度") \'设置图系的标题 Series.Length = t.Cols.Count \'设置图系的长度 For c As Integer = 1 To t.Cols.count - 1 Series.X(c) = c - 1 Series.Y(c) = t.Rows(r)(c) Chart.AxisX.SetValueLabel(c, t.Cols(c).caption) \'指定字符表示 Dim lbl As C1.Win.C1Chart.Label = lbls.LabelsCollection.AddNewLabel() lbl.Text = Format(val(series.y(c)), "0.00%") lbl.AttachMethod = C1.Win.C1Chart.AttachMethodEnum.DataIndex lbl.AttachMethodData.GroupIndex = 0 lbl.AttachMethodData.SeriesIndex = r lbl.AttachMethodData.PointIndex = c lbl.Style.ForeColor = Color.Red lbl.style.font = new font("宋体", 15) lbl.Compass = LabelCompassEnum.South lbl.Visible = True Next Next Chart.PrintWidth = 150 \'图表宽度为150毫米 Chart.PrintHeight = 100 \'图标高度为100毫米 Dim fnt As New Font("宋休",6) \'设置图表中所有的字体 Chart.AxisX.Font = fnt \'X轴调用设定的字体 Chart.AxisY.Font = fnt \'Y轴调用设定的字体 Chart.LegendFont = fnt \'图例调用设定的字体 Chart.HeaderText = "整车下线合格率趋势" \'给图表上标题进行赋值 Chart.AxisX.AnnoRotation = - 0 \'X轴标示逆时针旋转角度 Chart.AxisX.AnnoFormatString = "0月" \'设定X轴第一个,优化X轴 Chart.AxisX.GridMajorVisible = True \'显示主轴X网格线 Chart.AxisY.GridMajorVisible = True \'显示主轴Y网格线 Chart.AxisX.AnnoWithLabels = True \'启用字符标示 Chart.LegendVisible = True \'显示图例 Chart.LegendCompass= CompassEnum.South \'图例显示在南方(底端) \'设置系列线及标志 Chart.SeriesList(0).LineColor = Color.Green Chart.SeriesList(0).LineThickNess= 2 \'给第一个系列的线条宽度 Chart.SeriesList(0).MarkShape = MarkShapeEnum.Dot \'设置数据点标记的形状-圆点 Chart.SeriesList(0).MarkColor = Color.Red \'设置数据点标记的颜色-绿色 Chart.SeriesList(0).MarkSize= 3 \'给数据点标志线条直径 \'Chart.SeriesList(0).DataLabelText = "{#YVAL}" \'显示第一个系列数据标签 \'Chart.SeriesList(0).DataLabelText.Font= fnt \'数据标签的字体\' \'Chart.SeriesList(1).LineColor = Color.Red \'Chart.SeriesList(1).LineThickNess= 2 \'给第一个系列的线条宽度 \'Chart.SeriesList(1).MarkShape = MarkShapeEnum.Dot \'设置数据点标记的形状-圆点 \'Chart.SeriesList(1).MarkColor = Color.Green \'设置数据点标记的颜色-绿色 \'Chart.SeriesList(1).MarkSize= 3 \'给数据点标志线条直径 \'Chart.SeriesList(1).DataLabelText = "{#YVAL}" \'显示第一个系列数据标签
s(t.rows.Count + 6,6).Value = New XLS.Picture((Chart.Image)) \'在表的第十二列第十二行插入图表 t.visible = False b.Save("c:\\reports\\test.xls") Dim Proc As New Process Proc.File = "c:\\reports\\test.xls" Proc.Start()
|
-- 作者:cxmxjwlmq
-- 发布时间:2018/7/24 16:45:00
--
老师:按你的还是和二楼你回复的一样呀,没有变化!
|
-- 作者:有点甜
-- 发布时间:2018/7/24 16:58:00
--
Dim dtb As New DataTableBuilder("统计") dtb.AddDef("年度", Gettype(String), 32) dtb.AddDef("一月", Gettype(Double)) dtb.AddDef("二月", Gettype(Double)) dtb.AddDef("三月", Gettype(Double)) dtb.AddDef("四月", Gettype(Double)) dtb.AddDef("五月", Gettype(Double)) dtb.AddDef("六月", Gettype(Double)) dtb.AddDef("七月", Gettype(Double)) dtb.AddDef("八月", Gettype(Double)) dtb.AddDef("九月", Gettype(Double)) dtb.AddDef("十月", Gettype(Double)) dtb.AddDef("十一月", Gettype(Double)) dtb.AddDef("十二月", Gettype(Double)) dtb.Build() \'MainTable= Tables("统计") With Tables("统计") .Position = .Rows.Count - 1 End With Dim t As Table = Tables("统计") Dim cr = t.Current Dim nr As Row = t.AddNew(2) If t.Current Is Nothing OrElse t.Current.Index = t.Rows.count-1 Then nr.move(cr.Index+1) End If nr("年度") = "2017下线合格率" nr("一月") = 0.2 nr("二月") = 0.5 nr("三月") = 0.4 nr("四月") = 0.1 nr("五月") = 0.3 nr("六月") = 0.7 nr("七月") = 0.2 nr("八月") = 0.8 nr("九月") = 0.4 nr("十月") = 0.9 nr("十一月") = 0.5 nr("十二月") = 0.3 Dim b As New XLS.Book Dim s As XLS.Sheet = b.Sheets(0) Dim Chart As New ChartBuilder \'定义一个图表变量 Dim Series As WinForm.ChartSeries \'定义一个图系变量 Chart.DataSource = "统计" \'设置绑定表 Chart.ChartType = ChartTypeEnum.XYPlot \'设置图表类型-XYPlot线型(默认,可不设置)-Bar条形 Chart.SeriesList.Clear()
Dim bchart1 = Chart.basecontrol Dim lbls = bChart1.ChartLabels For r As Integer = 0 To t.Rows.count - 1 Series = Chart.SeriesList.Add() \'增加一个图系 Series.Text = t.rows(r)("年度") \'设置图系的标题 Series.Length = t.Cols.Count \'设置图系的长度 Series.X(0) = 0 Series.Y(0) = 0 For c As Integer = 1 To t.Cols.count - 1 Series.X(c) = c Series.Y(c) = t.Rows(r)(c) Chart.AxisX.SetValueLabel(c, t.Cols(c).caption) \'指定字符表示 Dim lbl As C1.Win.C1Chart.Label = lbls.LabelsCollection.AddNewLabel() lbl.Text = Format(val(series.y(c)), "0.00%") lbl.AttachMethod = C1.Win.C1Chart.AttachMethodEnum.DataIndex lbl.AttachMethodData.GroupIndex = 0 lbl.AttachMethodData.SeriesIndex = r lbl.AttachMethodData.PointIndex = c lbl.Style.ForeColor = Color.Red lbl.style.font = new font("宋体", 15) lbl.Compass = LabelCompassEnum.South lbl.Visible = True Next Next Chart.PrintWidth = 150 \'图表宽度为150毫米 Chart.PrintHeight = 100 \'图标高度为100毫米 Dim fnt As New Font("宋休",6) \'设置图表中所有的字体 Chart.AxisX.Font = fnt \'X轴调用设定的字体 Chart.AxisY.Font = fnt \'Y轴调用设定的字体 Chart.LegendFont = fnt \'图例调用设定的字体 Chart.HeaderText = "整车下线合格率趋势" \'给图表上标题进行赋值 Chart.AxisX.AnnoRotation = - 0 \'X轴标示逆时针旋转角度 Chart.AxisX.AnnoFormatString = "0月" \'设定X轴第一个,优化X轴 Chart.AxisX.GridMajorVisible = True \'显示主轴X网格线 Chart.AxisY.GridMajorVisible = True \'显示主轴Y网格线 Chart.AxisX.AnnoWithLabels = True \'启用字符标示 Chart.LegendVisible = True \'显示图例 Chart.LegendCompass= CompassEnum.South \'图例显示在南方(底端) \'设置系列线及标志 Chart.SeriesList(0).LineColor = Color.Green Chart.SeriesList(0).LineThickNess= 2 \'给第一个系列的线条宽度 Chart.SeriesList(0).MarkShape = MarkShapeEnum.Dot \'设置数据点标记的形状-圆点 Chart.SeriesList(0).MarkColor = Color.Red \'设置数据点标记的颜色-绿色 Chart.SeriesList(0).MarkSize= 3 \'给数据点标志线条直径 \'Chart.SeriesList(0).DataLabelText = "{#YVAL}" \'显示第一个系列数据标签 \'Chart.SeriesList(0).DataLabelText.Font= fnt \'数据标签的字体\' \'Chart.SeriesList(1).LineColor = Color.Red \'Chart.SeriesList(1).LineThickNess= 2 \'给第一个系列的线条宽度 \'Chart.SeriesList(1).MarkShape = MarkShapeEnum.Dot \'设置数据点标记的形状-圆点 \'Chart.SeriesList(1).MarkColor = Color.Green \'设置数据点标记的颜色-绿色 \'Chart.SeriesList(1).MarkSize= 3 \'给数据点标志线条直径 \'Chart.SeriesList(1).DataLabelText = "{#YVAL}" \'显示第一个系列数据标签
s(t.rows.Count + 6,6).Value = New XLS.Picture((Chart.Image)) \'在表的第十二列第十二行插入图表 t.visible = False b.Save("c:\\reports\\test.xls") Dim Proc As New Process Proc.File = "c:\\reports\\test.xls" Proc.Start()
|