$im = imagecreatetruecolor(810,620); $col = imagecolorallocate($im,102,204,255); imagefill($im,0,0,$col); $col = imagecolorallocate($im,255,0,0); # y axes imagefilledrectangle($im,40,50,42,580,$col); imagefilledrectangle($im,770,50,772,580,$col); # x axis imagefilledrectangle($im,40,580,770,582,$col); $col = imagecolorallocate($im,255,255,0); imagestring($im,5,350,605,"Month",$col); imagestringup($im,5,3,300,"Temp",$col); imagestring($im,5,190,20,"Figures in brackets show number of entries.",$col); # Each centigrade is 20px... # We have a max of 25C and a min of -2C $mintemp = -2; $maxtemp = 25; $px_per_c = 20; $temp_bot = 580; $temp = $mintemp; for ($i=$mintemp + 1;$i<$maxtemp;$i++) { $temp_bot = $temp_bot - 20; $temp = $temp + 1; if (floor($temp / 5) == ceil($temp / 5)) { $col = imagecolorallocate($im,102,255,255); imageline($im,42,$temp_bot + 2,770,$temp_bot + 2,$col); } $col = imagecolorallocate($im,255,0,0); imagefilledrectangle($im,36,$temp_bot,40,$temp_bot + 2,$col); $col = imagecolorallocate($im,255,255,0); imagestring($im,5,20,$temp_bot - 5,$temp,$col); } #We have 12 months but they don't start in the right places! #This gives us the start positions for the first of the month... $mnth[1] = 42; $mnth[2] = 104; $mnth[3] = 162; $mnth[4] = 224; $mnth[5] = 284; $mnth[6] = 346; $mnth[7] = 406; $mnth[8] = 468; $mnth[9] = 530; $mnth[10] = 590; $mnth[11] = 652; $mnth[12] = 712; $mnth[13] = 770; $mnthn[1] = 'Jan'; $mnthn[2] = 'Feb'; $mnthn[3] = 'Mar'; $mnthn[4] = 'Apr'; $mnthn[5] = 'May'; $mnthn[6] = 'Jun'; $mnthn[7] = 'Jul'; $mnthn[8] = 'Aug'; $mnthn[9] = 'Sep'; $mnthn[10] = 'Oct'; $mnthn[11] = 'Nov'; $mnthn[12] = 'Dec'; $mnthn[13] = 'Jan2'; for ($i=1;$i<=13;$i++) { $col = imagecolorallocate($im,255,0,0); imagefilledrectangle($im,$mnth[($i)] - 2,582,$mnth[($i)],586,$col); if ($i != 13) { $col = imagecolorallocate($im,255,255,0); imagestring($im,5,$mnth[$i] + 20,585,$mnthn[$i],$col); } } #$server="dm-scottc-w2k"; #$user="cas"; #$pw="cas"; #$cn = mssql_connect ($server,$user,$pw) or die('bollocks'); #mssql_select_db("CASTemp"); $server="localhost"; $user="calumsco_CAS01"; $pw="lotuselanK1!"; $cn = mysql_connect ($server,$user,$pw) or die('bollocks'); mysql_select_db("calumscott_csdb01"); $sqlq = "select tmp_month, avg(tmp_temp), count(tmp_temp) from temps group by tmp_month order by tmp_month"; $rs = mysql_query($sqlq); $NumRows = mysql_num_rows($rs); #$rs = mssql_query($sqlq); #$NumRows = mssql_num_rows($rs); for ($i=1;$i<=$NumRows;$i++) { # $k = mssql_fetch_row($rs); $k = mysql_fetch_row($rs); $col = imagecolorallocate($im,0,0,230); imagefilledrectangle($im,$mnth[$i],582 - (20 * ($k[1] + 2)),($mnth[($i+1)]-1),580,$col); #echo "
x1:".$mnth[$i].": y1:50: x2:".($mnth[($i+1)]-1).": y2:".(582 - (20 * ($k[1] + 2)))."
\n"; $col = imagecolorallocate($im,255,255,0); imagestringup($im,5,$mnth[$i] + 25,575,"(".$k[2].")",$col); } $sqlq = "select tmp_day, tmp_month, avg(tmp_temp) from temps group by tmp_month, tmp_day order by tmp_month, tmp_day"; #$rs = mssql_query($sqlq); #$NumRows = mssql_num_rows($rs); $rs = mysql_query($sqlq); $NumRows = mysql_num_rows($rs); $end_x = 770; $last_x = 42; $col = imagecolorallocate($im,255,255,0); for ($i=1;$i<=$NumRows;$i++) { # $k = mssql_fetch_row($rs); $k = mysql_fetch_row($rs); $thedate = mktime(0,0,0,$k[1],$k[0],'2004'); if ($i == 1) { $last_y = 582 - (20 * ($k[2] + 2)); $end_y = $last_y; } $this_x = (date('z',$thedate) * 2) + 42; $this_y = 582 - (20 * ($k[2] + 2)); #echo "x1: ".$last_x.": this_x".$this_x.": last_y:".$last_y.": this_y:".$this_y."
"; imageline($im,$last_x,$last_y,$this_x,$this_y,$col); $last_x = $this_x; $last_y = $this_y; } imageline($im,$last_x,$last_y,$end_x,$end_y,$col); header("Content-type: image/png"); imagepng($im); ?>