我想更改Chart_area的背景颜色以及删除所有边框。关于背景颜色,我尝试了建议的解决方案:How to set Background Color of Plot Area of Chart using openpyxl但是此解决方案不适用于任何图表,即BarChart,AreaChart,LineChart,ScatterChart,RadarChart等...我尝试了两个openpyxl版本:2.4.7 ,2.4.9。没有成功。
# setup the chart
chart = LineChart()
# test to remove border line
*****************************************************
chart.graphical_properties =
GraphicalProperties(ln=LineProperties(noFill=True))
chart.height = 9
chart.width = 13.4
props = GraphicalProperties(solidFill="f2f2f2")
# setup and append the first series
list_names = ['Fund', 'Market', 'Benchmark']
data = Reference(ws2, min_col=2, min_row=1, max_col=n + 1, max_row=p +
1)
chart.x_axis.number_format = 'mmm yy'
chart.x_axis.majorTimeUnit = "months"
chart.add_data(data, titles_from_data=True)
dates = Reference(ws2, min_col=1, min_row=2, max_col=1, max_row=1 + p)
chart.set_categories(dates)
# Style the lines
chart.series[0].graphicalProperties.line.solidFill = "7E3F00"
chart.series[1].graphicalProperties.line.solidFill = "45788C"
chart.series[2].graphicalProperties.line.solidFill = "8BADD9"
chart.plot_area.graphicalProperties = props
# test to change background color
*****************************************************
chart.graphical_properties = props
ws1.add_chart(chart, "B14")
我还尝试删除chart_area的边框。我找到了这篇文章:openpyxl - Ability to remove border from charts?。但我不明白如何处理修改库。我有点惊讶,没有更简单的方法。
非常感谢您的帮助。
答案 0 :(得分:2)
此过程可能有助于找到答案。