Python-Pie chart in reportlabs

断了今生、忘了曾经 提交于 2019-12-02 07:16:56

You can also provide from reportlab.lib.colors import Color like:

Color(red=0, green=0, blue=1, alpha=1) # gives blue
Color(red=1, green=0, blue=0, alpha=1) # gives red

It's easier to manage those arguments than Hex's.
So you could provide a dynamicaly generated list of Color instances. You could yield an iterator that will generate your 'Catchy' colors. I don't think I can define your 'catchyness' for you better than your self :)

I know it's kind of late to be answering, but in case someone else has the same problem, here is what worked for me:

At the start of the code you write:

from reportlab.lib.colors import HexColor
pdf_chart_colors = [
    HexColor("#0000e5"),
    HexColor("#1f1feb"),
    HexColor("#5757f0"),
    HexColor("#8f8ff5"),
    HexColor("#c7c7fa"),
    HexColor("#f5c2c2"),
    HexColor("#eb8585"),
    HexColor("#e04747"),
    HexColor("#d60a0a"),
    HexColor("#cc0000"),
    HexColor("#ff0000"),
    ]

You can change the color codes to get any color you like, some examples: http://www.creativecolorschemes.com/resources/free-color-schemes/beautiful-color-scheme.shtml

And when generating the pie chart you only need to add two lines at the end:

def piechart(Values, Names):        
    d = Drawing(100, 125)
    cht = Pie()
    ...
    n = len(cht.data)
    setItems(n,cht.slices,'fillColor',pdf_chart_colors)

Where setItems has been previously defined as:

def setItems(n, obj, attr, values):
m = len(values)
i = m // n
for j in xrange(n):
    setattr(obj[j],attr,values[j*i % m])

Use this link (last pie chart example) for extra ereference: http://m.blog.csdn.net/blog/wdt3385/10142163

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!