以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.com/bbs/index.asp)
--  专家坐堂  (http://foxtable.com/bbs/list.asp?boardid=2)
----  图表的跳过统计表用法  (http://foxtable.com/bbs/dispbbs.asp?boardid=2&id=179368)

--  作者:237756360
--  发布时间:2022/8/20 13:46:00
--  图表的跳过统计表用法
图片点击可在新窗口打开查看
........................................................................
上图是名为“订单”的SQL数据表,每分钟记录一次数据。

求助:
我想用编码方式跳过生成统计表的方法生成图表显示张三全天每个整点的用电量,X轴为时间,Y轴为电量,代码应该如何更改
Dim Chart As WinForm.Chart \'定义一个图表变量
Dim Series As WinForm.ChartSeries \'定义一个图系变量
Dim tbl As DataTable = DataTables("订单") \'定义一个变量tbl引用数据表
Dim lst As New List(Of String)
lst.Add( "00:00")
lst.Add( "01:00")
lst.Add( "02:00")
lst.Add( "03:00")
lst.Add( "04:00")
lst.Add( "05:00")
lst.Add( "06:00")
lst.Add( "07:00")
lst.Add( "08:00")
lst.Add( "09:00")
lst.Add( "10:00")
lst.Add( "11:00")
lst.Add( "12:00")
lst.Add( "13:00")
lst.Add( "14:00")
lst.Add( "15:00")
lst.Add( "16:00")
lst.Add( "17:00")
lst.Add( "18:00")
lst.Add( "19:00")
lst.Add( "20:00")
lst.Add( "21:00")
lst.Add( "22:00")
lst.Add( "23:00")
Chart = e.Form.Controls("Chart1") \' 引用窗口中的图表
Chart.SeriesList.Clear() \'清除图表原来的图系
Series = Chart.SeriesList.Add() \'增加一个图系
Series.Length = lst.Count \'设置图系的长度
For i As Integer = 0 To 23\'指定每个数据点的位置
    Series.X(i) = i \'指定水平坐标
    Series.Y(i) = tbl.Find("用户 = \'张三\'") \'指定垂直坐标
    Chart.AxisX.SetValueLabel(i, lst(i)) \'指定字符表示
Next
Chart.AxisX.AnnoWithLabels = True \'启用字符标示


--  作者:有点蓝
--  发布时间:2022/8/20 14:21:00
--  
……
dim  s as string = "2022-05-10"
Series.Length = lst.Count \'设置图系的长度
For i As Integer = 0 To 23\'指定每个数据点的位置
    Series.X(i) = i \'指定水平坐标
    Series.Y(i) = tbl.Find("用户 = \'张三\' and 时间=#“ & s & " " & lst(i) & ”#") \'指定垂直坐标
    Chart.AxisX.SetValueLabel(i, lst(i)) \'指定字符表示
Next
Chart.AxisX.AnnoWithLabels = True \'启用字符标示

--  作者:237756360
--  发布时间:2022/8/20 14:36:00
--  
未将对象引用设置到对象的实例。帮忙看看错在哪儿,我上传实例了,麻烦蓝版了!
[此贴子已经被作者于2022/8/20 15:27:54编辑过]

--  作者:有点蓝
--  发布时间:2022/8/20 15:07:00
--  
应该有些整点的数据不存在。

比如是要显示整点比如“01:00”这个时间点的数据?还是说把01:00~02:00之间的数据求和作为01:00”的数据?

--  作者:237756360
--  发布时间:2022/8/20 15:10:00
--  
是整点的唯一数据 例如:   01:00:00
--  作者:237756360
--  发布时间:2022/8/20 15:11:00
--  
我上传实例了,实例中我链接了数据库,数据全!帮忙看看蓝版,我实在是弄不明白了
[此贴子已经被作者于2022/8/20 16:07:56编辑过]

--  作者:有点蓝
--  发布时间:2022/8/20 15:21:00
--  
加一个判断自己测试就知道了

dim dr as datarow = tbl.Find("用户 = \'张三\' and 时间=#“ & s & " " & lst(i) & ”#")
if dr is nothing then
Series.Y(i) =  0 \'指定垂直坐标
output.show("张三没有整点数据:" & s & " " & lst(i))
else
Series.Y(i) =  dr("电量")
edn if

--  作者:237756360
--  发布时间:2022/8/20 15:34:00
--  
未将对象引用设置到对象的实例。这个就是找不到原因。。。
Dim Chart As WinForm.Chart \'定义一个图表变量
Dim Series As WinForm.ChartSeries \'定义一个图系变量
Dim tbl As DataTable = DataTables("订单") \'定义一个变量tbl引用数据表
Dim lst As New List(Of String)
lst.Add( "00:00")
lst.Add( "01:00")
lst.Add( "02:00")
lst.Add( "03:00")
lst.Add( "04:00")
lst.Add( "05:00")
lst.Add( "06:00")
lst.Add( "07:00")
lst.Add( "08:00")
lst.Add( "09:00")
lst.Add( "10:00")
lst.Add( "11:00")
lst.Add( "12:00")
lst.Add( "13:00")
lst.Add( "14:00")
lst.Add( "15:00")
lst.Add( "16:00")
lst.Add( "17:00")
lst.Add( "18:00")
lst.Add( "19:00")
lst.Add( "20:00")
lst.Add( "21:00")
lst.Add( "22:00")
lst.Add( "23:00")
Chart = e.Form.Controls("Chart1") \' 引用窗口中的图表
Chart.SeriesList.Clear() \'清除图表原来的图系
Series = Chart.SeriesList.Add() \'增加一个图系
Dim s As String = "2022-08-10 "
Series.Length = lst.Count \'设置图系的长度
For i As Integer = 0 To 23\'指定每个数据点的位置
    Series.X(i) = i \'指定水平坐标
    Series.Y(i) = tbl.Find("用户 = \'张三\' and 时间=#" & s & " " & lst(i) & "#") \'指定垂直坐标
    Chart.AxisX.SetValueLabel(i, lst(i)) \'指定字符表示
Next
Chart.AxisX.AnnoWithLabels = True \'启用字符标示

--  作者:有点蓝
--  发布时间:2022/8/20 15:38:00
--  
看7楼
--  作者:237756360
--  发布时间:2022/8/20 16:19:00
--  
处理好了,还是蓝版厉害!
[此贴子已经被作者于2022/8/20 16:25:48编辑过]