Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
=========================================================DataService.js===================================================================
app.factory('DataService' , function($http,$rootScope){
return {
getGraphData : function(){
var uid = $rootScope.user.id;
var graphdatas = $http.get('/smartfarm/getalldata/'+uid);
return graphdatas;
}
};
});
==============================================================Chart.js=================================================================
'use strict';
app.controller('FlotChartDemoCtrl', FlotChartDemoCtrl);
function FlotChartDemoCtrl($scope,$http,$rootScope,$state,$auth,toaster,$timeout,$window,DataService,$interval)
{
$auth.getToken();
var uid = $rootScope.user.id;
getGraphData();
function getGraphData(){
DataService.getGraphData().then(function(response){
$scope.humidity = response.data[response.data.length - 1].humidity;
$scope.temp = [];
for (var j = 1; j < response.data.length; ++j)
{
$scope.temp.push([j , angular.fromJson(response.data[j].temperature) ] );
}
$scope.light = [];
for (var j = 1; j < response.data.length; ++j)
{
$scope.light.push([j , angular.fromJson(response.data[j].light) ] );
}
$scope.ph = [];
for (var j = 1; j < response.data.length; ++j)
{
$scope.ph.push([j , angular.fromJson(response.data[j].ph) ] );
}
$scope.moisture = [];
for (var j = 1; j < response.data.length; ++j)
{
$scope.moisture.push([j , angular.fromJson(response.data[j].moisture) ] );
}
$scope.d = [ [1,6.5],[2,6.5],[3,7],[4,8],[5,7.5],[6,7],[7,6.8],[8,7],[9,7.2],[10,7],[11,6.8],[12,7] ];
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.