Jquery flot 相互依赖行 +饼图
我创建了一个 ajax 驱动的浮点折线图,我希望使用折线图中的求和数据将其与浮点饼图一起表示。
折线图的数据可能如下所示:
var datasets = {
"usa": {
label: "USA",
data: [[1988, 483994], [1989, 479060], [1990, 457648], [1991, 401949], [1992, 424705], [1993, 402375], [1994, 377867], [1995, 357382], [1996, 337946], [1997, 336185], [1998, 328611], [1999, 329421], [2000, 342172], [2001, 344932], [2002, 387303], [2003, 440813], [2004, 480451], [2005, 504638], [2006, 528692]]
},
"russia": {
label: "Russia",
data: [[1988, 218000], [1989, 203000], [1990, 171000], [1992, 42500], [1993, 37600], [1994, 36600], [1995, 21700], [1996, 19200], [1997, 21300], [1998, 13600], [1999, 14000], [2000, 19100], [2001, 21300], [2002, 23600], [2003, 25100], [2004, 26100], [2005, 31100], [2006, 34700]]
},
etc...
};
聚合此数据以使其适合饼图插件的最简单方法是什么?如果我将当前结果集提供给饼图,它将仅考虑每个数据集的第一个值。
谢谢!
I've created an ajax driven flot line chart that I would like to have represented along side a flot pie chart using the summed data from the line chart.
Data for the line chart might look something like this:
var datasets = {
"usa": {
label: "USA",
data: [[1988, 483994], [1989, 479060], [1990, 457648], [1991, 401949], [1992, 424705], [1993, 402375], [1994, 377867], [1995, 357382], [1996, 337946], [1997, 336185], [1998, 328611], [1999, 329421], [2000, 342172], [2001, 344932], [2002, 387303], [2003, 440813], [2004, 480451], [2005, 504638], [2006, 528692]]
},
"russia": {
label: "Russia",
data: [[1988, 218000], [1989, 203000], [1990, 171000], [1992, 42500], [1993, 37600], [1994, 36600], [1995, 21700], [1996, 19200], [1997, 21300], [1998, 13600], [1999, 14000], [2000, 19100], [2001, 21300], [2002, 23600], [2003, 25100], [2004, 26100], [2005, 31100], [2006, 34700]]
},
etc...
};
What would be the easiest way aggregate this data so that it would be fit for the pie chart plug-in? If I feed this current result set to the pie chart, it will only consider the first value of each dataset.
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
最好分别绘制每年的值,如下所示:
使年份可以通过某些适当的组件(例如递增/递减按钮)进行选择。对于所选年份,绘制每个国家/地区的相应值。
例如,在 1988 年,美国的绘图为 483994,俄罗斯的绘图为 218000。
It would probably be best to graph the the value separately for each year, like this:
Make the year selectable by some appropriate component such as increment/decrement buttons. For the year selected, plot the respective value for each country.
For example, in year 1988, plot 483994 for USA and 218000 for Russia.
我最终使用了一种方法,将每个图表的结果合并到服务器端的一个 json 响应中,然后将它们拉到客户端,如下所示:
然后在 ajax 事件的回调中,我将它们解析为每个图表的单独数据集图形:
I ended up using an approach that combined the results for each chart into one json response on the server side and then pulled them out on the client like thus:
Then on the callback for the ajax event, I parsed them out into separate datasets for each graph: