2

我的json数据:

{
   "d":[
      {
         "__type":"DashBoardControl.Info.DashBoardSettingInfo",
         "VisitTime":"183",
         "Browser":"Firefox"
      },
      {
         "__type":"DashBoardControl.Info.DashBoardSettingInfo",
         "VisitTime":"28",
         "Browser":"Chrome"

      },
      {
         "__type":"DashBoardControl.Info.DashBoardSettingInfo",
         "VisitTime":"2",
         "Browser":"IE"
      },
      {
         "__type":"DashBoardControl.Info.DashBoardSettingInfo",
         "VisitTime":"1",
         "Browser":"Opera"
      }
   ]
}

我尝试像这样在二维数组中制作这些数据。但我失败了。

                        var BrowserWiseVisit = [];
                        if (msg.d.length > 0) {
                            var arrVisit = [];
                            $.each(msg.d, function (index, item) {

                                arrVisit = [];
                                arrVisit.push(item.Browser);
                                arrVisit.push(item.VisitTime);
                                BrowserWiseVisit.push(arrVisit);

                            });


                        }

我想要这种格式的数据

[['Firefox', 183], ['Chrome', 28], ['IE', 2], ['Opera', 1]];

使用http://www.jqplot.com/这个插件。谢谢。

4

3 回答 3

3

看来你做得对http://www.jqplot.com/

你想要数据 [['Firefox', 183], ['Chrome', 28], ['IE', 2], ['Opera', 1]];

只需在您的 js 中将 visitTime 数据解析为 int。
这是演示:http: //jsfiddle.net/Simplybj/HCNL5/

var BrowserWiseVisit = [];
                        if (msg.d.length > 0) {
                            var arrVisit = [];
                            $.each(msg.d, function (index, item) {

                                arrVisit = [];
                                arrVisit.push(item.Browser);
                                arrVisit.push(parseInt(item.VisitTime));
                                BrowserWiseVisit.push(arrVisit);

                            });
                    }
于 2012-10-09T06:55:55.770 回答
0

试试这个:

var BrowserWiseVisit = [];
if (msg.d.length > 0) {
   var arrVisit = [];
   $.each(msg.d, function (index, item) {
      arrVisit = [item.Browser,item.VisitTime];
      BrowserWiseVisit.push(arrVisit);
   });
}
于 2012-10-09T06:42:08.877 回答
-2

这应该这样做:

var sampleData = [], results = d;
for (var i = 0, len = results.length; i < len; i++) {
    var result = results[i];
    sampleData.push({ browser: result.Browser, visitTime: result.VisitTime});
}
于 2012-10-09T06:23:48.227 回答