1

hey everyone am trying to display a chart of a data that am getting it from an API The Output of the API is List<String> not Json ; here's my js file

google.load('visualization', '1', {
packages: ['corechart'] 
});


app.controller("chartController",function($scope,$http)
    {


$http.get("/idcountcisco")
.success(function(data){

    $scope.cisco=data
    console.log($scope.cisco)


})


    $http.get("/idcountlog4j")
.success(function(data){

    $scope.log4j=data
    console.log($scope.log4j)


})
    $http.get("/idcountwin")
.success(function(data){

    $scope.windows=data
    console.log($scope.windows)


})



if (($scope.cisco=!undefined )&&($scope.log4j=!undefined )&&($scope.windows=!undefined ))

{

var data = google.visualization.arrayToDataTable([
                                                  ['type', 'Qs' ],
                                                  ['cisco', $scope.cisco],
                                                  ['lo4j',$scope.log4j ],
                                                 ['windows',$scope.windows],
   ]);
var options = {
  title: 'Statistiques'
 };
 var chart = new    google.visualization.PieChart(document.getElementById('chartdiv'));

 chart.draw(data, options);

}

});

okey so in console.log am getting this

$scope.cisco=18
$scope.log4j=45
$scope.windows=15

and am having a chart like this , it's like it's not getting the real value when i tried to understand it after the if all my vars value become equal to true

thanks for any help

enter image description here

1 Answer 1

2

Actually you have two issues in your code:

First issue:

not equal is != not =!, in your code you did $scope.cisco=!undefined this will set true to $scope.cisco that is '!undefined', so this is the first problem where your if condition will be true all the time.

it should be if (($scope.cisco!=undefined )&&($scope.log4j!=undefined )&&($scope.windows!=undefined )) or you can use angular.isUndefined for checking the variable is undefined or not.

Second issue:

As you are doing all $http.get in your controller and before all the $http.get executes you are going to drawing chart, $http.get will give you the promise where it runs in async mode so you don't have granted that when your are going to your if condition all the get request are executed completely , so this is your second problem , you need to fix it.

Sign up to request clarification or add additional context in comments.

3 Comments

but am using that condition so it can timeout until it gets the data
but your conditions are not correct , it should be != not =!
yes i fixed it thank you , just asking with that condition that i just fixed , if i wont include promises it should work right ?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.