The add_series()
method accepts either a string like '=name!$B$32:$B$532'
to define the ranges or, more usefully when generating a chart progrmatically, a list of values like ['name', 31, 1, 531, 1]
.
From the first example in the add_series()
documentation:
chart.add_series({
'categories': '=Sheet1!$A$1:$A$5',
'values': '=Sheet1!$B$1:$B$5',
'line': {'color': 'red'},
})
# Or using a list of values instead of category/value formulas:
# [sheetname, first_row, first_col, last_row, last_col]
chart.add_series({
'categories': ['Sheet1', 0, 0, 4, 0],
'values': ['Sheet1', 0, 1, 4, 1],
'line': {'color': 'red'},
})
The sheet name in the list example can be replaced with a variable if required:
sheet_name = 'Data'
chart.add_series({
'categories': [sheet_name, 0, 0, 4, 0],
'values': [sheet_name, 0, 1, 4, 1],
'line': {'color': 'red'},
})