带有分组数据过滤器的 Google 仪表板 - 如何绘制分组数据图表
我希望创建一个具有过滤功能的 Google 图表 API 仪表板,但我想根据分组数据绘制图表。例如,我可以创建一个如下所示的数据表:
salesman cust_age cust_sex quantity
Joe 21 Male 3
Joe 30 Female 10
Suzie 40 Female 2
Dave 15 Female 5
Dave 30 Male 10
我可以适当地创建一个仪表板,该仪表板创建两个控件(针对 cust_age 和 cust_sex)以及任意数量的输出图形和表格,所有这些输出图形和表格都从外部数据源中提取 - 这是非常常用的东西,参见http://code.google.com/apis/chart/interactive/docs/gallery/controls。 html
我遇到的问题是如何按分组值显示所有图表。以饼图为例,在没有任何过滤器的情况下,饼图有 5 个切片(Joe、Joe、Suzie、Dave、Dave) - 我只想看到三个(Joe、Suzie Dave)。当然,当应用控件时,所有内容都应该更新。
换句话说,过滤器应该作用于原始数据表,但图表应该基于分组数据表。
我猜我们可以使用分组功能: http://code.google.com/apis/ajax/playground/?type=visualization#组 但是我似乎无法将过滤器绑定到更大的数据表,更新分组表,然后根据分组表绘制图表。
有什么想法吗?
I am looking to create a Google charts API dashboard with filtering but I would like to chart the data based on grouped data. For example, I can create a datatable such as this:
salesman cust_age cust_sex quantity
Joe 21 Male 3
Joe 30 Female 10
Suzie 40 Female 2
Dave 15 Female 5
Dave 30 Male 10
I can appropriately create a dashboard that creates two controls (for cust_age and cust_sex) and any number of output graphs and tables all pulling from an external data source - this is pretty stock stuff, see http://code.google.com/apis/chart/interactive/docs/gallery/controls.html
The problem that I am having is how to show all charts by grouped values. Using a pie chart as an example, without any filters there are 5 slices of the pie (Joe, Joe, Suzie, Dave, Dave) - I would like to see only three (Joe, Suzie Dave). Of course, when a control is applied everything should update.
In other words, the filters should act on the original datatable, but the charts should be based on a grouped datatable.
I would guess that we could use the grouping function:
http://code.google.com/apis/ajax/playground/?type=visualization#group
however I cannot seem to bind the filters to the larger datatable, update the grouped table, and then draw the charts based on the grouped table.
Any thoughts?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我找到了一个解决方法,您应该使用不带仪表板的图表包装器,这样您就可以传递 dataTable 作为参数:
然后,您应该向控件添加回调,以便每当控件发生更改时,仪表板外部的图表都会更新,就像手动绑定,我们假设 cust_sex 的控件是 $genderPicker,ChartWrapper 表对象是 $tableWrapper:
结果:每当您选择男性、女性或两者时,饼图都会反映按名称分组的过滤结果。希望它对某人有帮助,并对我蹩脚的英语感到抱歉。
I found a workaround, you should use the chartWrapper without the dashboard, so you can pass a dataTable as parameter:
Then, you should add a callback to your controls so whenever the control changes the charts outside of the dashboard will be updated, like a manual binding, let's assume that the control for cust_sex is $genderPicker and the ChartWrapper table object is $tableWrapper:
The result: whenever you chose male, female or both the pie chart will reflect the filtered results grouped by name. Hope it helps someone and sorry for my broken english.
另一种方法是使用仪表板对象的“就绪”事件,然后根据对仪表板主表进行的分组在其中创建图表或表格。
例如:
another way to do it, is to use the 'ready' event of the dashboard object, then create a chart or table in there based on a grouping done to the main table of the dashboard.
eg:
经过长时间的研发,我找到了解决这个问题的方法。为了修复此问题,我使用了两个事件侦听器,其中一个是 ready 事件,另一个是 statechange 事件,如下所示,
查找我的初始(有问题的)此处示例 并修复(已解决)示例这里
After a long R&D, I found the solution fot this problem. For the fix, I used two event listeners in which one is ready event and other is statechange event as,
Find my initial (problematic) sample here and fixed (solved) sample here
阅读此帖子:如何不显示数据表 (至少阅读前两篇文章 - 其余的仅在您处理大型数据集时才重要)。
基本上,您必须使用对用户完全隐藏的中间图表(表格是一个不错的选择,因为它们的编写和渲染速度相对较快,并且内存占用比大多数图表更低)。您将类别选择器绑定到仪表板中的此图表。然后,您为选取器的“statechange”事件设置一个事件处理程序,该事件处理程序获取数据,将其分组到一个新的数据表中,并根据分组的数据绘制饼图。
Read this thread: How to not display the data table (read at least the first two posts - the rest are really only important if you are dealing with large data sets).
Basically, you have to use an intermediary chart (tables are a good choice, because they are relatively fast to write and render, with a lower memory footprint than most charts) that is completely hidden from the users. You bind the category picker to this chart in the dashboard. Then you set up an event handler for the picker's "statechange" event that takes the data, groups it into a new DataTable, and draws the PieChart based on the grouped data.