Change color of pie chart with google sheets API

Viewed 19

I'm using Python google sheet API v4 to produce a pie chart using the following code:

body = {
      "requests": [
        {
          "addChart": {
            "chart": {
              "spec": {
                  "backgroundColorStyle" : {
                      "themeColor": "BACKGROUND"
                    },
                "pieChart": {
                  "legendPosition": "LABELED_LEGEND",
                    "pieHole":0.7,
                  "domain": {
                    "sourceRange": {
                      "sources": [
                        {
                          "sheetId": 0,
                          "startRowIndex": 0,
                          "endRowIndex": last_row,
                          "startColumnIndex": 0,
                          "endColumnIndex": 1
                        }
                      ]
                    }
                  },
                  "series": {
                    "sourceRange": {
                      "sources": [
                        {
                          "sheetId": 0,
                          "startRowIndex": 0,
                          "endRowIndex": 7,
                          "startColumnIndex": 3,
                          "endColumnIndex": 4
                        }
                      ]
                    }
                  },
                }
              },
              "position": {
                "overlayPosition": {
                  "anchorCell": {
                    "sheetId": 0,
                    "rowIndex": 1,
                    "columnIndex": 5
                  }
                }
              }
            }
          }
        }
      ]
    }
request = service.spreadsheets().batchUpdate(spreadsheetId=sheet_id, body=body)
response = request.execute()

This get me exactly what I want, but I would like to set the color of each slice according to a give color palette. I've looked for a way to do so but haven't found it, so is it possible to do so thought the API?

To further clarify with an image, this is what I get with 4 class. How can I set the color of this 4 slice to go from green, blu, yellow, red to green, purple, yellow, orange? Graph I get with 4 class

0 Answers
Related