SHARE
TWEET

JS - GOOGLE CHART PHP MYSQL

AMONRA75 May 21st, 2019 (edited) 127 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2.  
  3.  
  4. require 'connect.php';
  5.  
  6. ?>
  7.  
  8.        
  9.  
  10.  
  11.  
  12. <html>
  13.   <head>
  14.     <script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
  15.    
  16.     <script type="text/javascript">
  17.       google.charts.load('current', {'packages':['bar']});
  18.       google.charts.setOnLoadCallback(drawChart);
  19.  
  20.       function drawChart() {
  21.         var data = google.visualization.arrayToDataTable([
  22.        
  23.         ['mese','somma'],
  24.            
  25.            
  26.           <?php  
  27.  
  28.  
  29.        
  30.   $query = "SELECT DATE_FORMAT(timeof, '%m-%Y') AS mese, SUM(totsell-cost) AS somma FROM position WHERE DATE_FORMAT(timeof, '%m-%Y') GROUP BY mese";
  31.   $exec = mysqli_query($conn,$query);
  32.   while($row = mysqli_fetch_array($exec)){
  33.   echo "['".$row['mese']."',".$row['somma']."],";
  34. }
  35.          
  36.          
  37.          
  38.          
  39.           ?>
  40.            
  41.            
  42.        
  43.        
  44.             ]);
  45.            
  46.          
  47.        
  48.  
  49.         var options = {
  50.  
  51.           title: '',
  52.          
  53.           colors: ['grey', '#618C5B', '#DB3D52', '#993333'],
  54.           legend: {position: 'none'},
  55.           width: 300,
  56.           height: 200,
  57.  
  58.           bar: {groupWidth: '20px'},
  59.  
  60.           backgroundColor: 'transparent'
  61.  
  62.  
  63.        
  64.         };
  65.  
  66.         var chart = new google.charts.Bar(document.getElementById('columnchart_material'));
  67.  
  68.         chart.draw(data, google.charts.Bar.convertOptions(options));
  69.       }
  70.     </script>
  71.   </head>
  72.   <body>
  73.     <div id="columnchart_material" style="width: 940px; height: 170px;"></div>
  74.   </body>
  75. </html>
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top