如何解决显示每月mysql记录的图表
我希望显示数据库中我的记录的html5 js月度图表,其中列状态=“销售”(计数等于销售的状态总数)并且日期为当前时间戳。
SELECT * FROM products WHERE status = 'Sale' ORDER BY MONTH(date),id DESC
类似此页面https://phppot.com/demo/creating-dynamic-data-graph-using-php-and-chart-js/的东西,但我希望显示的是像2020年9月这样的月份,而不是2020年10月,然后是计数。
到目前为止我尝试过什么,但是从数据库中什么也没得到
<script type="text/javascript">
// Load the Visualization API and the piechart package.
google.load('visualization','1.0',{'packages':['corechart']});
// Set a callback to run when the Google Visualization API is loaded.
google.setOnLoadCallback(drawChart);
// Callback that creates and populates a data table,// instantiates the pie chart,passes in the data and
// draws it.
function drawChart() {
// Create the data table.
var data = new google.visualization.DataTable();
data.addColumn('string','Topping');
data.addColumn('number','Slices');
data.addRows
([
<?php
$sql = "SELECT * FROM products WHERE status = 'Sale' ORDER BY MONTH(date)";
$result = $db->query($sql);
if ($result->rowCount > 0) {
while ($row = $result->fetch()) {
$a[] = "['".$row["status"]."']";
}
echo implode(',',$a);
}
?>
]);
// Set chart options
var options = {'title':'Monthly sales chart','width':900,'height':500};
// Instantiate and draw our chart,passing in some options.
var chart = new google.visualization.PieChart(document.getElementById('chart_div'));
chart.draw(data,options);
}
</script>
我不知道如何做到这一点,如果有人可以给我看,我将不胜感激?
致谢,非常感谢
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。