简体   繁体   English

Google Analytics嵌入式API中的多系列图表

[英]Multi-series Charts in Google Analytics Embed API

I am using the Embed API to create a "LINE" chart of sessions per-day, per-medium (ga:sessions, ga:date, ga:medium, respectively), but I can only succeed in creating a single series (sessions per day). 我正在使用Embed API创建每日会话的“LINE”图表,每个媒体(ga:sessions,ga:date,ga:medium),但我只能成功创建一个系列(会话)每天)。

 var chart = new gapi.analytics.googleCharts.DataChart({ query : { "ids" : view_id, "start-date" : "30daysAgo", "end-date" : "yesterday", "dimensions" : "ga:date", // Works, but only produces single series // "dimensions" : "ga:date,ga:medium", - Doesn't work "metrics" : "ga:sessions", }, chart : { type : "LINE", container : "ga-chart", options : { width: "100%", title : title, } }, }); chart.execute(); 

Using the commented line above produces the error "All series on a given axis must be of the same data type". 使用上面的注释行会产生错误“给定轴上的所有系列必须具有相同的数据类型”。

How do I get a separate series for each value of ga:medium ("referral", "organic" and "(none)"). 如何为ga的每个值获得单独的系列:medium(“referral”,“organic”和“(none)”)。

Using the commented line above produces the error "All series on a given axis must be of the same data type". 使用上面的注释行会产生错误“给定轴上的所有系列必须具有相同的数据类型”。

Yeah, so this is the problem. 是的,所以这就是问题所在。 Google Charts doesn't know what you want. Google Charts不知道您想要什么。 On the one hand you say you want an x-axis with type date, and then you say you want an x-axis with values that are random strings (ga:medium). 一方面,你说你想要一个带有日期类型的x轴,然后你说你想要一个x轴,其值是随机字符串(ga:medium)。

What you're asking for makes logical sense to you (and me) because you're asking for a timeline, but there's no way the Embed API can make this work for any two dimensions. 您要求的内容对您(和我)来说具有逻辑意义,因为您要求的是时间轴,但Embed API无法使其适用于任何两个维度。 Consider ga:medium,ga:browser , how would that look on a chart? 考虑ga:medium,ga:browser ,它在图表上看起来如何?

So the short answer is you can't do what you're asking with the Embed API's gapi.analytics.googleCharts.DataChart component. 所以简短的回答是你不能用Embed API的gapi.analytics.googleCharts.DataChart组件做你想要的。 It supports multiple metrics in queries (since metrics are always numeric), but not multiple dimensions of different datatypes. 它支持查询中的多个指标(因为指标始终是数字),但不支持不同数据类型的多个维度。

The long answer is that you can use the gapi.analytics.report.Data component and run the query yourself, get the results back, and then construct your own Google Chart instance after you've manipulated the data into the format you need it in to work. 答案很长,您可以使用gapi.analytics.report.Data组件并自己运行查询,获取结果,然后在将数据操作为您需要的格式后构建自己的Google图表实例上班。

I hope that helps. 我希望有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM