首页 > 解决方案 > Google bar graph from phpmyadmin data

问题描述

I have a user statistic program which counts every online user on my page and I want a statistics in bar form to see/count the number of users every week/month. I tried using google charts and I still don't know how to thoroughly use it but I have seen an example which I tried.

But the problem is I have multiple uvon, (column name of ip addresses that opens the page), dt (column name for the time) and date_current (column name for the date the user opened the page). I can't seem to filter it all out in a single date and count how many users opened it for that day. It only shows the date. Please help

<?php
include("database_config.php");

$query = "SELECT DISTINCT uvon, dt, current_date FROM counter_summary";
$exec = mysqli_query($conn ,$query);

?>

<!DOCTYPE html>
  <head>
    <script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
    <script type="text/javascript">
      google.charts.load('visualization', '1', {packages: ['corechart', 'bar']});
      google.charts.setOnLoadCallback(drawMaterial);

       function drawMaterial() {
       var data = google.visualization.arrayToDataTable([
       ['DATE', 'USERS'],
        <?php 
          while($row = mysqli_fetch_array($exec)){
           echo "['".$row[2]."', ".$row[1]."],"; 
          }
        ?>
        ]);

        var options = {
          title: 'User Statistics',
          bars: 'vertical'
        };

        var material = new google.charts.Bar(document.getElementById('barchart'));
          material.draw(data, options);
        }
    </script>
</head>
<body>
    <div id="barchart" style="width: 100%; height: 40em;"></div>
</body>
</html>

This is the resulting graph: enter image description here

This is the sample data from the database:

enter image description here

标签: htmlgraphchartsgoogle-visualizationbar-chart

解决方案


the following sql will give you the number of times an ip address connected per day...

SELECT current_date, count(*) FROM counter_summary group by current_date

note: I'm not sure if it is current_date as in your code,
or date_current as in the image of your table...

using the above, the rest of the code should work.


推荐阅读