% From Window Programming in Mozart by Christian Schulte declare local O=if Tk.isColor then o(fill:wheat) else o(stipple:gray50 fill:black) end D=9 D2=2*D B=10 in class GraphCanvas from Tk.canvas meth DrawBars(Pairs H X) case Pairs of nil then skip [] (Arg#Val)|Pr then {self tk(create rectangle X H X+D H-Val*D2 O)} {self tk(create text X H+D+1 text:Arg anchor:w)} {self DrawBars(Pr H X+D2)} end end meth configure(SX SY) {self tk(configure scrollregion:q(B ~B SX+B SY+B))} end meth bars(Pairs) WY=D2*({Max 1 {Length Pairs}}) HY=D2*({Max 1 {FoldL {Map Pairs fun {$ P} _#Val=P in Val end} Max 0}}) in {self configure(WY HY)} {self DrawBars(Pairs HY D)} end end end W={New Tk.toplevel tkInit(title:'BarGraph')} C={New GraphCanvas tkInit(parent:W bg:white width:500 height:200)} H={New Tk.scrollbar tkInit(parent:W orient:horizontal)} V={New Tk.scrollbar tkInit(parent:W orient:vertical)} {Tk.addXScrollbar C H} {Tk.addYScrollbar C V} {Tk.batch [grid(C row:0 column:0) grid(H row:1 column:0 sticky:we) grid(V row:0 column:1 sticky:ns)]} % To run it: % {C bars([1#7 2#3 4#2 5#9])}