# [reportlab-users] How to color each bar in a barchart ?

Andy Robinson reportlab-users@reportlab.com
Tue, 9 Jul 2002 13:30:05 +0100

```If you want each one to have a different color,
and there is a potentially infinite number
of points, then first figure out your
coloring scheme :-)

Our 'simplest case' was that each series
was the same color.  That's what Excel does.
To do something else you need to write
your own code snippet.  There are two schemes
I can see:  some gradual function, or a list of
colors used in rotation.

For a gradual transition do something like this,
where someFunction is your problem :-)

for i in range(len(myData)):
red, gree, blue = someFunction(i)
bars[i].fillColor = color.Color(red, green, blue)

For rotation in a palette (e.g. 4 colors that repeat):

myPalette = [red, pink, orange_chiffon, whatever...]
for i in range(len(mydata)):
i2 = i % (len(myPalette))
bars[i].fillColor = myPalette[i2]

Not tested but I hope the idea is clear,

Thanks,

Andy Robinson

-----Original Message-----
From: reportlab-users-admin@reportlab.com
[mailto:reportlab-users-admin@reportlab.com]On Behalf Of Marcus
Vinicius Laranjeira
Sent: 08 July 2002 18:06
To: reportlab-users@reportlab.com
Subject: Re: [reportlab-users] How to color each bar in a barchart ?

Let's supose I have a data series like:

[[1, 1, 1, 1, 2, 1, 2, 1, 1, 2, 2, 2, 1, 2, 1, 1, 4, 1, 1, 1, 1, 2, 2,
1, 1, 1, 1, 1, 1, 1, 3, 1, 1, 1, 3, 1]]

and the lenght of this data serie may change based on some
configuration of the program...

How do I know how many bars I have, like:

for bar in ???:
bar.fillColor(color.Color(r,g,b)

?!??

Any hints on this !?

```