【问题标题】:How to activate the aggregate option in Google Sheets API如何在 Google Sheets API 中激活聚合选项
【发布时间】:2021-07-14 14:22:44
【问题描述】:

我正在尝试通过 Google Sheets API 从 Python 在 Google Sheets 中创建折线图。但我无法激活聚合选项。

                {
                    "addChart": {
                        "chart": {
                            "spec": {
                                "title": type,
                                "basicChart": {
                                    "chartType": "LINE",
                                    "legendPosition": "TOP_LEGEND",
                                    "axis": [
                                        # X-AXIS
                                        {
                                            "position": "BOTTOM_AXIS",
                                            "title": "Date"
                                        },
                                        # Y-AXIS
                                        {
                                            "position": "LEFT_AXIS",
                                            "title": "Number of "+type
                                        }
                                    ],
                                    "domains": [
                                        {
                                            "domain": {
                                                "sourceRange": {
                                                    "sources": [
                                                        {
                                                            "sheetId": gid,
                                                            "startRowIndex": 0,
                                                            "endRowIndex": 1000000,
                                                            "startColumnIndex": 1,
                                                            "endColumnIndex": 2
                                                        }
                                                    ]
                                                }
                                            }
                                        }
                                    ],
                                    "series": [
                                        {
                                            "series": {
                                                "sourceRange": {
                                                    "sources": [
                                                        {
                                                            "sheetId": gid,
                                                            "startRowIndex": 0,
                                                            "endRowIndex": 1000000,
                                                            "startColumnIndex": 9,
                                                            "endColumnIndex": 10
                                                        }
                                                    ]
                                                },
                                                "aggregateType": "SUM"
                                            },
                                            "targetAxis": "LEFT_AXIS"
                                        }...

正如您在上面看到的,我正在创建一个折线图,其中包含来自另一张工作表的 adimpression 数据。除了聚合之外,一切都很好。我添加了 'aggregateType' = 'SUM' 但它仍然不起作用。 你们有解决这个问题的办法吗?

我一直在寻找解决方案,但找不到任何有用的东西。有人谈到了 .setOption('applyAggregateData', 0) 但该解决方案对我不起作用,我想我需要在请求正文中提供一些额外的信息。

谢谢。

【问题讨论】:

    标签: python google-api python-requests google-sheets-api


    【解决方案1】:

    Sheets API documentation 开始,aggregateType 字段仅支持由 BigQuery 请求生成的数据源图表。

    要使聚合起作用,您需要使用ChartSpec 中的dataSourceChartProperties 字段定义数据源。

    "dataSourceChartProperties": {
      object (DataSourceChartProperties)
    },
    

    关于数据源对象的更多信息可以在here找到。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-07-20
      • 2018-09-03
      • 2020-10-08
      • 2019-10-26
      • 1970-01-01
      • 1970-01-01
      • 2017-01-31
      • 1970-01-01
      相关资源
      最近更新 更多