Chart

class pygsheets.Chart(worksheet, domain=None, ranges=None, chart_type=None, title='', anchor_cell=None, json_obj=None)[source]

Represents a chart in a sheet.

Parameters:
  • worksheet – Worksheet object in which the chart resides
  • domain – Cell range of the desired chart domain in the form of tuple of tuples
  • ranges – Cell ranges of the desired ranges in the form of list of tuple of tuples
  • chart_type – An instance of ChartType Enum.
  • title – Title of the chart
  • anchor_cell – Position of the left corner of the chart in the form of cell address or cell object
  • json_obj – Represents a json structure of the chart as given in api.
title

Title of the chart

domain

Domain of the chart. The domain takes the cell range in the form of tuple of cell adresses. Where first adress is the top cell of the column and 2nd element the last adress of the column.

Example: ((1,1),(6,1)) or (‘A1’,’A6’)

chart_type

Type of the chart The specificed as enum of type :class:’ChartType’

The available chart types are given in the api docs .

ranges

Ranges of the chart (y values) A chart can have multiple columns as range. So you can provide them as a list. The ranges are taken in the form of list of tuple of cell adresses. where each tuple inside the list represents a column as staring and ending cell.

Example:
[((1,2),(6,2)), ((1,3),(6,3))] or [(‘B1’,’B6’), (‘C1’,’C6’)]
title_font_family

Font family of the title. (Default: ‘Roboto’)

font_name

Font name for the chart. (Default: ‘Roboto’)

legend_position

Legend postion of the chart. (Default: ‘RIGHT_LEGEND’) The available options are given in the api docs.

id

Id of the this chart.

anchor_cell

Position of the left corner of the chart in the form of cell address or cell object, Changing this will move the chart.

delete()[source]

Deletes the chart.

Warning

Once the chart is deleted the objects of that chart still exist and should not be used.

refresh()[source]

Refreshes the object to incorporate the changes made in the chart through other objects or Google sheet

update_chart()[source]

updates the applied changes to the sheet.

get_json()[source]

Returns the chart as a dictionary structured like the Google Sheets API v4.

set_json(chart_data)[source]

Reads a json-dictionary returned by the Google Sheets API v4 and initialize all the properties from it.

Parameters:chart_data – The chart data as json specified in sheets api.