0

I am displaying the customer data on the highchart who will register on the website based on their month and year. I am fetching the response from the server to display. But I am not getting how to inject those data into highchart. Any help/advice greatly appreciated.

Angularjs:

.controller('ctrl',['$scope','$http',function($scope,$http){            
$http({
    url: '//customerinformation',
    method: 'GET'
})
.then(
    function successCallback(response){
        $scope.users = response.data.customers;
    },
    function errorCallback(response){
        console.log('Error:' + response.data);
});

$scope.chartOptions =  {
chart: { type: 'column' },
title: { text: 'Customer Information' },
xAxis: { categories: ['Jan', 'Feb', 'Mar','Apr','May','June','July','Aug','Sep','Oct','Nov','Dec'] },
yAxis: { title: { text: 'No.of customer' } },
series: [{ 
         name: 'customer', 
         data: []  <-- 'Here I need to pass the response data'
      }]
    };
}]);
1

2 Answers 2

2

You could:

  • set series' data before your chart is generated from chartOptions

or

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

Comments

0

You have to push response data into an array then pass that array in your data like this.

.controller('ctrl',['$scope','$http',function($scope,$http){            
$http({
    url: '//customerinformation',
    method: 'GET'
  })
  .then(
    function successCallback(response){
       $scope.users = response.data;
       var CustomersData= [];
       for (var i = 0; i < $scope.users.length; i++) {
          CustomersData.push($scope.users[i].customers);   
       }
    },
    function errorCallback(response){
        console.log('Error:' + response.data);
  });



 $scope.chartOptions =  {
chart: { type: 'column' },
title: { text: 'Customer Information' },
xAxis: { categories: ['Jan', 'Feb', 'Mar','Apr','May','June','July','Aug','Sep','Oct','Nov','Dec'] },
yAxis: { title: { text: 'No.of customer' } },
series: [{ 
         name: 'customer', 
         data: CustomersData  <--- here you get your data.
        }]
      };
  }

Comments

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.