2017-06-13 43 views
0

我正在嘗試使用Google Sheets API v4創建堆疊條形圖。我成功創建了沒有堆疊的圖表(即圖表中的兩個系列並排顯示)。但是,當我嘗試添加選項以堆疊時,出現錯誤。我正在關注在https://developers.google.com/sheets/api/reference/rest/v4/spreadsheets#BasicChartSpec找到的文檔。使用python創建使用Google Sheets API v4的堆疊條形圖時出錯

當我選擇疊層式添加到傳遞的參數在JSON(與值「堆疊」),我收到以下錯誤:

「無效的請求[0] .addChart:chartSpec.basicChart.stackedType不當chartSpec.basicChart.chartType爲BAR時受支持。「

我不明白這個錯誤信息,因爲文檔說stackedType適用於條形圖。有其他人遇到過這個問題嗎?

我有如下要求我送(JSON格式):

chart_request = { 
    "requests": [ 
     { 
      "addChart": { 
       "chart": { 
        "spec": { 
         "title": title, 
         "basicChart": { 
          "chartType": "BAR", 
          "legendPosition": "RIGHT_LEGEND", 
          "axis": [ 
           { 
            "position": "BOTTOM_AXIS", 
            "title": "Revenue ($)" 
            }, 
           { 
            "position": "LEFT_AXIS", 
            "title": "Channel" 
            } 
           ], 
          "domains": [ 
           { 
            "domain": { 
             "sourceRange": { 
              "sources": [ 
               { 
                "sheetId": sheetId, 
                "startRowIndex": 0, 
                "endRowIndex": nrows, 
                "startColumnIndex": 0, 
                "endColumnIndex": 1 
                } 
               ] 
              } 
             } 
            } 
           ], 
          "series": [ 
           { 
            "series": { 
             "sourceRange": { 
              "sources": [ 
               { 
                "sheetId": sheetId, 
                "startRowIndex": 0, 
                "endRowIndex": nrows, 
                "startColumnIndex": 2, 
                "endColumnIndex": 3 
                } 
               ] 
              } 
             }, 
            "targetAxis": "BOTTOM_AXIS" 
            }, 
           { 
            "series": { 
             "sourceRange": { 
              "sources": [ 
               { 
                "sheetId": sheetId, 
                "startRowIndex": 0, 
                "endRowIndex": nrows, 
                "startColumnIndex": 5, 
                "endColumnIndex": 6 
                } 
               ] 
              } 
             }, 
            "targetAxis": "BOTTOM_AXIS" 
            } 
           ], 
          "headerCount": 1, 
          "stackedType": "STACKED", 
          } 
         }, 
        "position": { 
         "overlayPosition": { 
          "anchorCell": { 
           "sheetId": sheetId, 
           "rowIndex": 15, 
           "columnIndex": 0, 
           }, 
          "widthPixels": 600, 
          "heightPixels": 300, 
          }, 
         } 
        } 
       } 
      } 
     ] 
    } 

預先感謝您。

回答

0

如果檢查BasicChartSeries它說,它僅適用於圖圖表類型COMBO:

enum(BasicChartType)

The type of this series. Valid only if the chartType is COMBO. Different types will change the way the series is visualized. Only LINE, AREA, and COLUMN are supported.

我建議你查一下,如果你在做什麼,與COMBO chartTypes作品。如果確實如此,那麼確認您的問題,只支持COMBO圖表類型。

0

我是Google表格小組的工程師。通過API創建堆疊圖表時,我們發現了一個錯誤,該錯誤將很快修復。

謝謝發佈!

  • 邁克爾
+0

真棒,謝謝! – richincode

相關問題