reportlabs中的Python-Pie图表 [英] Python-Pie chart in reportlabs

查看:280
本文介绍了reportlabs中的Python-Pie图表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我指的是此链接,用于生成饼图.在这种情况下,为每个数据预定义颜色,即为10个数据点提供10种颜色.如果我有11个数据点,那么该第11个数据点将没有颜色怎么办.我想要一些动态的东西,它应该自动自动选择一种颜色并将其绘制在饼上.

I'm referring this link for generation of Pie Chart. In this the colors are pre-defined for each data, ie 10 colors for 10 data points. What if I have 11 data points and then there will be no color for that 11th data point. I want something dynamic which should automatically pick a color by itself and plot it on the pie.

我找到了此链接

I found this link and this link, but the colors over here are not catchy and not at all good.

有人可以向我介绍一下如何在饼图中获得醒目的颜色吗?

Can someone please brief me about how to get catchy colors in pie graph?

谢谢

推荐答案

我知道现在回答有点晚了,但是如果其他人遇到相同的问题,这对我有用:

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"),
    ]

您可以更改颜色代码以获得所需的任何颜色,例如: http://www.creativecolorschemes.com/resources/free-color-schemes/beautiful-color-scheme.shtml

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)

之前setItems定义为:

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])

使用此链接(最后一个饼图示例)获得更多参考: http://m .blog.csdn.net/blog/wdt3385/10142163

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

这篇关于reportlabs中的Python-Pie图表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆