วันศุกร์ที่ 23 กันยายน พ.ศ. 2554

Fusioncharts Scroll2d from Database


<?php require_once('Connections/mycon_data_connWater.php');

    include("../FusionCharts/Includes/FusionCharts.php");?>
<?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_rsChart = "SELECT * FROM show_data_tu01";
$rsChart = mysql_query($query_rsChart, $connWater) or die(mysql_error());
$row_rsChart = mysql_fetch_assoc($rsChart);
$totalRows_rsChart = mysql_num_rows($rsChart);
?>
<!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=windows-874" />
<title>Untitled Document</title>
<SCRIPT LANGUAGE="Javascript" SRC="../FusionCharts/FusionCharts.js"></SCRIPT>
<style type="text/css">
<!--
body {
font-family: Arial, Helvetica, sans-serif;
font-size: 12px;
}
-->
</style>
</HEAD>
<BODY>

<CENTER>
  <?php do {
$dt[] = $row_rsChart['dates'];
$dt1[] = $row_rsChart['volumes'];
$dt2[] = $row_rsChart['waters'];
         } while ($row_rsChart = mysql_fetch_assoc($rsChart));
$data1 = array($dt);
$data2 = array($dt1);
$data3 = array($dt2);  
 
for($i=0;$i<$totalRows_rsChart;$i++)
  {
$datas[$i][1] = $dt[$i] ;
$datas[$i][2] = $dt1[$i] ;
$datas[$i][3] = $dt2[$i] ;
}
   ?>

<h2>FusionCharts Examples</h2>
<h4>Basic example using dataXML method (with XML data hard-coded in PHP page itself)</h4>
<p>If you view the source of this page, you'll see that the XML data is present in this same page (inside HTML code). We're not calling any external XML (or script) files to serve XML data. dataXML method is ideal when you've to plot small amounts of data.<br />
</p>
<?php
//$strXML = "chart caption='Monthly Sales Summary' subcaption='For the year 2006' xAxisName='Month' yAxisName='Sales' yAxisMinValue='15000'  numberPrefix='$' showValues='0' alternateHGridColor='FCB541' alternateHGridAlpha='20' divLineColor='FCB541' divLineAlpha='50' canvasBorderColor='666666' baseFontColor='666666' lineColor='FCB541'>";

     // $strXML = "<chart caption='Sales by Product' numberPrefix='' formatNumberScale='1' rotateValues='1' placeValuesInside='1' decimals='0' >";
$strXML = "<chart caption='Site hits per hour' subCaption='In Thousands' numdivlines='9' lineThickness='2' showValues='1' anchorRadius='3' anchorBgAlpha='50' showAlternateVGridColor='0' numVisiblePlot='12' animation='1'  alternateHGridColor='00FF00' alternateHGridAlpha='20' divLineColor='FCB541' divLineAlpha='50' canvasBorderColor='666666' baseFontColor='666666' lineColor='FCB541'>";
           //Initialize <categories> element - necessary to generate a multi-series chart
           $strCategories = "<categories>";
          //Initiate <dataset> elements
           $strDataCurr = "<dataset seriesName='ปริมาณน้ำ' color='800080' anchorBorderColor='800080'>";
           $strDataCurr1 = "<dataset seriesName='ระดับน้ำ' color='FF8040' anchorBorderColor='FF8040'>";
           //Iterate through the data
           //Append <category label='...' /> to strCategories
   foreach ($datas as $arSubData) {
           $strCategories .= "<category label='" . $arSubData[1] . "' />";
           //Add <set value='...' /> to both the datasets
           $strDataCurr .= "<set value='" . $arSubData[2] . "' />";
 $strDataCurr1 .= "<set value='" . $arSubData[3] . "' />";
           //Close <categories> element }
            }    
      $strCategories .= "</categories>";
           //Close <dataset> elements
           $strDataCurr .= "</dataset>";
  $strDataCurr1 .= "</dataset>";
           //Assemble the entire XML now
           $strXML .= $strCategories . $strDataCurr . $strDataCurr1  . "</chart>";
   //Create the chart - Column 2D Chart with data from strXML
    echo renderChart("../FusionCharts/Charts/ScrollArea2D.swf", "", $strXML, "FactoryDetailed", 600, 300, false, false);

mysql_free_result($rsChart);
?>

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

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