我正在尝试使用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