目前我的Rails控制器返回對象的數組:關閉對象的jQuery的數組到一個新的數組
var _data = [];
$.getJSON(my_url, function(data) {
$.map(data, function(v) {
_data.push([v.occurrences, v.period])
});
});
console.log(_data) => []
,當擴張看起來是這樣的:
Array[4]
0:Object
1:Object
2:Object
3:Object
而單個對象擴大時的樣子像這樣:
0:Object
occurrences:1
period:1488499200000
我遇到了麻煩映射的初始數組對象的方式,我的fi最終結果將是由每個對象的出現值和週期值的數組的數組。
最終結果謹像:
[[1488499200000, 1],[.., ..],[.., ..],[.., ..]]
所以,我可以使用每個陣列的圖表中爲x軸和y軸點。
我使用.MAP,。每次,試圖(爲我..)等,沒有運氣。
編輯:
這是我的圖表數據:
var line_data2 = {
data: _data,
color: "#00c0ef"
};
$.plot("#myGraph", [line_data2], {
grid: {
hoverable: true,
borderColor: "#f3f3f3",
borderWidth: 1,
tickColor: "#f3f3f3"
},
series: {
shadowSize: 0,
lines: {
show: true
},
points: {
show: true
}
},
lines: {
fill: false,
color: ["#3c8dbc", "#f56954"]
},
yaxis: {
show: true,
},
xaxis: {
show: true,
mode: "time",
timeformat: "%m/%d/%Y"
}
});
的[我如何返回從一個異步調用的響應?(可能的複製http://stackoverflow.com/questions/14220321/how-do-i-return-the-response-from-an -asynchronous呼叫) – Dhiraj
@Dhiraj這不是它 – asalgan
你的代碼是正確的,我已經嘗試[的jsfiddle(https://jsfiddle.net/84p5kevk/),我能看到'上圖功能_data'用? –