亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

Python Google Spreadsheet API 氣泡圖未正確顯示

Python Google Spreadsheet API 氣泡圖未正確顯示

慕的地8271018 2023-09-05 15:51:36
我使用 Google 示例https://developers.google.com/chart/interactive/docs/gallery/bubblechart來使用 Python v3.7.8 測試 Google Spreadshhet API v4 以創建氣泡圖。數據存儲在 Google Drive 的電子表格中,我在其中創建氣泡圖。氣泡圖已創建,但氣泡不可見/不顯示。下面的代碼:from googleapiclient.discovery import buildfrom google_auth_oauthlib.flow import InstalledAppFlowfrom google.auth.transport.requests import Request...body = {'requests':         [{'addChart':           {'chart':            {'spec':             {'title': 'Correlation between life expectancy, fertility rate and population of some world countries (2010)',              'titleTextPosition':              {'horizontalAlignment': 'CENTER'},              'bubbleChart':              {'legendPosition': 'RIGHT_LEGEND',              'domain':               {'sourceRange':                {'sources':                 [{'sheetId': 909072886,                   'startRowIndex': 17,                   'endRowIndex': 27,                   'startColumnIndex': 1,                   'endColumnIndex': 2}]}},               'series':               {'sourceRange':                {'sources':                 [{'sheetId': 909072886,                   'startRowIndex': 17,                   'endRowIndex': 27,                   'startColumnIndex': 2,                   'endColumnIndex': 3}]}},               'groupIds':               {'sourceRange':                {'sources':                 [{'sheetId': 909072886,                  'startRowIndex': 17,                  'endRowIndex': 27,                  'startColumnIndex': 3,                  'endColumnIndex': 4}]}},               'bubbleLabels':              }            }           }          }         }        ]       }response = service.spreadsheets().batchUpdate(spreadsheetId=file_id, body=body).execute()我應該得到以下信息:但我明白了:沒有顯示氣泡。備注:將鼠標懸停在(不可見)氣泡上,它會顯示該國所有正確的數據(預期壽命、生育率、人口、正確顏色的地區)!
查看完整描述

1 回答

?
當年話下

TA貢獻1890條經驗 獲得超9個贊

在這種情況下,我建議將bubbleMaxRadiusSize和包含bubbleMinRadiusSize在請求正文中,如下所示。當你的請求體被修改后,就變成了下面這樣。


從:

'bubbleOpacity': 1.0}},

到:

'bubbleOpacity': 1.0,

'bubbleMaxRadiusSize': 50,

'bubbleMinRadiusSize': 5

}},

在此修改中,50和分別5用作 和 的樣本bubbleMaxRadiusSize值bubbleMinRadiusSize。所以請根據您的實際情況修改這些值。

結果:

https://img1.sycdn.imooc.com//64f6de6b0001ade905920365.jpg

整個腳本:

body = {'requests': [{'addChart': {'chart': {'spec': {'title': 'Correlation between life expectancy, fertility rate and population of some world countries (2010)', 'titleTextPosition': {'horizontalAlignment': 'CENTER'},

     'bubbleChart': {

    'legendPosition': 'RIGHT_LEGEND',

    'domain': {'sourceRange': {'sources': [{

        'sheetId': 909072886,

        'startRowIndex': 17,

        'endRowIndex': 27,

        'startColumnIndex': 1,

        'endColumnIndex': 2,

        }]}},

    'series': {'sourceRange': {'sources': [{

        'sheetId': 909072886,

        'startRowIndex': 17,

        'endRowIndex': 27,

        'startColumnIndex': 2,

        'endColumnIndex': 3,

        }]}},

    'groupIds': {'sourceRange': {'sources': [{

        'sheetId': 909072886,

        'startRowIndex': 17,

        'endRowIndex': 27,

        'startColumnIndex': 3,

        'endColumnIndex': 4,

        }]}},

    'bubbleLabels': {'sourceRange': {'sources': [{

        'sheetId': 909072886,

        'startRowIndex': 17,

        'endRowIndex': 27,

        'startColumnIndex': 0,

        'endColumnIndex': 1,

        }]}},

    'bubbleSizes': {'sourceRange': {'sources': [{

        'sheetId': 909072886,

        'startRowIndex': 17,

        'endRowIndex': 27,

        'startColumnIndex': 4,

        'endColumnIndex': 5,

        }]}},

    'bubbleOpacity': 1.0,

    'bubbleMaxRadiusSize': 50,  # Added

    'bubbleMinRadiusSize': 5,  # Added

    }}, 'position': {'overlayPosition': {

    'anchorCell': {'sheetId': 909072886, 'rowIndex': 61, 'columnIndex': 6},

    'offsetXPixels': 0,

    'offsetYPixels': 0,

    'widthPixels': 600,

    'heightPixels': 371,

    }}}}}]}


response = service.spreadsheets().batchUpdate(spreadsheetId=file_id, body=body).execute()


查看完整回答
反對 回復 2023-09-05
  • 1 回答
  • 0 關注
  • 142 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號