将图表添加到Reportlab PDF [英] Adding Graph to Reportlab PDF

查看:327
本文介绍了将图表添加到Reportlab PDF的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经看到很多reportlab绘图示例。生成图形不是问题,我似乎无法弄清楚如何在pdf上显示图形。



这里是代码:

  buffer = StringIO()
p = canvas.Canvas(buffer,pagesize = letter)

### ##有问题的代码开始

d =绘图(200,100)
pc = Pie()
pc.x = 65
pc.y = 15
pc.width = 70
pc.height = 70
pc.data = [10,20,30,40,50,60]
pc.labels = ['a' ,'b','c','d','e','f']
pc.slices.strokeWidth = 0.5
pc.slices [3] .popout = 10
pc.slices [3] .strokeWidth = 2
pc.slices [3] .strokeDashArray = [2,2]
pc.slices [3] .labelRadius = 1.75
pc.slices [ 3] .fontColor = colors.red
d.add(pc)

p.drawPath(d)###这不工作,但需要类似的东西

#####问题结束代码

p.showPage()#Page两个

p.save()#使用Response\\保存PDF和返回值\\

pdf = buffer.getvalue()
buffe r.close()
response.write(pdf)
return response

这是我如何显示文字。
p.setFillColorRGB(1,1,1)
header = p.beginText(100,765)
header.textLine(页面标题文本)
p.drawText(标题)

解决方案

我写了这段时间以前,但它是网站上最受欢迎的文章之一,所以我猜它适用于一些。



http://www.protocolostomy.com/2008/10/22/generating-reports-with-charts-using-python-reportlab/



如果还不足以让你通过,让我知道,当我有更多的时间时,我会回来帮助更多。


I have seen many reportlab graphing examples. Generating the graph is not the problem, I can't seem to figure out how to display the graph on the pdf.

Here is the code:

buffer = StringIO()
p = canvas.Canvas(buffer, pagesize = letter)

##### Beginning of code in question

d = Drawing(200, 100)
pc = Pie()
pc.x = 65
pc.y = 15
pc.width = 70
pc.height = 70
pc.data = [10,20,30,40,50,60]
pc.labels = ['a','b','c','d','e','f']
pc.slices.strokeWidth=0.5
pc.slices[3].popout = 10
pc.slices[3].strokeWidth = 2
pc.slices[3].strokeDashArray = [2,2]
pc.slices[3].labelRadius = 1.75
pc.slices[3].fontColor = colors.red
d.add(pc)

p.drawPath(d) ### THIS DOES NOT WORK, but need something similar

#####End of Code in Question

p.showPage() #Page Two

p.save() # Saves the PDF and Returns with Response\

pdf = buffer.getvalue()
buffer.close()
response.write(pdf)
return response

This is how I display text. p.setFillColorRGB(1,1,1) header = p.beginText(100, 765) header.textLine("Page Heading Text") p.drawText(header)

解决方案

I wrote this some time ago, but it's been one of the most popular articles on the site, so I guess it works for some.

http://www.protocolostomy.com/2008/10/22/generating-reports-with-charts-using-python-reportlab/

If it's not enough to get you through, let me know and I'll come back to help out more later when I have more time.

这篇关于将图表添加到Reportlab PDF的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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