我想更改图表空间的图形属性,特别是与图表空间边框相对应的图形属性。
为了理解代码,我需要添加/修改以下方法:
'How to set up the Graphical Properties of Chart Area using openpyxl'
代码如下:
from openpyxl import Workbook
from openpyxl.chart import (
ScatterChart,
Reference,
Series,
)
from openpyxl.chart.shapes import GraphicalProperties
from openpyxl.drawing.colors import ColorChoice
from openpyxl.drawing.line import LineProperties
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()
# ChartSpace graphical properties
colori = ColorChoice(srgbClr = "FF0000")
linprop = LineProperties(solidFill = colori)
prop = GraphicalProperties(ln = linprop)
chart.graphical_properties = prop
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("Example.xlsx")
但是,上述代码中的下一行似乎对图表没有影响。
colori = ColorChoice(srgbClr = "FF0000")
linprop = LineProperties(solidFill = colori)
prop = GraphicalProperties(ln = lineprop)
chart.graphical_properties = pro
是否可以为图表空间指定图形属性?