Reputation: 781
I would like to change the background color of Chart_area as well as remove all borders. Regarding the background color, I have tried the solution suggested: How to set Background Color of Plot Area of Chart using openpyxl but this solution doesn't work for any charts i.e. BarChart, AreaChart, LineChart, ScatterChart, RadarChart etc... I tried two openpyxl versions: 2.4.7, 2.4.9. without success.
# 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")
I also tried to remove the borders of chart_area. I found this post: openpyxl - Ability to remove border from charts?. But I don't understand how do I handle to modify the library. I am a bit surprised that there is no simpler way.
Many thanks in advance for your help.
Upvotes: 2
Views: 5112
Reputation: 181
This process may be helpful guidance to find an answer.
Upvotes: 5