<?php 
set_time_limit(3600);
include "../config/conn.php";
$sql="SELECT * FROM m_lokasi WHERE 1=1";
if($_POST['pos']==""){
	$sql.=" AND nama_lokasi='awlr_katulampa'";
} else { 
	$sql.=" AND nama_lokasi='".$_POST['pos']."'";
}
$sql_ambil_namapos=mysql_query($sql);
$ambil=mysql_fetch_array($sql_ambil_namapos);
?>
        <script>

            AmCharts.makeChart("charttma", {

                type: "serial",
                dataProvider: [/*{
                    "date": "2012-01-01 12:00",
                    "value": 8
                }*/
				<?php
                 if($_POST['pos']!="" && $_POST['tgl1']!="" && $_POST['tgl2']!=""){
                $SQL="SELECT DISTINCT ReceivedDate,jam_value AS ReceivedTime,UNIX_TIMESTAMP(CONCAT(ReceivedDate,'-',DATE_FORMAT(a.ReceivedTime,'%H:0'))) AS tgl,max(a.WLevel) AS WLevel, FORMAT(a.WLevel*100,0) AS klWLevel
FROM ".$_POST['pos']." AS a
INNER JOIN m_jam AS b ON DATE_FORMAT(b.jam_value,'%H:0') = DATE_FORMAT(a.ReceivedTime,'%H:0')
WHERE 1=1 AND a.WLevel!=0 AND a.WLevel>=1 AND a.ReceivedDate>='".$_POST['tgl1']."' AND a.ReceivedDate<='".$_POST['tgl2']."' GROUP BY ReceivedDate,jam_value
ORDER BY a.ReceivedDate,b.jam_value ASC";
                        }
				    //    $SQL="SELECT DISTINCT UNIX_TIMESTAMP(CONCAT(ReceivedDate,'-',ReceivedTime)) AS tgl, WLevel FROM awlr_bebedahan ";
                        $QUERY=mysql_query($SQL);
                        $i=0;
						while ($x=mysql_fetch_array($QUERY)) {
                        $i++;
							if($ambil['id_merk']=="RADIO") { $tma=$x['klWLevel']; } else {
								if($_POST['pos']=="awlr_katulampa") {$tma=$x['WLevel']-5; }	else { $tma=$x['WLevel']; }
							}
							echo '{"date":"'.$x['ReceivedDate'].' '.date('H:i',strtotime($x['ReceivedTime'])).'","value":'.$tma.'},';
						}
                    ?>],

                dataDateFormat: "YYYY-MM-DD JJ:NN",
                categoryField: "date",


                categoryAxis: {
                    parseDates: true,
                    minPeriod: "mm",
                    gridAlpha: 0.07,
					title:"<?php echo str_replace('_','',strtoupper(str_replace('awlr_','',$_POST['pos'])));?>\nsiaga3 : <?php echo $ambil['siaga3'];?>, siaga2 : <?php echo $ambil['siaga2'];?>, siaga1 : <?php echo $ambil['siaga1'];?>"
                },

                graphs: [{
                    id:"g1",
                    lineColor: "#00CC00",
                    valueField: "value",
                    dashLength: 3,
                    bullet: "round",
                    balloonText: "<b><span style='font-size:14px;'>[[value]] Cm</span></b>",
                    balloon:{
                        drop:true
                    }
                }],

                chartCursor: {
                    limitToGraph:"g1",
                    cursorColor:"#00CC00"
                },
                chartScrollbar: {

                },

                mouseWheelZoomEnabled: true,

               
            });
        </script>        
        
<div id="charttma" style="height: 350px; min-width: 310px"></div>

