|
 |
|
PHP ดึงข้อมูลจาก MySQL แสดงบน FusionChart ไม่ได้ครับ |
|
 |
|
|
 |
 |
|
ผมต้องการดึงข้อมูลจาก MySQL มาแสดงบนกราฟของ FusionChart ครับ แต่ FusionChart เวอร์ชั่นใหม่ต่างกับเวอร์ชั่นเดิมมากเลย ไม่มีโฟลเดอร์ Code แบบเวอร์ชั่นเดิมครับ ผมดูตัวอย่างจากเว็บนี้ http://www.fusioncharts.com/getting-started/ แสดงกราฟได้แต่ไม่ได้ดึงข้อมูลจาก MySQL ผมก็เลยลองใช้ json ดึงมาดู แต่มันก็ไม่แสดงกราฟครับ
ผมใช้ echo $json_data=json_encode($json); ได้ผลลัพธ์ดังนี้ครับ
Code
[{"CustomerID":"C001","Budget":"1000000"},{"CustomerID":"C002","Budget":"2000000"},{"CustomerID":"C003","Budget":"3000000"},{"CustomerID":"C004","Budget":"4000000"}]
ผมก็เลยแก้ไขโค้ดเป็นแบบนี้ครับ แต่มันไม่แสดงกราฟครับ จากที่ดูตัวอย่างผมว่าที่ json แสดงออกมากับในตัวอย่างไม่ได้ต่างกันมากนะครับ ไม่ทราบว่าต้องทำยังไงครับ
Code
<html>
<head>
<title>My first chart using FusionCharts Suite XT</title>
<script type="text/javascript" src="fusioncharts/fusioncharts.js"></script>
<script type="text/javascript" src="fusioncharts/themes/fusioncharts.theme.zune.js"></script>
<script type="text/javascript">
FusionCharts.ready(function(){
var revenueChart = new FusionCharts({
type: "column2d",
renderAt: "chartContainer",
width: "500",
height: "300",
dataFormat: "json",
dataSource: {
"chart": {
"caption": "Monthly revenue for last year",
"subCaption": "Harry's SuperMart",
"xAxisName": "Month",
"yAxisName": "Revenues (In USD)",
"theme": "zune"
},
<?
$objConnect = mysql_connect("localhost","root","1234") or die("Error Connect to Database");
$objDB = mysql_select_db("customer");
$strSQL = "SELECT CustomerID, Budget FROM customer";
$objQuery = mysql_query($strSQL) or die ("Error Query [".$strSQL."]");
$json = array();
while($r=mysql_fetch_assoc($objQuery)){
$json[] = $r;
}
//Display the JSON data
echo $json_data=json_encode($json);
mysql_close($objConnect);
?>
});
revenueChart.render("chartContainer");
});
</script>
</head>
<body>
<div id="chartContainer">FusionCharts XT will load here!</div>
<?
$objConnect = mysql_connect("localhost","root","1234") or die("Error Connect to Database");
$objDB = mysql_select_db("customer");
$strSQL = "SELECT CustomerID, Budget FROM customer";
$objQuery = mysql_query($strSQL) or die ("Error Query [".$strSQL."]");
$json = array();
while($r=mysql_fetch_assoc($objQuery)){
$json[] = $r;
}
//Display the JSON data
echo $json_data=json_encode($json);
mysql_close($objConnect);
?>
</body>
</html>
Tag : PHP, MySQL, JavaScript

|
|
 |
 |
 |
 |
Date :
2014-08-07 23:23:45 |
By :
mmc01 |
View :
1392 |
Reply :
2 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ใช้ ajax ในการดึงค่า json มาแสดงครับ
|
 |
 |
 |
 |
Date :
2014-08-08 01:26:57 |
By :
yamcrocodile |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 01
|