[reportlab-users] BarLabelFormat

Robin Becker reportlab-users@reportlab.com
Fri, 26 Jul 2002 19:06:22 +0100


In article <5.1.1.6.0.20020726143827.00a0dab0@imap.datacraft.com.br>, Marcus Vinicius Laranjeira
<m.laranjeira@datacraft.com.br> writes
.....
>    Why! ?!?!?!?!
>
>    At 18:25 26/07/02 +0200, you wrote:
>>       Marcus Vinicius Laranjeira:
>
>>>              self.bc.barLabelFormat = self._formatHour(self)
>
>>       Try:
>
>>         self.bc.barLabelFormat = self._formatHour
>
>>       Dinu
.....
it seems the code in barcharts wants a function or callable instance not just a callable. Try
replacing the _getlabelText method with

    def _getLabelText(self, rowNo, colNo):
        '''return formatted label text'''
        labelFmt = self.barLabelFormat
        if labelFmt is None:
            labelText = None
        elif type(labelFmt) is StringType:
            labelText = labelFmt % self.data[rowNo][colNo]
        elif callable(labelFmt):
            labelText = labelFmt(self.data[rowNo][colNo])
        else:
            msg = "Unknown formatter type %s, expected string or function" % labelFmt
            raise Exception, msg
        return labelText

-- 
Robin Becker