SHARE
TWEET

Google Chart from dynamic data

a guest Nov 4th, 2012 72 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2. include "conn_string.php";
  3. ?>
  4. <html>
  5. <head>
  6. <!--Load the AJAX API-->
  7. <script type="text/javascript" src="jsapi.js"></script>
  8. <script type="text/javascript" src="jquery-1.7.1.min.js"></script>
  9. <script type="text/javascript">
  10.  
  11.   // Load the Visualization API and the package.
  12.   google.load('visualization', '1', {'packages':['corechart']});
  13.  
  14.   // Set a callback to run when the Google Visualization API is loaded.
  15.   google.setOnLoadCallback(drawChart);
  16.   function drawChart() {
  17.         var data = google.visualization.arrayToDataTable([
  18.         ['Time', 'Bots', 'Openresolvers', 'Proxy', 'Malwareurl', 'Phishing', 'Bruteforce', 'Scanners', 'Spam']
  19.         <?php
  20.         $sql_query = "
  21.                 SELECT DATE_FORMAT(time, '%Y-%m-%d') AS time,
  22.                 SUM(CASE WHEN report = 'bots' THEN ipc ELSE 0 END) AS bots,
  23.                 SUM(CASE WHEN report = 'openresolvers' THEN ipc ELSE 0 END) AS openresolvers,
  24.                 SUM(CASE WHEN report = 'proxy' THEN ipc ELSE 0 END) AS proxy,
  25.                 SUM(CASE WHEN report = 'malwareurl' THEN ipc ELSE 0 END) AS malwareurl,
  26.                 SUM(CASE WHEN report = 'phishing' THEN ipc ELSE 0 END) AS phishing,
  27.                 SUM(CASE WHEN report = 'bruteforce' THEN ipc ELSE 0 END) AS bruteforce,
  28.                 SUM(CASE WHEN report = 'scanners' THEN ipc ELSE 0 END) AS scanners,
  29.                 SUM(CASE WHEN report = 'spam' THEN ipc ELSE 0 END) AS spam
  30.                 FROM (
  31.                 SELECT count(ip) AS ipc, report, DATE(time) as time
  32.                 FROM  asn_data
  33.                 GROUP BY report, DATE(time)) i
  34.                 GROUP BY time;
  35. ";
  36.  
  37.         $result = mysql_query($sql_query);
  38.  
  39.         while($row = mysql_fetch_assoc($result)){
  40.                 echo ",['{$row['time']}',{$row['bots']},{$row['openresolvers']},{$row['proxy']},{$row['malwareurl']},{$row['phishing']},{$row['br
  41. uteforce']},{$row['scanners']},{$row['spam']}]\r\n";
  42.         }
  43.         ?>
  44.         ]);
  45.  
  46. var options = {
  47.           title : 'Category Counts',
  48.           vAxis: {title: "Counts"},
  49.           hAxis: {title: "Date"},
  50.           seriesType: "bars",
  51.           series: {5: {type: "line"}}
  52.         };
  53.        
  54.   var chart = new google.visualization.ComboChart(document.getElementById('chart_div'));
  55.   chart.draw(data, options);
  56.  }
  57.  
  58. </script>
  59. </head>
  60. <body>
  61. <br>
  62. <div id="chart_div"></div>
  63. </body>
  64. </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