javascript - Google Analytics 嵌入 API 图表 : Responsive

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

如何使此 Google Analytic Embed API 图表具有响应能力?我注意到此页面上的演示是响应式的:https://ga-dev-tools.appspot.com/embed-api/basic-dashboard/

我还在这里看到了使用 Google Charts 执行此操作的各种方法 https://code.google.com/p/google-visualization-api-issues/issues/detail?id=1056

<!doctype html>
<html lang="en">
<head>
<title>Google Charts</title>


    <script>
    (function(w,d,s,g,js,fs){
        g=w.gapi||(w.gapi={});g.analytics={q:[],ready:function(f){this.q.push(f);}};
        js=d.createElement(s);fs=d.getElementsByTagName(s)[0];
        js.src='https://apis.google.com/js/platform.js';
        fs.parentNode.insertBefore(js,fs);js.onload=function(){g.load('analytics');};
    }(window,document,'script'));
    </script>

    <script>

    gapi.analytics.ready(function() {
    var ACCESS_TOKEN = 'XXX'; // obtained from your service account

    gapi.analytics.auth.authorize({
        serverAuth: {
        access_token: ACCESS_TOKEN
        }
    });

    var linechart = new gapi.analytics.googleCharts.DataChart({
    query: {
    ids: 'ga:XXXXXX',
    metrics: 'ga:users',
    dimensions: 'ga:date',
    'start-date': '30daysAgo',
    'end-date': 'yesterday'
      },
    chart: {
    type: 'LINE',
    container: 'line-chart',
    options: {
        width: '100%',
        title: 'Test.com: Visitors over the past 30 days.',
        fontSize: 12
        }
    }
    });

    linechart.on('success', function(response) {
    // response.chart : the Google Chart instance.
    // response.data : the Google Chart data object.
    });

    linechart.execute();        

    });

    </script>

</head>

<body>
                <div>
                    <div id="embed-api-auth-container"></div>
                    <div id="line-chart" style='width:100%;height:300px;'></div>

                </div>    

</body>
</html>

最佳答案

我在这里回答了这个问题

(Google Embed API) How to change chart-table-style width

基本上,您只需添加一个选项元素并在图表选项元素内分配 x% 的宽度

关于javascript - Google Analytics 嵌入 API 图表 : Responsive,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27556273/

相关文章:

angularjs - Google Analytic中我的事件跟踪在哪里?

javascript - D3 力图 - 固定不重叠的节点

javascript - 当 chrome 通过 selenium 运行时,我看不到弹出的模式

javascript - 有什么方法可以保持按下 html 按钮?

html - 使用纯 css 格式化单词

jquery - 获取最后一天的访问Google Analytics(分析)

android - 在 Android 4.4 及以下版本中实现 Google Analytics 7.5.0(Play 服务)会崩溃

javascript - TINYMCE 在点击添加图像后添加输入字段

javascript - 如果未选中 JavaScript 中的复选框,则表循环

html - 在固定图像上使用 div 作为 mask