0

I need to push the http url from the json i encoded using php into data.push in the following code. For now i have used a random math array. How do i push a json http url:

http://maricoih.e21designs.com/services/productionhourlyscopra

into the data.push() in the following code:

app.controller('MainCtrl', ['$scope',

  function($scope) {

    $scope.tasksRunData = [{
      label:"ope",
      data: []
    },{
      label:"lma",
      data: []
    },{
      label:"lmb",
      data: []
    }];

    $scope.tasksRunChartOptions = {
      legend: {
        show: true
      },
      lines: {
        show: true
      }
    };

    // some data
    for (var i = 1; i < 100; i += 1) {
      $scope.tasksRunData[0].data.push([i, Math.random(i) * 100]);
    }
    for (var i = 1; i < 100; i += 1) {
      $scope.tasksRunData[1].data.push([i, Math.random(i) * 45]);
    }
for (var i = 1; i < 100; i += 1) {
      $scope.tasksRunData[2].data.push([i, Math.random(i) * 65]);
    }
    $scope.reportTasksRunRange = {
      min: 1,
      max: 100,
      floor: 1,
      ceil: 100,
      step: 1
    };
  }
]); 

Go to the plunkr link to follow the full code.

1
  • $http.get(url).success(function(data){})? Commented Mar 23, 2015 at 15:56

2 Answers 2

2

You need to use $http from Angular.js to make a request to your url. Once you get the data back, you can just set the data object in your tasksRunData to the result of your $http call.

https://docs.angularjs.org/api/ng/service/$http

$http.get('http://maricoih.e21designs.com/services/productionhourlyscopra')
    .success(function(data) {
        // do stuff with data from the request here
    })

I couldn't get a working example on plunkr because of cross-orgin restrictions but this should get you started in the right direction.

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

Comments

0

You should read $http documentation. Simply get your data with $http.get() then treats the way you need.

$http.get('http://maricoih.e21designs.com/services/productionhourlyscopra').then(
  function (data) {
      console.log('data retrieved', data);
      //Your code here
  }, function (error) {
      console.error(error);
  });

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.