
How to display a bin count histogram
Quote:
> Hi,
> I have a list of bin count from 0 to 255, I need to update the contents
> of these bins as the content values change. What would be a good way
> to do this? I tried to use for loops to add label, but 256 bin
> wouldn't fit in one window, then I tried to add a scrollbar, but the
> scrollbar appears to work only on listbox. The label bin1....bin256
> remains the same. Only the content of these need to be updated.
> Thanks in advance,
> Ann
The Tk canvas widget is a good fit for this sort of
task. There are some pure tcl solutions such as
http://mini.net/tcl/13680
and
http://mini.net/tcl/10878
Here is some bare Tcl code
to make horizontal bars of various
colors and update their length.
---------------------------------------------
package require Tk
destroy .c
pack [canvas .c -bd 0 -highlightthickness 0] -fill both -expand 1
set dataset {
10 red val1
13 green val2
99 blue bigval
22 brown midval
Quote:
}
set y 10
set w 20
set scale 1
set x 50
foreach {val color text} $dataset {
# Draw the bar as a line
.c create line $x $y [expr {$x + ($scale * $val)}] $y -width $w \
-fill $color -tags [list $text]
# put text over it
.c create text 0 $y -anchor w -text $text -fill black
incr y [expr {$w+5}]
Quote:
}
proc changeval {text newval} {
global scale x
foreach {x1 y1 x2 y2} [.c coords $text] break
.c coords $text $x1 $y1 [expr {$x + ($scale * $newval)}] $y2
Quote:
}
Roy