Currently my Rails controller is returning an array of objects:
var _data = [];
$.getJSON(my_url, function(data) {
$.map(data, function(v) {
_data.push([v.occurrences, v.period])
});
});
console.log(_data) => []
Which when expanded looks like this:
Array[4]
0:Object
1:Object
2:Object
3:Object
And individual objects when expanded look like this:
0:Object
occurrences:1
period:1488499200000
I'm having trouble mapping the initial array of objects in such a way that my final result will be an array of arrays that is comprised of each objects' occurrences value and period value.
The end result should like like:
[[1488499200000, 1],[.., ..],[.., ..],[.., ..]]
So that I can use each array in a chart as an x and y axis point.
I've tried using .map, .each, (for i in ..), etc. with no luck.
EDIT:
This is my chart data:
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"
}
});