Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- https://jtblin.github.io/angular-chart.js/
- <script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.3.0/Chart.min.js"></script>
- <script src="https://cdnjs.cloudflare.com/ajax/libs/angular-chart.js/1.0.3/angular-chart.min.js"></script>
- <script id="chart.html" type="text/ng-template">
- <ion-view title="Home">
- <ion-nav-buttons side="left">
- <button class="button button-icon button-clear ion-navicon" ng-click="openMenuLeft()"></button>
- </ion-nav-buttons>
- <ion-content padding="true">
- <h1 style="text-align: center;">Charting</h1>
- <canvas id="line" class="chart chart-line" chart-data="data"
- chart-labels="labels" chart-series="series" chart-options="options"
- chart-dataset-override="datasetOverride" chart-click="onClick">
- </canvas>
- </ion-content>
- </ion-view>
- </script>
- app.controller('chartctrl',function($scope,$ionicModal,$http,$ionicSideMenuDelegate) {
- $scope.getyearsales = function (user) {
- $http.post('http://192.168.43.105/ionicangularjs/script/getyearsales.php', {
- //user: user
- })
- .then(function success(e) {
- if(e.data.status=="true")
- {
- $scope.labels = e.data.year;
- $scope.series = ['Series A'];
- $scope.data =e.data.amount;
- $scope.onClick = function (points, evt) {
- console.log(points, evt);
- $scope.datasetOverride = [{ yAxisID: 'y-axis-1' }, { yAxisID: 'y-axis-2' }];
- $scope.options = {
- scales: {
- yAxes: [
- {
- id: 'y-axis-1',
- type: 'linear',
- display: true,
- position: 'left'
- },
- {
- id: 'y-axis-2',
- type: 'linear',
- display: true,
- position: 'right'
- }
- ]}
- };
- };
- }
- else
- {
- alert("not good");
- }
- $scope.errors = [];
- }, function error(e) {
- $scope.errors = e.data.errors;
- alert(e);
- });
- };
- $scope.getyearsales();
- $scope.openMenuLeft = function() {
- $ionicSideMenuDelegate.toggleLeft();
- };
- });
- <?php
- //$data = json_decode(file_get_contents('php://input'), TRUE);
- //if (isset($data['user'])) {
- require __DIR__ . '/library.php';
- //$username = (isset($data['user']['username']) ? $data['user']['username'] : NULL);
- //$password = (isset($data['user']['password']) ? $data['user']['password'] : NULL);
- // validations
- /*if ($username == NULL) {
- http_response_code(400);
- echo json_encode(['errors' => ["Username Field is required"]]);
- }
- else if($password==NULL){
- http_response_code(400);
- echo json_encode(['errors' => ["Password Field is required"]]);
- }else {
- */
- $user = new user();
- echo $user->getyearsales();
- //}
- //}
- ?>
- public function getyearsales()
- {
- $query = $this->db->prepare("select year(paymentdate)as year,sum(amount)as amount from payments group by year(paymentdate) ");
- $query->execute();
- $label = array();
- $data=array();
- $status=false;
- while ($row = $query->fetch(PDO::FETCH_ASSOC))
- {
- $status=true;
- $label[] = $row['year'];
- $data[]=$row['amount'];
- }
- if($status){
- return json_encode(array( "status" => "true","year"=>$label, "amount" => $data) );
- }
- else{
- return json_encode(array( "status" => "false") );
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement