Presenting my code below:
function gatherDataForGraph(unit, startTs, endTs, startState, endState){
points = [];
console.log('/file/tsDataPoints/'+unit+"?startDate="+startTs+"&endDate="+endTs+"&startState="+startState+"&endState="+endState);
$http.get('/file/tsDataPoints/'+unit+"?startDate="+startTs+"&endDate="+endTs+"&startState="+startState+"&endState="+endState).success(function(data){
for (var i = 0; i < data.length; i++) {
points.push({x:getBasicTimeFromEpoch(data[i].ts), y:data[i].data});
}
return points;
});
}
function displayFileStateLineGraph(unit, startTs, endTs){
gatherDataForGraph(unit, startTs, endTs, 1, 2);
console.log(gatherDataForGraph(unit, startTs, endTs, 1, 2));
var dp1= gatherDataForGraph(unit, startTs, endTs, 1, 2);
var dp2= gatherDataForGraph(unit, startTs, endTs, 2,3);
var dp3 = gatherDataForGraph(unit, startTs, endTs, 3,4);
console.log(dp1);
console.log(dp2);
console.log(dp3);
var chart = new CanvasJS.Chart("chartContainer", {
title: {
text: "Click on legend items to hide/unhide dataseries"
},
legend: {
cursor: "pointer",
itemclick: function (e) {
if (typeof (e.dataSeries.visible) === "undefined" || e.dataSeries.visible) {
e.dataSeries.visible = false;
} else {
e.dataSeries.visible = true;
}
chart.render();
}
},
data: [{
showInLegend: true,
type: "line",
dataPoints: dp1
}, {
showInLegend: true,
type: "line",
dataPoints: dp2
}, {
showInLegend: true,
type: "line",
dataPoints: dp3
}]
});
chart.render();
}
displayFileStateLineGraph("day",1404000000, 1406000000)
Upon running the console.logs, only "undefined" is shown. It's possible that this occurs because the function executes before the JSON call is complete. This issue seems unfamiliar to me.