0
我在openpyxl中创建折线图时遇到问题。 我使用下面的代码:openpyxl中的折线图
from datetime import date
from openpyxl import Workbook
from openpyxl.chart import LineChart, Reference, Series
list_of_num = ['Batch 1', 'Batch 2', 'Batch 3']
ms_lastc = 3
rows = [
['Date', 'Batch 1', 'Batch 2', 'Batch 3'],
[date(2015, 9, 1), 40, 30, 25],
[date(2015, 9, 2), 40, 25, 30],
[date(2015, 9, 3), 50, 30, 45],
[date(2015, 9, 4), 30, 25, 40],
[date(2015, 9, 5), 25, 35, 30],
[date(2015, 9, 6), 20, 40, 35]]
if __name__ == '__main__':
wb = Workbook()
ms = wb.active
for row in rows:
ms.append(row)
lc = LineChart()
x = Reference(ms,
min_col=1,
min_row=2,
max_col=1,
max_row=7)
for i, name in enumerate(list_of_num):
values = Reference(ms,
min_col=i+1,
min_row=2,
max_col=i+1,
max_row=7)
serie = Series(values, xvalues=x, title=name)
lc.append(serie)
ms.add_chart(lc, 'A9')
wb.save('bla.xlsx')
当我在图表中打开意甲系列值为空。
有人可以帮我吗?
它看起来像你没有使用正确的文档为您有的版本的openpyxl。请参阅http://openpyxl.readthedocs.io/en/2.4/charts/introduction.html#creating-a-chart –