如何在google工作表中添加第二个yaxis

2024-10-01 00:14:35 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在使用google api python客户端处理google spreadhsset,我正在尝试将图表添加到具有两个y轴的工作表中,一个在左侧,一个在右侧。在登录到google服务的代码之后,要使用电子表格资源和batchUpdate方法进行此im,请求主体是

body_chart_Create={
  "requests": [
    {
      "addChart": {
        "chart": {
            "position":
                {
                "newSheet": True
                },
          "spec": {
            "title": "TEST CHART",
            "titleTextPosition": {
            "horizontalAlignment":"center"
            },
            "basicChart": {
              "chartType": "LINE",
              "legendPosition": "RIGHT_LEGEND",
              "axis": [
                {
                  "position": "BOTTOM_AXIS",
                  "title": "Time"
                },
                {
                  "position": "LEFT_AXIS",
                  "title": "Relative Humidity [%rH]"
                },
                {
                  "position": "RIGHT_AXIS",
                  "title": "Temperature [°C]"
                }
              ],
              "domains": [
                {
                  "domain": {
                    "sourceRange": {
                      "sources": [
                        {
                          "sheetId":814487582,
                          "startRowIndex": 0,
                          "endRowIndex": 1003,
                          "startColumnIndex": 0,
                          "endColumnIndex":1
                        }
                      ]
                    }
                  }
                }
              ],
              "series": [
                {
                  "series": {
                    "sourceRange": {
                      "sources": [
                        {
                          "sheetId": 814487582,
                          "startColumnIndex": 1,
                          "endColumnIndex": 2
                        }
                      ]
                    }
                  },
                  "targetAxis": "LEFT_AXIS"
                },
                  {
                  "series": {
                    "sourceRange": {
                      "sources": [
                        {
                          "sheetId": 814487582,
                          "startColumnIndex": 2,
                          "endColumnIndex": 3
                        }
                      ]
                    }
                  },
                  "targetAxis": "RIGHT_AXIS"
                },
              ],
              "headerCount": 1
            }
          },
        }
      }
    }
  ]
}

对服务的调用是:

spreadsheets = service.spreadsheets()
response = spreadsheets.batchUpdate(spreadsheetId=ID, body=body_chart_Create).execute()

结果是: enter image description here

我们可以看到,图表在图纸上显示,但右轴,在本例中,命名为

温度[°C]剂量装置


Tags: righttitlegooglechart图表positionbodyseries
1条回答
网友
1楼 · 发布于 2024-10-01 00:14:35

这似乎是一个错误

我冒昧地在谷歌的问题追踪器上为您报告了这一点,详细说明了以下行为:

你可以打电话☆ 在页面左上角的问题编号旁边,它让谷歌知道有更多的人遇到了这个问题,因此它更有可能更快地被看到

我希望这对你有帮助

相关问题 更多 >