ReportLab的 - 饼图填充颜色

问题描述:

我正在在ReportLab的一个简单的饼图。我不能在这个文档中找到如何改变每一个人的馅饼填充颜色。ReportLab的 - 饼图填充颜色

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) 

好有几种方法可以做到这一点。

该物业.fillColor,但你必须确保你提供正确的颜色吧。以下是两种使用CMYK和RGB的方法。

  1. 使用CMYK catColor = PCMYKColor(0,0,0,100)

    pc.slices [0] = .fillColor catColor

    See this snippet

  2. 使用RGB颜色 catColor =色(0.10,0.26,0.46)

    pc.slices [0] = .fillColor catColor

    • 显然你不需要CatColor变量,你可以把这些行放在一起。关于颜色here

查看更多信息(ReportLab的文档,请参见第23页)

可以使用color.HexColor( “#F00”)。结帐以下例子:

Hex color codes