Reportlab 文件生成中的问题

发布于 2024-11-14 07:47:29 字数 2260 浏览 2 评论 0原文

我正在编写这个简单的代码来显示 pdf 和其他格式的图表,同时从 mysql 数据数据库收集要显示的数据。 代码正在运行,没有错误,但尚未生成文件。请帮忙。

from rlextra.graphics.guiedit.datacharts import DataAwareDrawing, DataSource, ODBCDataSource, DataAssociation

from reportlab.graphics.shapes import _DrawingEditorMixin

from reportlab.graphics.charts.lineplots import GridLinePlot

class Ok(_DrawingEditorMixin,DataAwareDrawing):

                def __init__(self,width=800,height=800,*args,**kw):
                                DataAwareDrawing.__init__(self,width,height,*args,**kw)
                                self._add(self,GridLinePlot(),name='plot',validate=None,desc=None)
                                self.height           = 125
                                self.width            = 300
                                self.plot.height          =125
                                self.plot.width           = 300
                                self.plot.x               = 50
                                self.plot.y               = 50
                                self.dataSource       = ODBCDataSource()
                                self.dataSource.driver                   = 'mysql'
                                self.dataSource.user                     = 'root'
                                self.dataSource.password                 = 'soumya'
                                self.dataSource.name                     = 'fundrep'
                                self.dataSource.sql                      = 'SELECT fund_id, periodEnd, fundReturn,indexReturn FROM fundrep_monthlyreturnseriess ORDER BY fund_id, periodEnd'
                                self.outDir           = 'output'
                                self.fileNamePattern  = 'pleaserun'
                                self.formats          = ['pdf', 'eps', 'gif']
                                self.dataSource.associations.size       = 2
                                self.dataSource.associations.element00  = DataAssociation(column=0, target='chartId', assocType='scalar')
                                self.dataSource.associations.element01  = DataAssociation(column=[(1,2),(1,3)], target='plot.data', assocType='tmatrix')

if __name__=="__main__": #NORUNTESTS

                 Ok().go()

I am writing this simple code to display a chart in pdf and other formats while collecting data to be displayed from mysql data database.
The code is running w/o errors but yet the files are not generated. Please help.

from rlextra.graphics.guiedit.datacharts import DataAwareDrawing, DataSource, ODBCDataSource, DataAssociation

from reportlab.graphics.shapes import _DrawingEditorMixin

from reportlab.graphics.charts.lineplots import GridLinePlot

class Ok(_DrawingEditorMixin,DataAwareDrawing):

                def __init__(self,width=800,height=800,*args,**kw):
                                DataAwareDrawing.__init__(self,width,height,*args,**kw)
                                self._add(self,GridLinePlot(),name='plot',validate=None,desc=None)
                                self.height           = 125
                                self.width            = 300
                                self.plot.height          =125
                                self.plot.width           = 300
                                self.plot.x               = 50
                                self.plot.y               = 50
                                self.dataSource       = ODBCDataSource()
                                self.dataSource.driver                   = 'mysql'
                                self.dataSource.user                     = 'root'
                                self.dataSource.password                 = 'soumya'
                                self.dataSource.name                     = 'fundrep'
                                self.dataSource.sql                      = 'SELECT fund_id, periodEnd, fundReturn,indexReturn FROM fundrep_monthlyreturnseriess ORDER BY fund_id, periodEnd'
                                self.outDir           = 'output'
                                self.fileNamePattern  = 'pleaserun'
                                self.formats          = ['pdf', 'eps', 'gif']
                                self.dataSource.associations.size       = 2
                                self.dataSource.associations.element00  = DataAssociation(column=0, target='chartId', assocType='scalar')
                                self.dataSource.associations.element01  = DataAssociation(column=[(1,2),(1,3)], target='plot.data', assocType='tmatrix')

if __name__=="__main__": #NORUNTESTS

                 Ok().go()

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

箜明 2024-11-21 07:47:29

假设这是您的全部代码,则此问题似乎是您从未实际绘制到 ReportLab Canvas 以便将其写出到文件中。一般来说,ReportLab 的工作方式是:

  1. 创建一个画布来绘制文档。
  2. 绘制文档(即创建页面、在页面上放置内容等)。
  3. 将文档写入文件。

由于您的代码中没有发生这些情况,因此我认为 ReportLab 不会发布任何内容。

Assuming this is all your code, this issue appears to be that you never actually draw to a ReportLab Canvas in order for it to be written out to a file. The general, the way ReportLab works is:

  1. Create a canvas to draw the document on.
  2. Draw the document (i.e. create pages, put stuff on the pages, etc.).
  3. Write the document out to a file.

Since none of that happens in your code, I don't think ReportLab will put anything out.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文