Squeak
  links to this page:    
View this PageEdit this PageUploads to this PageHistory of this PageTop of the SwikiRecent ChangesSearch the SwikiHelp Guide
How to lay out submorphs - example 5
Last updated at 9:16 pm UTC on 14 August 2017

Bar chart


This example shows how to do a simple bar chart by using the Morphic layout manager TableLayout.

MorphicLayoutExample5_Screenshot_from_2015-10-31.png

|cont m length |
 cont := Morph new.
  cont color: Color lightBlue.
 
  cont layoutPolicy: TableLayout new.
  cont listDirection: #topToBottom.
  cont cellPositioning:  #topLeft.
  cont hResizing: #shrinkWrap.
  cont vResizing: #shrinkWrap.
  
  #( 'Label A' 'Label B' 'Label C' 'Label D') 
  do:  [ :label |  
 	         m:= Morph new. 
 		 m layoutPolicy: TableLayout new.
 		 m listDirection: #leftToRight.
                m height: 25. 
 	         m cellInset: 4.
                m color: Color random twiceLighter.      
 
 		 length := m width + 200 atRandom.
                m width: length. 
 		 m addMorphBack: (StringMorph contents: label) .
                 m addMorphBack: (StringMorph contents: length asString). 
                cont addMorph: m.
             ].

  cont cellInset: 4.
  cont openInWorld.

See also

HistogramMorph