Customized Series Title In Openpyxl Python
I am trying to modify the existing xlsx sheet and adding graphs to it using openpyxl module in python. But while creating a line chart, the series title is shown as Series 1,Series
Solution 1:
I found a solution in a different question that works for me:
from openpyxl.chart import LineChart, Reference, Series
chart1 = LineChart()
# setup and append the first series
values = Reference(dprsheet, min_col=2, min_row=1, max_row=34)
series = Series(values, title="First series of values")
chart1.append(series)
# setup and append the second series
values = Reference(dprsheet, min_col=3, min_row=1, max_row=34)
series = Series(values, title="Second series of values")
chart1.append(series)
#set x-axis
dates = Reference(dprsheet, min_col=2, min_row=1, max_row=34)
chart1.set_categories(dates)
It's a bit more fiddly than the chart.add_data method, I'm going to assume that if you dig around in the code for that method you'll find something a bit more... pythony.
Post a Comment for "Customized Series Title In Openpyxl Python"