gpt4 book ai didi

php - 使用php使用mysql数据绘制条形图

转载 作者:行者123 更新时间:2023-11-30 22:06:33 25 4
gpt4 key购买 nike

我正在使用 PHP 作为我的 Web 应用程序后端的脚本语言

<?php

//importing db.php in the includes folder
require("includes/db.php");

$nic = $_POST["NIC"];
$dp = $_POST["DP"];

$date = $_POST["Date"];
$tele = $_POST["Tele"];
$mail = $_POST["Email"];

$sql="INSERT INTO `order` (NIC,DP,Address,Date,Telephone,Email) VALUES ('$nic ','$dp','$address',CURDATE(),'$tele','$mail')";

$result = mysqli_query($db,$sql);
?>

上面的代码涉及客户在下订单时提交表单。我想使用 y 轴的订单数和 x 轴的日期绘制条形图。我怎样才能做到这一点?

最佳答案

谷歌图表 https://developers.google.com/chart/

为您的使用定制的示例代码:

<html>
<head>
<!--Load the AJAX API-->
<script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
<script type="text/javascript">
// Load the Visualization API and the corechart package.
google.charts.load('current', {'packages':['corechart']});
// Set a callback to run when the Google Visualization API is loaded.
google.charts.setOnLoadCallback(drawChart);
// Callback that creates and populates a data table,
// instantiates the bar chart, passes in the data and
// draws it.
function drawChart() {
// Create the data table.
var data = new google.visualization.DataTable();
data.addColumn('string', 'Date');
data.addColumn('number', '# of Orders');
// This is where you will need to pass your SQL data to JavaScript
// I have not included this information, if needed, ask
data.addRows([
['01/02/17',1],
['01/03/17',4],
['01/04/17',9],
['01/05/17',6]
]);
// Set chart options
var options = {
'title':'Orders over Time',
'width':500,
'height':500};
// Instantiate and draw our chart, passing in some options.
var chart = new google.visualization.BarChart(document.getElementById('chart_div'));
chart.draw(data, options);
}
</script>
</head>
<body>
<!--Div that will hold the pie chart-->
<div id="chart_div"></div>
</body>
</html>

JS Fiddle 证明: https://jsfiddle.net/g77pnex5/

关于php - 使用php使用mysql数据绘制条形图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41532807/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com