我正在编写这个简单的代码,以显示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()
答案 0 :(得分:1)
假设这是您的所有代码,此问题似乎是您从未实际绘制到ReportLab Canvas以便将其写入文件。一般来说,ReportLab的工作方式是:
由于您的代码中没有发生这种情况,我认为ReportLab不会放任何东西。