Charts
- class Charts
A collection of all
chartobjects on the specified sheet:>>> import xlwings as xw >>> xw.books['Book1'].sheets[0].charts Charts([<Chart 'Chart 1' in Sheet1>, <Chart 'Chart 1' in Sheet1>])
在 0.9.0 版本加入.
- add(left=0, top=0, width=355, height=211, chart_type=None, source=None, plot_by=None, name=None, anchor=None, style=227)
在指定的工作表中创建一个新的图表。
- 参数:
left (float) -- left position in points. If you use
top/left, you must not provide a value foranchor.top (float) -- top position in points. If you use
top/left, you must not provide a value foranchor.width (float) -- 宽带,单位是
point。height (float) -- 高度,单位是
point。chart_type (str | None) -- Chart type, see
Chart.chart_type. New in version 0.37.3.source (Range | None) -- Source data range, see
Chart.set_source_data. New in version 0.37.3.plot_by (str | None) --
"rows"or"columns", requiressource. New in version 0.37.3.name (str | None) -- Excel chart name. Defaults to Excel standard name if not provided, e.g., 'Chart 1'. New in version 0.37.3.
anchor (Range | None) -- The xlwings Range object of where you want to insert the chart. If you use
anchor, you must not provide values fortop/left. New in version 0.37.3.style (int | None) -- Built-in chart style. Defaults to the modern Excel style 227. Use
Noneto retain the host application's native creation default. SeeChart.style.
- 返回类型:
示例
>>> import xlwings as xw >>> sheet = xw.Book().sheets[0] >>> sheet.range('A1').value = [['Foo1', 'Foo2'], [1, 2]] >>> chart = sheet.charts.add( ... source=sheet.range('A1').expand(), ... chart_type='line', ... anchor=sheet.range('D1'), ... ) >>> chart.title = 'My chart'
The same in steps:
>>> chart = sheet.charts.add() >>> chart.set_source_data(sheet.range('A1').expand()) >>> chart.chart_type = 'line' >>> chart.name 'Chart 1'