Chart Object

Note

The chart object is currently still lacking a lot of important methods/attributes.

Note

Check out the What’s New regarding the latest changes to the Chart object.

class xlwings.Chart(*args, **kwargs)

A chart object that represents an existing Excel chart can be created with the following arguments:

Chart(1)            Chart('Sheet1', 1)              Chart(1, 1)
Chart('Chart 1')    Chart('Sheet1', 'Chart 1')      Chart(1, 'Chart 1')

If no worksheet name is provided as first argument (as name or index), it will take the chart from the active sheet.

To insert a new chart into Excel, create it as follows:

Chart().add()
Parameters:
  • *args

    Definition of sheet (optional) and chart in the above described combinations.

  • chart_type (Member of ChartType, default xlColumnClustered) – Chart type, can also be set using the chart_type property
add(sheet=None, left=168, top=217, width=355, height=211, **kwargs)

Inserts a new chart in Excel.

Parameters:
  • sheet (string or integer, default None) – Name or Index of the sheet, defaults to the active sheet
  • left (float, default 100) – left position in points
  • top (float, default 75) – top position in points
  • width (float, default 375) – width in points
  • height (float, default 225) – height in points
  • chart_type (xlwings.ChartType member, default xlColumnClustered) – Excel chart type. E.g. xlwings.ChartType.xlLine
  • name (str, default None) – Excel chart name. Defaults to Excel standard name if not provided, e.g. ‘Chart 1’
  • source_data (xlwings Range) – e.g. Range(‘A1’).table
name

Gets and sets the name of a chart

chart_type

Gets and sets the chart type of a chart

activate()

Makes the chart the active chart.

set_source_data(source)

Sets the source for the chart

Parameters:source (Range) – xlwings Range object, e.g. Range('A1')

Previous topic

Range Object

This Page