html - 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 sample data from the database:
解决方案
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.
推荐阅读
- java - 如何在 IntelliJ Idea 中添加远程 Maven 存储库?
- azure-devops - 如何使用命令行任务将 Azure Pipeline 变量打印到文件?
- debugging - 应用程序的发布版本未请求许可。调试版本正常工作
- sql - 空结果预期实际值
- php - codeigniter 中的分页 URL 问题
- webots - 为什么我不能在我的原型的 BallJoint 节点的“设备”字段中插入 RotationalMotor 节点?
- linux - 如何杀死已使用源执行的脚本?
- python - 在 QDateTimeEdit 中获取当前日期时间
- if-statement - 根据单元格中的值将数据从一张表复制到另一张表
- asp.net-mvc - url.action 不会在 asp.net mvc 中生成 url