<?php
//connect.php
//function random
function rgb2hex($r, $g, $b, $uppercase=false, $shorten=false)
{
// The output
$out = "";
// If shorten should be attempted, determine if it is even possible
if ($shorten && ($r + $g + $b) % 17 !== 0) $shorten = false;
// Red, green and blue as color
foreach (array($r, $g, $b) as $c)
{
// The HEX equivalent
$hex = base_convert($c, 10, 16);
// If it should be shortened, and if it is possible, then
// only grab the first HEX character
if ($shorten) $out .= $hex[0];
// Otherwise add the full HEX value (if the decimal color
// is below 16 then we have to prepend a 0 to it)
else $out .= ($c < 16) ? ("0".$hex) : $hex;
}
// Package and away we go!
return $uppercase ? strtoupper($out) : $out;
}
//โค๊ด random สีกราฟ
echo "<graph numdivlines='4' lineThickness='3' showValues='0' numVDivLines='10' formatNumberScale='2' rotateNames='1' decimalPrecision='2' anchorRadius='2' anchorBgAlpha='0' numberPrefix='' divLineAlpha='30' showAlternateHGridColor='1' yAxisMinValue='800000' shadowAlpha='50' >";
echo "<categories>";
// เดือน 12 เดือน ----->>
$aa="2014";//ค่านี้อยากให้ให้ส่งมาจาก หน้า test.php
$strQueryData = "SELECT DISTINCT order_date, SUM( size_new ) AS V_TOTAL_new, DATE_FORMAT( order_date, '%$aa-%m' ) AS Mydate, check_status, order_generation AS V_TOTAL2_
FROM `data_1`
WHERE DATE_FORMAT( order_date, '%Y' ) = '$aa'
GROUP BY DATE_FORMAT( order_date, '%Y-%m' ) ASC ";
$resultData = mysql_query($strQueryData) or die(mysql_error());
while($arr=mysql_fetch_array($resultData)){
echo "<category Name='".$arr[Mydate]."'/>";
}
echo "</categories>";
// Model 14 Model----------->>>>
$strQueryData_new = "SELECT DISTINCT order_date, SUM( size_new ) AS V_TOTAL_new, DATE_FORMAT( order_date, '%$aa-%m' ) AS Mydate, check_status, order_generation AS V_TOTAL2_
FROM `data_1`
WHERE DATE_FORMAT( order_date, '%Y' ) = '$aa'
GROUP BY order_generation ";
$resultData_new = mysql_query($strQueryData_new) or die(mysql_error());
while($arr_new=mysql_fetch_array($resultData_new)){
$name_ =$arr_new['V_TOTAL2_'];
echo "<dataset seriesName='".$arr_new[V_TOTAL2_]."' color='".rgb2hex(rand(0, 255), rand(0, 255), rand(0, 255), true)."' anchorBorderColor='F6BD0F' anchorRadius='4'>";
// ผลรวม sum model ทุก เดือน --------------->>
$strQueryData_new_1 = "SELECT DISTINCT order_date , SUM( size_new ) AS V_TOTAL_new , DATE_FORMAT( order_date, '%$aa-%m' ) AS Mydate , order_generation AS V_TOTAL2_
FROM `data_1`
WHERE DATE_FORMAT( order_date, '%Y' ) = '$aa' AND order_generation='$arr_new[V_TOTAL2_]'
GROUP BY DATE_FORMAT( order_date, '%$aa-%m') ";
$resultData_new_1 = mysql_query($strQueryData_new_1) or die(mysql_error());
while($arr_new_1=mysql_fetch_array($resultData_new_1)){
$Mydate=$arr_new_1['Mydate'];
$V_TOTAL2_=$arr_new_1['V_TOTAL2_'];
$V_TOTAL_new=$arr_new_1['V_TOTAL_new'];
echo "<set value='".$arr_new_1['V_TOTAL_new'] / 10000 ."'/>";
}
echo "</dataset>";
}
echo "</graph>";
?>
<center><div id="chart5Div">This text is replaced by chart.</div></center>
48.<script type="text/javascript">
49.var chart2 = new FusionCharts("Charts/FCF_MSLine.swf", "ChId1", "850", "430");
50.chart2.setDataURL("Data/SalesCompare_2014.php");
51.chart2.render("chart5Div");
52.</script></td>