How to use the pygsheets.custom_types.ChartType function in pygsheets

To help you get started, we’ve selected a few pygsheets examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github nithinmurali / pygsheets / pygsheets / chart.py View on Github external
def set_json(self, chart_data):
        """
        Reads a json-dictionary returned by the Google Sheets API v4 and initialize all the properties from it.

        :param chart_data:   The chart data as json specified in sheets api.
        """
        anchor_cell_data = chart_data.get('position',{}).get('overlayPosition',{}).get('anchorCell')
        self._anchor_cell = (anchor_cell_data.get('rowIndex',0)+1, anchor_cell_data.get('columnIndex',0)+1)
        self._title = chart_data.get('spec',{}).get('title',None)
        self._chart_id = chart_data.get('chartId',None)
        self._title_font_family = chart_data.get('spec',{}).get('titleTextFormat',{}).get('fontFamily',None)
        self._font_name = chart_data.get('spec',{}).get('titleTextFormat',{}).get('fontFamily',None)    
        basic_chart = chart_data.get('spec',{}).get('basicChart', None)
        self._chart_type = ChartType(basic_chart.get('chartType', None))
        self._legend_position = basic_chart.get('legendPosition', None)
        domain_list = basic_chart.get('domains')
        for d in domain_list:
            source_list = d.get('domain',{}).get('sourceRange',{}).get('sources',None)
            for source in source_list:
                start_row = source.get('startRowIndex',0)
                end_row = source.get('endRowIndex',0)
                start_column = source.get('startColumnIndex',0)
                end_column = source.get('endColumnIndex',0)
                self._domain = [(start_row+1, start_column+1),(end_row, end_column)]
        range_list = basic_chart.get('series', [])
        self._ranges = []
        for r in range_list:
            source_list = r.get('series',{}).get('sourceRange',{}).get('sources',None)
            for source in source_list:
                start_row = source.get('startRowIndex',0)
github nithinmurali / pygsheets / pygsheets / chart.py View on Github external
def chart_type(self, new_chart_type):
        if not isinstance(new_chart_type, ChartType):
            raise InvalidArgumentValue
        temp = self._chart_type
        self._chart_type = new_chart_type
        try:
            self.update_chart()
        except:
            self._chart_type = temp