Here is my code:
function getLineGraphData(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 fileStateLineGraph(unit, startTs, endTs){
getLineGraphData(unit, startTs, endTs, 1, 2);
console.log(getLineGraphData(unit, startTs, endTs, 1, 2));
var dp1= getLineGraphData(unit, startTs, endTs, 1, 2);
var dp2= getLineGraphData(unit, startTs, endTs, 2,3);
var dp3 = getLineGraphData(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: [{
//axisYType:"secondary",
showInLegend: true,
type: "line",
dataPoints: dp1
}, {
showInLegend: true,
type: "line",
dataPoints: dp2
}, {
showInLegend: true,
type: "line",
dataPoints: dp3
}]
});
chart.render();
}
fileStateLineGraph("day",1404000000, 1406000000)
When I run the console.logs just display "undefined." I'm wondering if it is because the function is running before the JSON call is completed, but I've never encountered an error like this.
$httpcome from?