Updated 2012-11-10 15:15:27 by RLE

Example of how to set up a vertical axis on a BLT graph labelled with a horizontal label. Achieved by ignoring the "label" option of the axis method, which would give a vertical label, and tacking the label onto one of the tick labels instead. Execute in wish, and it should look like this:

Version A - Paul Welton - 24.06.02
    package require BLT
    
    pack [blt::graph .g]
    
    #  Proc passed as a callback to BLT to draw custom tick labels.
    #
    proc format_yAxis_tick {win value} {
        if {$value == [$win axis cget y -max]} {
            set yAxisHeightPixels [expr {abs (
                [$win axis transform y [$win axis cget y -max]] -
                [$win axis transform y [$win axis cget y -min]])}]
                
            set font [$win axis cget y -tickfont]
                
            set yAxisHeightLines  [expr {$yAxisHeightPixels /
                [font metrics $font -linespace]}]
                
            set v [string repeat "\n" [expr {$yAxisHeightLines / 2}]]
            set h [string repeat " "  [expr {
                [font measure $font "$::y_title           "] /
                [font measure $font " "]}]]
            return "$v$h$value$v$::y_title"
        } else {
            return $value
        }
    }
    
    #  The following global is used by the callback "format_yAxis_tick".
    set y_title "Y axis title"
    
    #  Configure the vertical axis.
    .g axis configure y -min 0 -max 100 -majorticks     \
            {0 10 20 30 40 50 60 70 80 90 100}
            
    #  Need to force the graph to be drawn before distances can be
    #  measured.
    update
    
    .g axis configure y -command format_yAxis_tick

See also BLT