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

Rüdiger Mähl reportlab-users@reportlab.com
Mon, 8 Jul 2002 13:11:43 +0200


Marcus Vinicius Laranjeira schrieb am 05.07.02 15:12:30:
> I am currently learning and discovering the power of reportlab.
> Actually I am creating two charts, one as a horizontal bar chart and the=
 other
> one as a vertical bar chart. In both of them the bars are printed filled=
 in 
> red.
> 
> I need these bars to be printed each one with a different colors and nev=
er
> repeating the colors (in the same chart).

How about this:

use a stacked bar chart and use only one element in each value 
series, the others set to zero. Then you can change the color 
of each bar.

(example appended)

Rüdiger

#####
    drawing = Drawing(400, 200)

    bc = HorizontalBarChart()
    bc.x = 50
    bc.y = 50
    bc.height = 125
    bc.width = 300
    # Use only one element of each value series.
    # Append a complete value tuple for each additional value you got.
    bc.data = [
        (1, 0, 0, 0), 
        (0, 2, 0, 0),
        (0, 0, 3, 0),
        (0, 0, 0, 4)
        ]

    bc.strokeColor = colors.black

    bc.valueAxis.valueMin = 0
    bc.valueAxis.valueMax = 10
    bc.valueAxis.valueStep = 1

    # must be stacked
    bc.categoryAxis.style = 'stacked'
    bc.categoryAxis.labels.boxAnchor = 'e'
    bc.categoryAxis.categoryNames = ['one', 'two', 'three', 'four']
    
    bc.bars[0].fillColor = colors.yellow
    bc.bars[1].fillColor = colors.green
    bc.bars[2].fillColor = colors.blue
    bc.bars[3].fillColor = colors.red
    
    drawing.add(bc)


________________________________________________________________
Keine verlorenen Lotto-Quittungen, keine vergessenen Gewinne mehr! 
Beim WEB.DE Lottoservice: http://tippen2.web.de/?x=13