以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.net/bbs/index.asp)
--  专家坐堂  (http://foxtable.net/bbs/list.asp?boardid=2)
----  咨询  (http://foxtable.net/bbs/dispbbs.asp?boardid=2&id=97645)

--  作者:cqli
--  发布时间:2017/3/16 10:06:00
--  咨询
你好!
希望X轴显示月份和月份对应的列1内容,Y轴按X轴进行列2数据统计。帮忙修改下代码,谢谢!

Dim Chart As WinForm.Chart

        Dim Series As WinForm.ChartSeries

        Dim y As Integer = Date.Today.Year

        Dim m As Integer = Date.Today.Month

        Dim tb As DataTable = DataTables("A")

        Chart = e.Form.Controls("Chart1")

        Chart.ChartType = ChartTypeEnum.Bar

        Chart.SeriesList.Clear()

        Chart.AxisX.ClearValueLabel \'清除所有通过SetValueLabel设置的数值字符标示

        Series = Chart.SeriesList.Add()

        Series.Length = 6

        Dim td As Date = new Date(Date.Today.Year, Date.Today.Month, 1)

        For i As Integer = 0 To 5

            Dim d As Date= td.AddMonths(-i)

            Dim lst As List(Of String) = tb.SQLGetValues("1","日期 >= \'" & d & "\' and 日期 < \'" & d.AddMonths(1) & "\'")

            Series.X(i) = i

            Series.Y(i) = val(tb.SQLCompute("Sum(2)","日期 >= \'" & d & "\' and 日期 < \'" & d.AddMonths(1) & "\' and [1] = \'" & lst(i) & "\'"))

            Chart.AxisX.SetValueLabel(i, Format(d, "yyyy-MM"))

            Chart.HeaderText="数量()"   \'设置图表的上标题

            Chart.AxisX.AnnoWithLabels = True \'启用字符标示

            \'Chart.LegendVisible = True

            \'Chart.LegendCompass= CompassEnum.South

            Series.DataLabelText = "{#YVAL}"    \'图中显示数据

            Chart.VisualEffect = True           \'图更漂亮

            Chart.SeriesList(0).LineColor= Color.GreenYellow

        Next


--  作者:有点色
--  发布时间:2017/3/16 10:07:00
--  
 上传实例说明。
--  作者:cqli
--  发布时间:2017/3/16 10:38:00
--  
你好!
X轴按月显示的同时显示对应月份的类型

--  作者:有点色
--  发布时间:2017/3/16 11:04:00
--  
 上传具体实例测试。
--  作者:cqli
--  发布时间:2017/3/16 20:48:00
--  
 下载信息  [文件大小:   下载次数: ]
图片点击可在新窗口打开查看点击浏览该文件:管理项目1.rar


--  作者:有点色
--  发布时间:2017/3/17 1:47:00
--  

Dim Chart As WinForm.Chart
Dim Series As WinForm.ChartSeries
Dim y As Integer = Date.Today.Year
Dim m As Integer = Date.Today.Month
Dim tb As DataTable = DataTables("表A")
Chart = e.Form.Controls("Chart1")
Chart.ChartType = ChartTypeEnum.Bar
Chart.SeriesList.Clear()
Chart.AxisX.ClearValueLabel \'清除所有通过SetValueLabel设置的数值字符标示

Dim td As Date = new Date(Date.Today.Year, Date.Today.Month, 1)
Dim lst As List(Of String) = tb.SQLGetValues("类型", "类型 is not null")
For Each s As String In lst
    series = Chart.SeriesList.Add
    series.text = s
    series.Length = 6
   
    For i As Integer = 0 To 5
        Dim d As Date= td.AddMonths(-i)
        Series.X(i) = i
        Series.Y(i) = val(tb.SQLCompute("Sum(数量)","日期 >= #" & d & "# and 日期 < #" & d.AddMonths(1) & "# and 类型 = \'" & s & "\'"))
        Chart.AxisX.SetValueLabel(i, Format(d, "yyyy-MM"))
       
        Series.DataLabelText = "{#YVAL}"    \'图中显示数据
       
    Next
Next
Chart.HeaderText="数量(件)"   \'设置图表的上标题
Chart.AxisX.AnnoWithLabels = True \'启用字符标示
Chart.VisualEffect = True \'加上这一行,让你的图表更漂亮
Chart.LegendVisible = True \'显示图列
Chart.LegendCompass= CompassEnum.South \'图列显示在南方(底端)