2017-06-13 75 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

相关问题