Jquery flot 相互依赖行 +饼图

发布于 2024-11-18 18:39:08 字数 914 浏览 9 评论 0原文

我创建了一个 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

暖风昔人 2024-11-25 18:39:08

最好分别绘制每年的值,如下所示:

使年份可以通过某些适当的组件(例如递增/递减按钮)进行选择。对于所选年份,绘制每个国家/地区的相应值。
例如,在 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.

明天过后 2024-11-25 18:39:08

我最终使用了一种方法,将每个图表的结果合并到服务器端的一个 json 响应中,然后将它们拉到客户端,如下所示:

var datasets = {
"usa-line": {
    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]]
},  
"usa-pie": {
    label: "USA",
    data: [[1, TOTAL GOES HERE]]]
},        
"russia-line": {
    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]]
},
"russia-pie": {
    label: "Russia",
    data: [[1, TOTAL GOES HERE]]]
}
};

然后在 ajax 事件的回调中,我将它们解析为每个图表的单独数据集图形:

$.ajax({
        type: "POST",
        dataType: 'json',
        url: "url goes here",
        data: "data goes here",
        success: function (datasets) {         
            linedata = [];
            pieData = [];

            $.each (datasets, function (objName) {
                if(objName.indexOf('-line') != -1)
                    linedata .push(datasets[objName]);
                        else
                    pieData.push(datasets[objName]);
            });                       

            $.plot(plotarea, linedata , options /* options defined elsewhere */);
            $.plot(piearea, pieData, pieOptions /* pieOptions defined elsewhere */);  
        }
    });

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:

var datasets = {
"usa-line": {
    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]]
},  
"usa-pie": {
    label: "USA",
    data: [[1, TOTAL GOES HERE]]]
},        
"russia-line": {
    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]]
},
"russia-pie": {
    label: "Russia",
    data: [[1, TOTAL GOES HERE]]]
}
};

Then on the callback for the ajax event, I parsed them out into separate datasets for each graph:

$.ajax({
        type: "POST",
        dataType: 'json',
        url: "url goes here",
        data: "data goes here",
        success: function (datasets) {         
            linedata = [];
            pieData = [];

            $.each (datasets, function (objName) {
                if(objName.indexOf('-line') != -1)
                    linedata .push(datasets[objName]);
                        else
                    pieData.push(datasets[objName]);
            });                       

            $.plot(plotarea, linedata , options /* options defined elsewhere */);
            $.plot(piearea, pieData, pieOptions /* pieOptions defined elsewhere */);  
        }
    });
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文