I am making a simple pie chart in reportlab. I can not find in the docs how to change each individual pies fill color.
pie_chart = Drawing(200, 200)
pc = Pie()
pc.x = 65
pc.y = 15
pc.width = 150
pc.height = 150
pc.data开发者_运维知识库 = [65,13,12,9,1]
pc.labels = ['Name','Another','Yet Another','Test','Stack']
pc.slices[1]. // This is where I need the fill color property.
pie_chart.add(pc)
renderPM.drawToFile(pie_chart, '/images/temp/pie_chart.png', 'PNG')
p.drawImage('/images/temp/pie_chart.png', 10, 60, width=150, height=150, mask=None)
Ok there is a couple ways to do this.
The property is .fillColor, but you have to make sure you provide the color to it correctly. Below are two ways, with CMYK and RGB.
Using CMYK catColor = PCMYKColor(0,0,0,100)
pc.slices[0].fillColor = catColor
See this snippet
Using RGB Color catColor = Color(0.10,0.26,0.46)
pc.slices[0].fillColor = catColor
- Obviously you do not need CatColor variable, you can put the lines together.
View more info about colors here (reportlab docs, see page 23)
You can use color.HexColor("#f00"). Checkout the following examples`
Hex color codes
精彩评论