<?php
//We've included ../Includes/FusionCharts.php and ../Includes/DBConn.php, which contains
//functions to help us easily embed the charts and connect to a database.
include("../Includes/FusionCharts.php");
include("../Includes/DBConn.php");
?>
<HTML>
<HEAD>
<TITLE> FusionCharts Free - Database and Drill-Down Example </TITLE>
<SCRIPT LANGUAGE="Javascript" SRC="../../FusionCharts/FusionCharts.js"></SCRIPT>
</HEAD>
<BODY>
<?php
//In this example, we show how to connect FusionCharts to a database.
//For the sake of ease, we've used a MySQL database containing two
//tables.
//Connect to database
$link = connectToDB();
'strXML will be used to store the entire XML document generated
//Fetch all factory records
$strQuery = "select * from Factory_Master"; /*ส่วนอันนี้เราต้องใช้ select * เพื่อให้เลือกข้อมูลทั้งหมดจากตารางก่อนรึเปล่าค่ะ โดยที่เราสาราถเลียนแบบโดยเปลี่ยนเฉพาะชื่อตารางรึป่าวค่ะ*/
$result = mysql_query($strQuery) or die(mysql_error());
//Iterate through each factory
if ($result) {
while($ors = mysql_fetch_array($result)) {
'Now create second query to get details for this factory
$strQuery = "select sum(Quantity) as TotOutput from Factory_Output where FactoryId=" . $ors['FactoryId']; /* ส่วนอันนี้เป็นการ select ส่วนไหน แล้วออกมาเป็นยังไงช่วยอธิบายหน่อยค่ะ*/
$result2 = mysql_query($strQuery) or die(mysql_error());
$ors2 = mysql_fetch_array($result2);
//Generate <set name='..' value='..' link='..' />
//Note that we're setting link as Detailed.php?FactoryId=<<FactoryId>> and then URL Encoding it
$strXML .="<set name='" . $ors['FactoryName'] . "' value='" . $ors2['TotOutput'] . "' link='" . urlencode("Detailed.php?FactoryId=" . $ors['FactoryId']) . "'/>"; /* อธิบายตรงนี้ด้วยนะค่ะว่ามันคือการลิ้งไปไหน หมายถึงตอน dill down รึเปล่าค่ะ*/
//free the resultset
mysql_free_result($result2);
}
}
mysql_close($link);
//Finally, close <chart> element
$strXML .="</chart>";
//Create the chart - Pie 3D Chart with data from $strXML
echo renderChart("../../FusionCharts/FCF_Pie3D.swf", "", $strXML, "FactorySum", 600, 300);
?>
</BODY>
</HTML>
แล้วอันนี้น่าจะเป็นส่วนที่ แสดงรายละเอียด dill down
Creating the detailed data chart page
The page Detailed.php contains the following code:
<?php
//We've included ../Includes/FusionCharts.php and ../Includes/DBConn.php, which contains
//functions to help us easily embed the charts and connect to a database.
include("../Includes/FusionCharts.php");
include("../Includes/DBConn.php");
//a file having a list of colors to be applied to each column (using getFCColor() function)
include("../Includes/FC_Colors.php");
?>
<HTML>
<HEAD>
<TITLE> FusionCharts Free - Database and Drill-Down Example </TITLE>
<SCRIPT LANGUAGE="Javascript" SRC="../../FusionCharts/FusionCharts.js"></SCRIPT>
</HEAD>
<BODY>
<?php
//This page is invoked from Default.php. When the user clicks on a pie
//slice in Default.php, the factory Id is passed to this page. We need
//to get that factory id, get information from database and then show
//a detailed chart.
//First, get the factory Id
//Request the factory Id from Querystring
$FactoryId = $_GET['FactoryId'];
//Connect to database
$link = connectToDB();
//$strXML will be used to store the entire XML document generated
//Generate the chart element string
$strXML = "<graph caption='Factory " & FactoryId &" Output ' subcaption='(In Units)' xAxisName='Date' showValues='1' decimalPrecision='0'>";
//Now, we get the data for that factory
$strQuery = "select * from Factory_Output where FactoryId=" . $FactoryId;
$result = mysql_query($strQuery) or die(mysql_error());
//Iterate through each factory
if ($result) {
while($ors = mysql_fetch_array($result)) {
//Here, we convert date into a more readable form for set name.
$strXML .="<set name='" . datePart("d",$ors['DatePro']) . "/" . datePart("m",$ors['DatePro']) . "' value='" . $ors['Quantity'] . "' color='" . getFCColor() . "'/>";
}
}
mysql_close($link);
//Close <chart> element
$strXML .="</chart>";
//Create the chart - Column 2D Chart with data from $strXML
echo renderChart("../../FusionCharts/FCF_Column2D.swf", "", $strXML, "FactoryDetailed", 600, 300);
?>
</CENTER>
</BODY>
</HTML>