Reputation: 350
I'm generating a bar chart using ReportLab VerticalBarChart. I need one of the bars (each time a different one) to be a different color than the rest, to specify it is the 'chosen' value.
Or else, I need to mark it differently than the other bars somehow.
Any idea how to do that?
Upvotes: 3
Views: 1110
Reputation: 51
You need to use a sequence to access an individual bar. The snippet below sets the color for the first bar of the first data series.
chart.bars[(0,0)].fillColor = colors.red
Note: just passing through an index value e.g. chart.bars[0]
will give you access the entire first data series
Upvotes: 5
Reputation: 350
Meitham's answer didn't work for me - it seems that chart.bars.fillColor[0] colors all the bars in a series. When you have more than one series in one chart, you can determine the color for each series by Meitham's method.
What I ended up doing is emphasizing the label (ix is the index for the parameter I needed to single out):
...
bc = VerticalBarChart()
...
bc.categoryAxis.labels[ix].fontName = 'Times-Bold'
bc.categoryAxis.labels[ix].fontSize = 15
bc.categoryAxis.labels[ix].angle = 30
bc.categoryAxis.labels[ix].dy = -15
drawing.add(bc)
You can search for this in the reportlab user manual.
Upvotes: 1
Reputation: 9670
You would want to do
chart.bars.fillColor = some_colour
and for the specific bar where x is an integer representing the number
chart.bars.fillColor[x] = special_colour
Upvotes: 2