Question

I have created graph using add series method.is it possible to pass string into add_series method as I am creating worksheet with string value ( depend on some condition). In below code, Can I replace Graph with string. name = "abhi"

chart.add_series({
    'categories' : '=name!$B$32:$B$532',
    'values': '=name!$C$32:$C$532',
    'name':'clk2q0_S',
    'line':{'color':'blue'}})
Was it helpful?

Solution

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'},
})
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top