我有一个sql表,如下所示:
+------+------------+---------+---------------------+-----------+
| SrNo | BidderName | BidAmt | BidDate | BidTicks |
+------+------------+---------+---------------------+-----------+
| 1 | ARBAAZ | 500.00 | Apr 30 2015 10:27AM | 348854000 |
| 2 | SHEKHAR | 600.00 | Apr 30 2015 10:28AM | 348845000 |
| 3 | SHEKHAR | 800.00 | Apr 30 2015 10:28AM | 348838000 |
+------+------------+---------+---------------------+-----------+
我将这个以JSON格式发送给我的客户端。
我可以通过以下方式获取值:
var data;
Table.forEach(function (field) {
var name = field.BidderName;
var amount = field.BidAmt;
data = "";
});
我正在尝试使用Table
为我的flot图创建一个看起来像这样的对象:
var dataset = [
{
label: "ARBAAZ",
data: [[348854000, 500.00]],//created from [bidticks,bidamt]
color: "#FF0000",
points: { fillColor: "#FF0000", show: true },
lines: { show: true }
},
{
label: "SHEKHAR",
data: [[348845000, 600.00], [48838000, 800.00]],
color: "#0062E3",
points: { fillColor: "#0062E3", show: true },
lines: { show: true }
}
];
任何想法,我怎么能做到这一点?
答案 0 :(得分:0)
我不知道你在json对象中有什么确切的数据结构。 但是,我认为你可以这样做
padding : 15px
现在您可以在数据集对象中使用teamRed和teamBlue。
我假设您确实拥有此BidderName,以区分此行属于蓝队或红队。
答案 1 :(得分:0)
假设你的json数据是var'data',
你可以使用filter
函数
var seen = {};
data = data.filter(function(entry) {
var previous;
// Have we seen this label before?
if (seen.hasOwnProperty(entry.label)) {
// Yes, grab it and add this data to it
previous = seen[entry.label];
var data = [entry.BidTicks, entry.BidAmt] ;
previous.data.push(data);
// Don't keep this entry, we've merged it into the previous one
return false;
}
// entry.data probably isn't an array; make it one for consistency
entry.data = [];
var data = [entry.BidTicks, entry.BidAmt] ;
entry.data.push(data);
//delete the attributes which are not required in final output
delete entry.BidTicks;
delete entry.BidAmt;
// Remember that we've seen it
seen[entry.label] = entry;
// Keep this one, we'll merge any others that match into it
return true;
});
工作小提琴就在这里 - > fiddle to filter the array of objects
关于你的额外属性'color','lines'等,我相信你现在可以将它们带入最终输出。