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)
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)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
好的,有几种方法可以做到这一点。
该属性是 .fillColor,但您必须确保正确地为其提供颜色。下面有两种方式,CMYK和RGB。
使用 CMYK
猫颜色 = PCMYKColor(0,0,0,100)
pc.slices[0].fillColor = catColor
查看此代码段
使用 RGB 颜色
猫颜色 = 颜色(0.10,0.26,0.46)
pc.slices[0].fillColor = catColor
查看有关颜色的详细信息 这里< /a>(reportlab 文档,请参阅第 23 页)
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
View more info about colors here (reportlab docs, see page 23)
您可以使用 color.HexColor("#f00")。查看以下示例`
十六进制颜色代码
You can use color.HexColor("#f00"). Checkout the following examples`
Hex color codes