一个页面上的两个谷歌图表与超级代理

时间:2014-10-27 22:14:52

标签: javascript google-visualization google-analytics-api

如何在一个页面上显示两个Google图表?我使用超级代理从谷歌分析API获取JSON表。

目前,仅显示第一个图表(表格)。缺少第二张图表。

我的代码附在下面。我不熟悉API的东西。我检查了一些解决方案,但都是本地数据而不是在线资源,例如电子表格,JSON表。

任何帮助将不胜感激。

<html>
<head>
    <!--Load the AJAX API-->
    <script type="text/javascript"
    src='https://www.google.com/jsapi?autoload={"modules":[{"name":"visualization","version":"1"}]}'>
    </script>

    <script type="text/javascript">
        google.load('visualization', '1', {packages: ['table','geochart']});
        google.setOnLoadCallback(drawVisualization);

        function drawCountriesTable() {
            var CountriesTableWrapper = new google.visualization.ChartWrapper({
            "containerId": "CountriesTable_div",
            "dataSourceUrl": "https://top3dapp.appspot.com/query?id=agpzfnRvcDNkYXBwchULEghBcGlRdWVyeRiAgICAgICACgw&format=data-table-response",
            "refreshInterval": 43200,
            "chartType": "Table",
            "options": {
                "showRowNumber" : true
                }
            });

            CountriesTableWrapper.draw();
        }

        function drawRegionsMap() {
            var RegionsMapWrapper = new google.visualization.ChartWrapper({
            "containerId": "RegionsMap_div",
            "dataSourceUrl": "https://top3dapp.appspot.com/query?id=agpzfnRvcDNkYXBwchULEghBcGlRdWVyeRiAgICAvKGCCgw&format=data-table-response",
            "refreshInterval": 43200,
            "chartType": "GeoChart",
            "options": {
                "displayMode": 'markers',
                "colorAxis": { "colors": ['#A9DEF2', '#048DC7'] }
                }
            });

            RegionsMapWrapper.draw();
        }

        function drawVisualization() {
            drawCountriesTable();
            drawRegionsMap();
        }
    </script>
</head>
<body>
    <h2>Countries</h2>
    <div id="CountriesTable_div" style="margin:auto;width:630px;"></div>
    <h2>Regions</h2>
    <div id="RegionsMap_div" style="margin:auto;width:630px;"></div>
</body>

1 个答案:

答案 0 :(得分:1)

这是超级代理的错误。错误报告见: https://github.com/googleanalytics/google-analytics-super-proxy/issues/17

按照github上建议的步骤进行操作:

  1. 打开query_helper.py
  2. 转到方法&#39; GetPublicEndpointResponse&#39;
  3. 在第395行,你应该看到

    transformed_response_content = response.get('transformed_content')

  4. 将该行更改为:

    transformed_response_content = transform.Transform(response_content)
    
    1. 测试/部署更新