[reportlab-users] color individual bars
Robin Becker
reportlab-users@reportlab.com
Sat, 27 Jul 2002 11:03:20 +0100
In article <3D41BA56.9DC216EA@rasselstein-hoesch.de>, Dirk Datzert
<dirk.datzert@tks-rasselstein.thyssenkrupp.com> writes
>Hi all,
>
>I read thru the mail-archive of this month and found several article
>about coloring bars. My intention is to color each bar with an
>individual color. Context from the mail-archive was that it should be
>possible, but I walked thru the examples and the barcharts.py while
>I thing it won't work as expected.
>
>from makeBars:
>
> lenData = len(self.data)
> reversePlotOrder = self.reversePlotOrder
> for rowNo in range(lenData):
> if reversePlotOrder: rowNo = lenData-1 - rowNo
> row = self._barPositions[rowNo]
> styleCount = len(self.bars)
> styleIdx = rowNo % styleCount
> rowStyle = self.bars[styleIdx]
> for colNo in range(len(row)):
> barPos = row[colNo]
>
>lenData is the count of data rows
>rowNo is the current number of data row which is drawn
>styleCount is the count of bars definition
>
>If lenData is 1, and in the one row are the data it is impossible to
>color
>each bar with an individual color since styleIdx will always be 0 and
>rowStyle will always be self.bars[0] -> All bars will be the same color!
>
>On the other way I found that each barLabel can be individual defined
>since self.barLabels[(rowNo, colNo)] will be defined for each row and
>column.
>
>I thing that something like bars[(rowNo, colNo)] should be implemented
>in the BarChart or in a derived class, if really individual bar colors
>should be useable.
>
>Does anybody agree with this ?
>
>Regards,
>Dirk
...
Hi Dirk, I checked in some changes to graphics/widgetbase.py and
barcharts.py. Note that if you want to use the simple data form
bc.data =[(1,2,3,4,5)]
you need to do stuff like
bc.bars[(0,0)] = pink
bc.bars[(0,1)] = blue
....
bc.bars[(0,4)] = lime
--
Robin Becker