ReportLab 中 GridLinePlot() 的 Y 轴缩放问题

发布于 2024-12-15 14:29:34 字数 1430 浏览 0 评论 0原文

我刚刚在 django 中发现了 GridLinePlot() 的一些奇怪行为 项目。看起来绘制的线的形状没问题,但是 y 轴标签不正常。我正在使用的代码如下:

class MyLineChartDrawing(Drawing):

  def __init__(self, width=600, height=400, *args, **kw):
    apply(Drawing.__init__,(self,width,height)+args,kw)
    self.add(GridLinePlot(), name='chart')

    self.chart.x = 50 # The x coordinate of the reference point
    self.chart.y = 30 # The y coordinate of the reference point
    self.chart.width = self.width - 150  # The width of the chart
    self.chart.height = self.height - 75 # The height of the chart

    self.chart.data = [[('20110930', 80), ('20111007', 116), ('20111014',139), ('20111021', 163), ('20111028', 105), ('20111104', 97), ('20111111', 112)]]

  def HttpChart (self, title, XLabel, YLabel, data, isPercent=False):
    return (renderSVG.drawToString(self))

为了调用它,我只需执行以下操作:

d = MyLineChartDrawing(width=chartWidth, height=chartHeight)
return HttpResponse(d.HttpChart ("", "", "MyYAxisTitle", edata),'image/svg+xml')

轴上似乎发生了一些缩放,该缩放未应用于绘制的坐标,当我添加更多数据时,这变得非常戏剧性。例如,这个 self.chart.data 列表只是在列表前面添加了一个点,导致缩放比例从轻微错误变为大约 50%。

self.chart.data = [[('20110923', 32), ('20110930', 80), ('20111007', 116), ('20111014', 139), ('20111021', 163), ('20111028', 105), ('20111104', 97), ('20111111', 112)]]

我正在使用在 OSX 10.7.2 上运行的 ReportLab 2.5、Django 1.3.0、Python 2.7。

预先感谢您的任何帮助或建议。

I have just spotted some weird behaviour with GridLinePlot() in a django
project. It seems that the shape of the line plotted is OK, but that the
y-axis labels are out of whack. The code I am using is below:

class MyLineChartDrawing(Drawing):

  def __init__(self, width=600, height=400, *args, **kw):
    apply(Drawing.__init__,(self,width,height)+args,kw)
    self.add(GridLinePlot(), name='chart')

    self.chart.x = 50 # The x coordinate of the reference point
    self.chart.y = 30 # The y coordinate of the reference point
    self.chart.width = self.width - 150  # The width of the chart
    self.chart.height = self.height - 75 # The height of the chart

    self.chart.data = [[('20110930', 80), ('20111007', 116), ('20111014',139), ('20111021', 163), ('20111028', 105), ('20111104', 97), ('20111111', 112)]]

  def HttpChart (self, title, XLabel, YLabel, data, isPercent=False):
    return (renderSVG.drawToString(self))

To call this I am simply doing the following:

d = MyLineChartDrawing(width=chartWidth, height=chartHeight)
return HttpResponse(d.HttpChart ("", "", "MyYAxisTitle", edata),'image/svg+xml')

It appears that there is some scaling going on on the axis which is not applied to the plotted coordinates, this becomes quite dramatic when I add more data. For example, this self.chart.data list, which simply adds one more point to the front of the list, causes scaling to go from subtly wrong to about 50% out.

self.chart.data = [[('20110923', 32), ('20110930', 80), ('20111007', 116), ('20111014', 139), ('20111021', 163), ('20111028', 105), ('20111104', 97), ('20111111', 112)]]

I am using ReportLab 2.5, Django 1.3.0, Python 2.7 running on OSX 10.7.2.

Thanks in advance for any help or advice.

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

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文