Google 电子表格 API。无法指定系列的 axisPosition

Google spreadsheet API. Cannot specify axisPosition of a series

我想指定系列的轴。如果我将 targetAxis 指定为“RIGHT_AXIS”,它不起作用..

LEFT_AXIS 和 RIGHT_AXIS 的 Axis-titles 也没有显示。只有最下面的一个。

我希望图表看起来像这样:

但它最终看起来像这样:

此处红轴位于底部,因为此列包含的数字比蓝色条带数字的列少得多。

谁知道我该如何解决这个问题?

这是我的代码:

          {
            addChart: {
              chart: {
                spec: {
                  title: "Graf - tibber",
                  basicChart: {
                    chartType: "COMBO",

                    axis: [

                      // X-AXIS
                      {
                        position: "BOTTOM_AXIS",
                        title: "TID",
                      },

                      // Y-AXIS LEFT
                      {
                        position: "LEFT_AXIS",
                        title: "FORBRUK(KWH)",
                       
                      },

                      // X-AXIS RIGHT
                      {
                        position: "RIGHT_AXIS",
                        title: "PRIS",
                      },
                      
                    ],
                    legendPosition: "BOTTOM_LEGEND",
                    
                    domains: [
                      {
                        domain: {
                          sourceRange: {
                            sources: [
                              {
                                sheetId: 0,
                                startRowIndex: 0,
                                endRowIndex: endIndex,
                                startColumnIndex: 0,
                                endColumnIndex: 1
                              }
                            ]
                          }
                        }
                      }
                    ],
                    
                
                    series: [
                      {
                        series: {
                          sourceRange: {
                            sources: [
                              {
                                sheetId: 0,
                                startRowIndex: 0,
                                endRowIndex: endIndex,
                                startColumnIndex: 5,
                                endColumnIndex: 6,
                              },
                            ],
                          },
                        },
                        targetAxis: "LEFT_AXIS",
                      },
                      {
                        series: {
                          sourceRange: {
                            sources: [
                              {
                                sheetId: 0,
                                startRowIndex: 0,
                                endRowIndex: endIndex,
                                startColumnIndex: 3,
                                endColumnIndex: 4,
                              },
                            ],
                          },
                        },
                        targetAxis: "RIGHT_AXIS",
                      }
                    ],
                    headerCount: 1,
                  },
                },
                position: {
                  newSheet: true,
                },
              },
            },
          },
        ],
  

改进请求

免责声明,右手轴 API 中存在错误,请参阅答案结尾

{
  "requests": [
    {
      "addChart": {
        "chart": {
          "spec": {
            "title": "Graf - tibber",
            "basicChart": {
              "chartType": "COMBO",
              "legendPosition": "BOTTOM_LEGEND",
              "axis": [
                {
                  "position": "BOTTOM_AXIS",
                  "title": "TID"
                },
                {
                  "position": "LEFT_AXIS",
                  "title": "FORBRUK(KWH)"
                },
                {
                  "position": "RIGHT_AXIS",
                  "title": "PRIS"
                }
              ],
              "domains": [
                {
                  "domain": {
                    "sourceRange": {
                      "sources": [
                        {
                          "sheetId": 0,
                          "startRowIndex": 0,
                          "endRowIndex": 8,
                          "startColumnIndex": 0,
                          "endColumnIndex": 1
                        }
                      ]
                    }
                  }
                }
              ],
              "series": [
                {
                  "series": {
                    "sourceRange": {
                      "sources": [
                        {
                          "sheetId": 0,
                          "startRowIndex": 0,
                          "endRowIndex": 8,
                          "startColumnIndex": 1,
                          "endColumnIndex": 2
                        }
                      ]
                    }
                  },
                  "targetAxis": "LEFT_AXIS",
                  "type": "COLUMN"
                },
                {
                  "series": {
                    "sourceRange": {
                      "sources": [
                        {
                          "sheetId": 0,
                          "startRowIndex": 0,
                          "endRowIndex": 8,
                          "startColumnIndex": 2,
                          "endColumnIndex": 3
                        }
                      ]
                    }
                  },
                  "targetAxis": "RIGHT_AXIS",
                  "type": "LINE"
                }
              ],
              "headerCount": 1
            }
          },
          "position": {
            "newSheet": true
          }
        }
      }
    }
  ]
}

请注意,我更改了行和列索引,因为我正在处理一些示例数据。 "type": "COLUMN""type": "LINE" 系列中的条目。事实上,对我来说,没有它我会得到 400 bad request。这会生成一个包含 BOTTOM_AXISLEFT_AXIS 但不包含 RIGHT_AXIS 的图表(请参阅下文了解相关信息)。该图表还有两种不同的比例,因此线条不会被列遮盖。

右轴

不幸的是,这是 API 的当前错误:https://issuetracker.google.com/issues/153528225 - 请务必用 ☆ 标记它,让 Google 知道这会影响您。

参考