我正在使用Python 3.6.3和openpyxl 2.5.4
我写了一些代码,发现用chart.title = "Test Heading"
设置图表标题没有任何作用。作为健全性检查,我复制并运行了example from here:
from openpyxl import Workbook
from openpyxl.chart import (
ScatterChart,
Reference,
Series,
)
wb = Workbook()
ws = wb.active
rows = [
['Size', 'Batch 1', 'Batch 2'],
[2, 40, 30],
[3, 40, 25],
[4, 50, 30],
[5, 30, 25],
[6, 25, 35],
[7, 20, 40],
]
for row in rows:
ws.append(row)
chart = ScatterChart()
chart.title = "Scatter Chart"
chart.style = 13
chart.x_axis.title = 'Size'
chart.y_axis.title = 'Percentage'
xvalues = Reference(ws, min_col=1, min_row=2, max_row=7)
for i in range(2, 4):
values = Reference(ws, min_col=i, min_row=1, max_row=7)
series = Series(values, xvalues, title_from_data=True)
chart.series.append(series)
ws.add_chart(chart, "A10")
wb.save("scatter.xlsx")
奇怪的是,将title_from_data=True
更改为title_from_data=False
似乎也对图表的内容没有影响。
答案 0 :(得分:1)
这很像是您用来查看文件的应用程序中的错误,我怀疑是LibreOffice。