Graph 带区间窗的blt图?
我在tcl/tk中有一个blt实时图,该图无时间限制地收集数据,并将所有数据点存储到向量中,用户可以在图中来回滚动。问题是,如果让图形长时间收集这些点,cpu和内存消耗会急剧增加,我认为24小时间隔窗口应该可以。当我试图从图中“取消设置x(0)”时,我得到一个错误,说“命令名无效”,我也尝试使用“x删除0”和同样的东西。非常感谢您的帮助 以下是我初始化图形的方式:Graph 带区间窗的blt图?,graph,tcl,real-time,Graph,Tcl,Real Time,我在tcl/tk中有一个blt实时图,该图无时间限制地收集数据,并将所有数据点存储到向量中,用户可以在图中来回滚动。问题是,如果让图形长时间收集这些点,cpu和内存消耗会急剧增加,我认为24小时间隔窗口应该可以。当我试图从图中“取消设置x(0)”时,我得到一个错误,说“命令名无效”,我也尝试使用“x删除0”和同样的东西。非常感谢您的帮助 以下是我初始化图形的方式: proc startGraph {} { global btnColor global backColor
proc startGraph {} {
global btnColor
global backColor
global startTime
global txtActionLevel
global txtAlertLevel
global x y1 y2 flagTime inStart inTime vectorFlag
global resolution
global notFirstTime
global txtActionLevel
set notFirstTime 0
set resolution 0
# Create stripchart widget
blt::stripchart .s -width 625 -height 330 -background $backColor -plotbackground black -font defaultFont
scrollbar .scroll -command { ScrollToEnd
.s axis view x } -orient horizontal -relief flat -background black -troughcolor $backColor -activebackground black -elementborderwidth 5
.s axis configure x -scrollcommand { .scroll set }
# Create BLT vectors
blt::vector create x
blt::vector create y1
blt::vector create y2
set startTime 0
set flagTime 0
set inStart -1
set inTime 0
set vectorFlag 0
.s configure -borderwidth 0 \
-leftmargin 0 \
-rightmargin 0 \
-plotborderwidth 0 \
-plotpadx {0 0} \
-plotpady {0 0}
.s legend configure -hide yes
.s grid configure -color gray \
-dashes 1 \
-minor 0 \
-hide 0
# X-axis
.s axis configure x -autorange 60 \
-shiftby 1 \
-stepsize 10 \
-subdivisions 1 \
-command FormatXLabel
# Alert txtAlertLevel
#.s tag create line -mapx 2 -mapy 2
proc FormatXLabel {widget x} {
set x [expr round($x)]
return [clock format $x -format "%I:%M:%S"]
}
# Y-axis
#.s axis configure y -title "C o u n t s"
image create photo .countsIcon -format PNG -file counts.png
label .titleGraph -image .countsIcon -background $backColor
place .titleGraph -in .measureView -x 0 -y 160
# Particles
.s element create Particles -symbol {} -color yellow -linewidth 1 \
-smooth linear -xdata x -ydata y1
# Bio
.s element create Bio -symbol {} -color red -linewidth 1 \
-smooth linear -xdata x -ydata y2
.s marker create line -name actionLine -coords {-Inf $txtActionLevel Inf $txtActionLevel} -linewidth 1 -outline orange
.s marker create line -name alertLine -coords {-Inf $txtAlertLevel Inf $txtAlertLevel} -linewidth 1 -outline green
place .s -in .measureView -x 10 -y 50
place .scroll -in .measureView -x 60 -y 380 -width 515 -height 35
#chartTime
}
这是我向向量添加值的地方:
set x(++end) [clock seconds]
set flagTime 0
set vectorFlag 1
set len [y1 length]
if {$len == 0} {
set startTime $x(end)
set y1(++end) $particle_sec
set y2(++end) $x_summary(bio_sec)
#if {$inStart < 0} {
# .s axis configure x -min "" -max ""
# set inStart 0
#}
} else {
set y1(++end) $particle_sec
set y2(++end) $x_summary(bio_sec)
}
puts "Vector length [x length]------"
puts "First value $x(0)----------"
#This is where i'm trying to catch whenever it reaches 60 seconds in this case
#when the length of the vector reaches 60 seconds it will unset the first value
#but it doesn't work it throws and invalid command name error
if {[x length] > 60} {
[unset -nocomplain x(0)]
}
#incr everyten
add_Result $particle_sec $bioSec [format "%.2f" $fv_eff]
设置x(++end)[时钟秒]
将flagTime设置为0
设置矢量标志1
设置长度[y1长度]
如果{$len==0}{
设置开始时间$x(结束)
设置y1(++结束)$particle\u秒
设置y2(++结束)$x_摘要(生物秒)
#如果{$inStart<0}{
#.s轴配置x-最小值“”-最大值“”
#设置inStart 0
#}
}否则{
设置y1(++结束)$particle\u秒
设置y2(++结束)$x_摘要(生物秒)
}
放置“向量长度[x长度]----”
放入“第一个值$x(0)----”
#这就是我试图抓住的地方,在这种情况下,每当它达到60秒
#当向量长度达到60秒时,它将取消设置第一个值
#但它不工作,它抛出了无效的命令名错误
如果{[x长度]>60}{
[未设置-无投诉x(0)]
}
#递增每单位
添加结果$particle\u sec$bioSec[格式“%.2f”$fv\u eff]
由于一些奇怪的原因,当您使用blt::vector时,创建“[unset-nocomplain x(0)]”似乎不起作用,因此我将其更改回“x delete 0”,而不使用方括号,它现在就起作用了。当您将unset-nocomplain x(0)
放在[
方括号]中,并像这样独立使用时,你得到的是:
它试图取消设置该变量(我不知道这是否会有问题;我没有在自己的代码中使用BLT向量)。这不会导致任何错误。结果将是空字符串(它是空的)
它接受结果(一个空字符串)并将其用作命令的字。整个词,因为你没有连接任何东西。事实上,整个第一个词。您将尝试计算名称为空字符串的命令,并且不传递其他参数。这是一般的Tcl语义
现在,用空名称创建命令是合法的,有点棘手(因为重命名为空字符串会删除它-完全限定名称是解决办法),而且非常不寻常。在你的情况下,你没有这样的命令,你真正得到的是一个bug。虫子?那些方括号
使用unset-nocomplain x(0)
代替[unset-nocomplain x(0)]
还要注意的是,在网上的许多地方,当Tcl程序将Tcl代码片段内联到一个没有奇特格式的地方时,他们会在代码周围放上方括号。这只是一个惯例,使事情更容易阅读。您不应该在Stack Overflow上看到这种情况。您需要向我们展示一些codedone,希望这有助于感谢您的回答,现在就有意义了。现在,我怎样才能用所有数据重新创建图形呢?不仅仅是一个间隔窗口,我将所有数据存储在数据库中。有什么想法吗。。?谢谢