Foxtable(狐表)用户栏目专家坐堂 → 求助:图表代码编写


  共有2079人关注过本帖树形打印复制链接

主题:求助:图表代码编写

帅哥哟,离线,有人找我吗?
有点甜
  1楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:版主 帖子:85326 积分:427815 威望:0 精华:5 注册:2012/10/18 22:13:00
  发帖心情 Post By: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()


 回到顶部
帅哥哟,离线,有人找我吗?
有点甜
  2楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:版主 帖子:85326 积分:427815 威望:0 精华:5 注册:2012/10/18 22:13:00
  发帖心情 Post By:2018/7/24 15:05:00 [显示全部帖子]

 

[此贴子已经被作者于2018/7/24 15:05:05编辑过]

 回到顶部
帅哥哟,离线,有人找我吗?
有点甜
  3楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:版主 帖子:85326 积分:427815 威望:0 精华:5 注册:2012/10/18 22:13:00
  发帖心情 Post By: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()


 回到顶部
帅哥哟,离线,有人找我吗?
有点甜
  4楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:版主 帖子:85326 积分:427815 威望:0 精华:5 注册:2012/10/18 22:13:00
  发帖心情 Post By: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()


 回到顶部