如何在工作簿中放置图表 [英] How To Position Chart in Workbook

查看:71
本文介绍了如何在工作簿中放置图表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在运行python2.7,并使用openpyxl版本1.8.6.我能够很好地生成图表,但是无法找到任何指示该图表可以放置在工作表中的特定位置的东西.任何帮助将不胜感激.

I am running python2.7, and using openpyxl version 1.8.6. I am able to generate a chart just fine, but am unable to locate anything that indicates the chart can then be positioned in a particular location in a sheet. Any assistance would be appreciated.

我正在使用以下代码来生成图表:

I am using the following code to generate the chart:

ws = wb2.get_sheet_by_name('Traffic Data')
rowcount = ws.get_highest_row()
values = Reference(ws,(1,1), (rowcount - 1,1))
labels = Reference(ws,(0,1),(rowcount,0))
title = "Events recorded in " + str(datetime.datetime.strptime(str(runmonth), '%m').strftime('%B'))
series = Series(values, title=title)
chart.add_series(series)
ws = wb2.get_sheet_by_name('Traffic Incidents')
ws.add_chart(chart)

推荐答案

我能够通过使用chart.drawing偏移图表位置.具体来说,我使用了:

I was able to offset the chart position by using chart.drawing. Specifically, I used:

chart.drawing.left = 1000

chart.drawing.left = 1000

这使图表偏移了大约11个单元格.我不确定像素到单元的映射,但可以通过一些试验轻松地对其进行逆向工程.

This offset the chart by about 11 cells. I'm not sure about the pixel to cell mapping, but it can be easily reverse engineered by a few trials.

这篇关于如何在工作簿中放置图表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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