gspread icon indicating copy to clipboard operation
gspread copied to clipboard

Add chart functionality to gspread

Open darkfiberiru opened this issue 1 month ago • 4 comments

This commit adds comprehensive chart support to gspread, enabling users to create, update, delete, and list charts in Google Sheets.

New features:

  • Worksheet.add_chart() - Create charts with customizable properties
  • Worksheet.update_chart() - Modify existing chart specifications
  • Worksheet.delete_chart() - Remove charts by ID
  • Worksheet.list_charts() - List all charts in a worksheet

New enums in utils:

  • ChartType - Chart types (column, line, area, bar, scatter, combo, stepped_area)
  • ChartLegendPosition - Legend positions (bottom, left, right, top, no_legend)
  • ChartAxisPosition - Axis positions (bottom_axis, left_axis, right_axis)

Implementation details:

  • Uses Google Sheets API v4 batchUpdate endpoint
  • Supports multiple data series per chart
  • Handles both single-range (auto-generated domain) and multi-range (explicit domain) data
  • Includes input validation for data ranges and dimensions
  • Converts A1 notation to GridRange format
  • Properly handles enum to string conversion for API calls

Documentation:

  • Added comprehensive user guide section with examples
  • Includes usage examples for all chart operations
  • Documents all chart types and configuration options

Fixes applied during code review:

  • Fixed enum string conversion for ChartAxisPosition
  • Corrected data range logic for single vs multiple ranges
  • Added KeyError protection in list_charts()
  • Added input validation for empty ranges and invalid dimensions
  • Validated non-empty series before chart creation

🤖 Generated with Claude Code

darkfiberiru avatar Nov 25 '25 16:11 darkfiberiru

@burnash I understand if you not a fan of AI for personal reason or more complicated one but realizing gap in lack of ability to create graphs with gspread library I added them with help of claude-code from anthropic. So here it is.

darkfiberiru avatar Nov 25 '25 17:11 darkfiberiru

I see this repo is in freeze due to lack of maintainer

darkfiberiru avatar Nov 25 '25 17:11 darkfiberiru

I see this repo is in freeze due to lack of maintainer

hi :] thanks for the suggestion. yes it is.

please see https://github.com/burnash/gspread/issues/1570

alifeee avatar Nov 26 '25 11:11 alifeee

@darkfiberiru Something is unclear about updating an existing chart. Let's say I have this chart data range currently defined:

image

How do I extend the data range, axis and series down to say line 575? I didn't see anything in Worksheet.update_chart() to update those.

brianjmurrell avatar Dec 03 '25 15:12 brianjmurrell