我正在嘗試使用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,
},
}
}
}
}
]
}
預先感謝您。
真棒,謝謝! – richincode