Advertisement
Guest User

Untitled

a guest
Apr 27th, 2018
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.34 KB | None | 0 0
  1. https://jtblin.github.io/angular-chart.js/
  2.  
  3. <script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.3.0/Chart.min.js"></script>
  4. <script src="https://cdnjs.cloudflare.com/ajax/libs/angular-chart.js/1.0.3/angular-chart.min.js"></script>
  5.  
  6. <script id="chart.html" type="text/ng-template">
  7. <ion-view title="Home">
  8. <ion-nav-buttons side="left">
  9. <button class="button button-icon button-clear ion-navicon" ng-click="openMenuLeft()"></button>
  10. </ion-nav-buttons>
  11. <ion-content padding="true">
  12. <h1 style="text-align: center;">Charting</h1>
  13. <canvas id="line" class="chart chart-line" chart-data="data"
  14. chart-labels="labels" chart-series="series" chart-options="options"
  15. chart-dataset-override="datasetOverride" chart-click="onClick">
  16. </canvas>
  17. </ion-content>
  18. </ion-view>
  19. </script>
  20.  
  21. app.controller('chartctrl',function($scope,$ionicModal,$http,$ionicSideMenuDelegate) {
  22. $scope.getyearsales = function (user) {
  23. $http.post('http://192.168.43.105/ionicangularjs/script/getyearsales.php', {
  24. //user: user
  25. })
  26. .then(function success(e) {
  27. if(e.data.status=="true")
  28. {
  29. $scope.labels = e.data.year;
  30. $scope.series = ['Series A'];
  31. $scope.data =e.data.amount;
  32. $scope.onClick = function (points, evt) {
  33. console.log(points, evt);
  34. $scope.datasetOverride = [{ yAxisID: 'y-axis-1' }, { yAxisID: 'y-axis-2' }];
  35. $scope.options = {
  36. scales: {
  37. yAxes: [
  38. {
  39. id: 'y-axis-1',
  40. type: 'linear',
  41. display: true,
  42. position: 'left'
  43. },
  44. {
  45. id: 'y-axis-2',
  46. type: 'linear',
  47. display: true,
  48. position: 'right'
  49. }
  50. ]}
  51. };
  52. };
  53. }
  54. else
  55. {
  56. alert("not good");
  57. }
  58. $scope.errors = [];
  59. }, function error(e) {
  60. $scope.errors = e.data.errors;
  61. alert(e);
  62. });
  63. };
  64. $scope.getyearsales();
  65. $scope.openMenuLeft = function() {
  66. $ionicSideMenuDelegate.toggleLeft();
  67. };
  68. });
  69.  
  70. <?php
  71.  
  72. //$data = json_decode(file_get_contents('php://input'), TRUE);
  73.  
  74. //if (isset($data['user'])) {
  75.  
  76. require __DIR__ . '/library.php';
  77. //$username = (isset($data['user']['username']) ? $data['user']['username'] : NULL);
  78. //$password = (isset($data['user']['password']) ? $data['user']['password'] : NULL);
  79.  
  80. // validations
  81. /*if ($username == NULL) {
  82. http_response_code(400);
  83. echo json_encode(['errors' => ["Username Field is required"]]);
  84.  
  85. }
  86. else if($password==NULL){
  87. http_response_code(400);
  88. echo json_encode(['errors' => ["Password Field is required"]]);
  89. }else {
  90.  
  91. */
  92.  
  93. $user = new user();
  94.  
  95. echo $user->getyearsales();
  96. //}
  97. //}
  98.  
  99. ?>
  100. public function getyearsales()
  101. {
  102.  
  103. $query = $this->db->prepare("select year(paymentdate)as year,sum(amount)as amount from payments group by year(paymentdate) ");
  104. $query->execute();
  105. $label = array();
  106. $data=array();
  107. $status=false;
  108. while ($row = $query->fetch(PDO::FETCH_ASSOC))
  109. {
  110. $status=true;
  111. $label[] = $row['year'];
  112. $data[]=$row['amount'];
  113. }
  114. if($status){
  115. return json_encode(array( "status" => "true","year"=>$label, "amount" => $data) );
  116. }
  117. else{
  118. return json_encode(array( "status" => "false") );
  119. }
  120. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement