我正在尝试使用Google Analytic Embed API(https://developers.google.com/analytics/devguides/reporting/embed/v1/component-reference#datachart)创建图表。身份验证工作正常,但未呈现图表。
这是我的代码:
<html>
...
<body>
<script>
(function(w,d,s,g,js,fjs){
g=w.gapi||(w.gapi={});g.analytics={q:[],ready:function(cb){this.q.push(cb)}};
js=d.createElement(s);fjs=d.getElementsByTagName(s)[0];
js.src='https://apis.google.com/js/platform.js';
fjs.parentNode.insertBefore(js,fjs);js.onload=function(){g.load('analytics')};
}(window,document,'script'));
</script>
<script>
gapi.analytics.ready(function() {
var CLIENT_ID = '[client id, which I removed for this purpose]';
gapi.analytics.auth.authorize({
container: 'auth-button',
clientid: CLIENT_ID,
});
var chart = new gapi.analytics.googleCharts.DataChart({
query: {
'ids': 'ga: [profile id, removed]',
'metrics': 'ga:sessions',
'dimensions': 'ga:date',
'start-date': '30daysAgo',
'end-date': 'yesterday',
},
chart: {
'type': 'LINE',
'container': 'line-chart',
'options': {
'title': 'Test report',
}
}
});
chart.on('success', function(response) {
response.chart
});
chart.execute();
});
</script>
<div id="auth-button"></div>
<div id="line-chart" style='width:100%;height:300px;'></div>
</body>
</html>
如果有人可以看一下代码并为我提供帮助,我将不胜感激。
提前致谢
克里斯
当我使用客户ID和视图ID时,您的确切代码对我来说很好。
这使我相信您没有正确设置客户端ID,在这种情况下,您应该在开发人员控制台中遇到JavaScript错误。你看那里了吗?最可能的问题是您没有设置正确的原点。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句