วันอังคารที่ 27 กันยายน พ.ศ. 2554

Fusion Chart ZoomLine การสร้างกราฟแบบ ซูม-ซูม



file 1 :

<?php
//header('content-type:text/xml'); //php ส่ง Head เป็น XML
require_once('Connections/connWater.php');
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
  $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;

  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;  
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}
}

mysql_select_db($database_connWater, $connWater);
$query_rs_tu01 = "SELECT * FROM powerplant ORDER BY dates ASC";
$rs_tu01 = mysql_query($query_rs_tu01, $connWater) or die(mysql_error());
$row_rs_tu01 = mysql_fetch_assoc($rs_tu01);
$totalRows_rs_tu01 = mysql_num_rows($rs_tu01);

do {
$data0[] = $row_rs_tu01['dates'];
$data1[] = $row_rs_tu01['inflows'];
$data2[] = $row_rs_tu01['releases'];
$data3[] = $row_rs_tu01['spillway'];
$data4[] = $row_rs_tu01['tot_release'];
 } while ($row_rs_tu01 = mysql_fetch_assoc($rs_tu01));

$xml = "<?xml version='1.0' encoding='UTF-8'?>\r\n";
$xml.= "<chart compactDataMode=\"1\" dataSeparator=\"|\" paletteThemeColor=\"5D57A5\" divLineColor=\"5D57A5\" divLineAlpha=\"40\" vDivLineAlpha=\"40\"
dynamicAxis=\"1\">\r\n";
$xml.= "<categories>\r\n";
for($i=0;$i<$totalRows_rs_tu01;$i++){
$xml.= $data0[$i]."|"; }
$xml.= "</categories>\r\n";
$xml.= "<dataset seriesName=\"Inflows\" color='#0000FF'>";
for($i=0;$i<$totalRows_rs_tu01;$i++){
$xml.= $data1[$i]."|"; }
$xml.= "</dataset>\r\n";
$xml.= "<dataset seriesName=\"Release\" color='#FFFF00'>";
for($i=0;$i<$totalRows_rs_tu01;$i++){
$xml.= $data2[$i]."|"; }
$xml.= "</dataset>\r\n";
$xml.= "<dataset seriesName=\"Spillway\" color='#FF0000'>";
for($i=0;$i<$totalRows_rs_tu01;$i++){
$xml.= $data3[$i]."|"; }
$xml.= "</dataset>\r\n";
$xml.= "<dataset seriesName=\"Release+Spillway\" color='#FF00FF'>";
for($i=0;$i<$totalRows_rs_tu01;$i++){
$xml.= $data4[$i]."|"; }
$xml.= "</dataset>\r\n";
$xml.= "</chart>";
// Write the XML code to the file mcm_results.xml
//$file= fopen("ammap_data_select.xml", "w");
$file= fopen("zoomline3s.xml", "w");
fwrite($file, $xml);
fclose($file);
mysql_free_result($rs_tu01);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>ระบบโทรมาตรเพื่อการบริหารจัดการน้ำ แม่น้ำน่าน กฟผ. เขื่อนสิริกิติ์</title>
<style type="text/css">
body,td,th {
font-family: Tahoma, "MS Sans Serif";
font-size: 12px;
text-align: center;
}
.mytable {
background-color: #CFC;
}
.header {
font-family: Tahoma, "MS Sans Serif";
font-size: 14px;
font-weight: bold;
}
body {
background-color: #FFC;
}
</style>
</head>

<body topmargin="0">
<a href="zoomline3s.xml">อ่าน XML</a><br />
<br />

<iframe SRC='fusion_zoom1.htm' width="1000" height="620" vspace="0" hspace="0" scrolling="no" frameborder="0">Sorry, your browser doesn't support IFRAMEs</iframe>

</body>
</html>





File 2: fusion_zoom1.htm


<?xml version="1.0" encoding="utf-8"?>
<html xmlns="http://www.w3.org/1999/xhtml">
 <head>
        <title>ZoomLine Chart31</title>
        <script language="JavaScript" src="../FusionCharts32/Charts/FusionCharts.js"></script>
    </head>
<body>
<div id="chartdiv" align="center">
        FusionCharts. </div>
      <script type="text/javascript">
    var chart = new FusionCharts("../FusionCharts32/Charts/ZoomLine.swf", "ChartId", "950", "600", "0", "1");
  chart.setXMLUrl("ZoomLine3s.xml");
  chart.render("chartdiv");
</script>

     </body>
 </html>

ไม่มีความคิดเห็น:

แสดงความคิดเห็น