|
 |
|
.php ต้องการสอบถามเกี่ยวกับการสร้างกราฟโดยดึงข้อมูลจากฐานข้อมูล |
|
 |
|
|
 |
 |
|
ผมอยากถามเกี่ยว PHP Code ที่ใช้สร้างกราฟต่อไปนี้ครับว่า ข้อมูลแกนนอนนั้นสามารถเปลี่ยนจากข้อมูล timestamp ไปเป็นข้อมูล varchar ได้รึเปล่าครับ แล้วก็สามารถเพิ่มข้อมูลให้เป็นกราฟที่มีมากกว่า 2เส้น ได้รึเปล่า
หากมีผู้เชี่ยวชาญคนใดสามารถแก้ไขได้ก็ขอความกรุณาด้วยครับ , ขอบคุณครับ       
Code (PHP)
<?php
//connect Database mysql
$host = "xxxxxxxxxxxxx";
$user = "xxxxxxxxxxxxx";
$pwd = "xxxxxxxxxxxxx";
$db = "xxxxxxxxxxxxx";
global $link;
$link = mysql_connect($host,$user,$pwd) or die ("Could not connect to MySQL");
mysql_query("SET NAMES UTF8",$link);
mysql_select_db($db,$link) or die ("Could not select $db database");
//.connect database
//sql สำหรับดึงข้อมูล
$sql = "SELECT unix_timestamp(service.visitdate)*1000 AS date, service.cvno AS val FROM service GROUP BY date";
//จบ sql
$result = mysql_query($sql);
?>
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Highstock Example</title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
<script src="http://code.highcharts.com/stock/highstock.js"></script>
<script src="http://code.highcharts.com/stock/modules/exporting.js"></script>
<script type="text/javascript">
$(function() {
// Create the chart
$('#container').highcharts('StockChart', {
rangeSelector : {
selected : 1
},
title : {
text : 'จำนวนผู้รับบริการ'
},
yAxis: {
min: 0,
},
series : [{
name : 'จำนวนผู้รับบริการ(ครั้ง)',
data : [<?php while($row=mysql_fetch_array($result)) {
$val = $row[val];
$datestamp = $row[date];
$sss = "[". $datestamp.",".$val."],";
echo $sss;
} ?>],
tooltip: {
valueDecimals: 2
}
}]
});
});
</script>
</head>
<body>
<div id="container" style="height: 500px; min-width: 500px"></div>
</body>
</html>
Tag : PHP, MySQL, HTML, jQuery, Google Chrome

|
|
 |
 |
 |
 |
Date :
2020-06-11 16:47:23 |
By :
deatinyfrank |
View :
705 |
Reply :
4 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
แปลงสองชั้น
1. varchar > date STR_TO_DATE() *
2. date > unix_timestamp UNIX_TIMESTAMP()
Code (SQL)
SELECT UNIX_TIMESTAMP(STR_TO_DATE('Apr 15 2012 12:00AM', '%M %d %Y %h:%i%p')) AS ...
* STR_TO_DATE ต้องใส่ format
|
 |
 |
 |
 |
Date :
2020-06-11 22:37:12 |
By :
PhrayaDev |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 03
|