Does anyone know how to loop through JSON data inside a variable? For example:
var data = {
$.each(data, function(i, item) {
console.log(data[i].PageName);
});
labels: [dateLoop],
datasets: [{
}]
};
The code above didn't work for me. I need to loop inside that variable because I have filters for buyers and date ranges. For instance, if I select 3 buyers and a date range from January 2016 to May 2016, the data will show each buyer's values within that date range. Here is an example of the JSON data:
data [Buyer 1] : ["167404", "129770", "113598", "127301", "156868", "634789", "242188", "166312", "169418"];
data [Buyer 2] : ["9580", "22250", "3500", "5558", "254556", "268500", "77750", "69850", "55"];
I'm trying to figure out how to loop inside the variable. Apologies for my poor language.
To provide a clearer explanation, let's say I choose 2 buyers - Buyer A (Json["data"][0]) and Buyer B (Json["data"][1]). Each buyer has values ordered by month. If I pick January and May, it should show values like "222," "555." The code could look something like this:
var data = {
labels: [dateLoop], #ignore this
datasets: [{ label : (Json["data"][0])
fillColor: "rgba(220,220,220,0.2)",
strokeColor: "rgba(220,220,220,1)",
pointColor: "rgba(220,220,220,1)",
pointStrokeColor: "#fff",
pointHighlightFill: "#fff",
pointHighlightStroke: "rgba(220,220,220,1)",
data: [(value orderby month in Json["data"][0]]
},
{ label : (Json["data"][1])
fillColor: "rgba(220,220,220,0.2)",
strokeColor: "rgba(220,220,220,1)",
pointColor: "rgba(220,220,220,1)",
pointStrokeColor: "#fff",
pointHighlightFill: "#fff",
pointHighlightStroke: "rgba(220,220,220,1)",
data: [(value orderby month in Json["data"][1]]
}
]
};
That's what I'm aiming for, but using 'each' is causing errors. :/