chart.php3
来自「FIREFLY 是一个多用户专业帮助桌面系统」· PHP3 代码 · 共 310 行
PHP3
310 行
<?################################################################## CHART#################################################################/* init */include ("../include/levels.php3");$access_level = $r_level["admin"];include ("../include/config.php3");/* process *///r閏up閞ation des donn閑s statistiques$cont['month'] = $month;$cont['year'] = $year;$cont['sort'] = "number DESC,duration DESC";$cont['mode'] = $content;$datas = SQL_READ_CASE_STATS($dbproc,$cont);//閘imination des index num閞iques(1/2);$datacopy = $datas;if (is_array($datacopy)){ if (is_array($datacopy[0])) { reset($datacopy); while(list($id,$value) = each($datacopy)) { reset ($value); while(list($idd) = each($value)) { unset($datas[$id][$idd]); list($idd) = each($value); } } } else { while(list($idd) = each($datacopy)) { unset($datas[$idd]); list($idd) = each($datacopy); } }}//mise en forme des donn閑sif (!is_array($datas)){ unset($datas); $datas[0] = 0; $ncoltitle = 1;}if(!is_array($datas[0])){ $id = 0; unset($datacopy); while (list($index,$value) = each($datas)) { $datacopy[$id]['index'] = $index; $datacopy[$id]['value'] = $value; $id++; } $datas = $datacopy;}if (!$ncoltitle) $ncoltitle = 1; if ($height == 0) $height = 15*count($datas)*(count($datas[0])-$ncoltitle)+50; if (!$width) $width = 100; if (!$height) $height = 100; if (!$mode) $mode = 'histogram'; if (!$type) $type = $gd_type; $topmargin = 10; $botmargin = 10; $legheight = 30; $hmargin = 10; $charspace = imagefontwidth(5); $scharspace = imagefontwidth(3); $legsize = $width - 2*$hmargin; $legtop = $height-$botmargin-$legheight; $legbot = $height-$botmargin; $legcenter = $legtop+$legheight/2; switch($mode) { case "circle": $legspace = $legsize/count($datas); $ncolors = count($datas); break; default: $legspace = $legsize/(count($datas[0])-$ncoltitle); $ncolors = count($datas[0])+1; }$image = imagecreate($width,$height);$col_back = imagecolorallocate($image,220,200,240);imagefill($image,0,0,$col_back);$col_black = imagecolorallocate($image,0,0,0);$col_white = imagecolorallocate($image,255,255,255);$ncolors = $ncolors+1;for ($i = 0; $i < $ncolors; $i++){ $pos = floor(750*$i/($ncolors-1)); if ($pos < 256) { $r = 255; $v = $pos; $b = 0; } elseif ($pos < 512) { $r = 0; $v = 512-$pos; $b = $pos-256; } else { $r = $pos-512; $v = 0; $b = 768-$pos; } if ($r > 255) $r = 255; if ($v > 255) $v = 255; if ($b > 255) $b > 255; $col_chart[$i] = imagecolorallocate($image,$r,$v,$b);}imagerectangle($image,$hmargin,$legtop,$hmargin+$legsize,$legbot,$col_black);reset($datas);while (list($index,$value) = each($datas)){ reset($value); list($title1,$content1) = each($value); for($i = 1; $i < $ncoltitle; $i++) { list($title,$content) = each($value); $datas[$index][$title1] .= " ".$content; unset($datas[$index][$title]); } if ($mode != "circle") { $idleg = 0; //reset($value); while(list($title) = each($value)) { //print $title; $leghpos = $hmargin+10+$idleg*$legspace; imagefilledrectangle($image,$leghpos-5,$legcenter-5,$leghpos+5,$legcenter+5,$col_chart[$idleg]); $title = ucfirst($title); for ($pos = 0; $pos < strlen($title); $pos++) imagechar($image,3,$leghpos+10+$pos*$scharspace,$legcenter-6,substr($title,$pos,1),$col_black); $idleg ++; } }}$rows = count($datas);$columns = count($datas[0]);$maxchar = 0;reset($datas);while(list($index) = each($datas)){ list($title,$value) = each($datas[$index]); if (strlen($value) > $maxchar) $maxchar = strlen($value); while(list($title,$value) = each($datas[$index])) { settype($value,'integer'); if ($value > $max[$title]) $max[$title] = $value; }}switch($mode){ case "circle": $degtorad = 2*pi()/360; $hcenter = $width/2; $vcenter = $topmargin+($height-$topmargin-$botmargin*2-$legheight)/2; if ($width < $height) $rayon = $width/2-$hmargin-10; else $rayon = ($height-$topmargin-$botmargin*2-$legheight)/2-10; imagearc ($image,$hcenter+3,$vcenter+3,$rayon*2+1,$rayon*2+1,0,360,$col_black); imagefilltoborder($image,$hcenter,$vcenter,$col_black,$col_black); $anglestart = 0; $tot = 0; reset($datas); while(list($index) = each($datas)) { reset($datas[$index]); list($useless,$title) = each($datas[$index]); list($useless,$value) = each($datas[$index]); $tot += $value; } if ($tot == 0) $tot = 1; reset($datas); while(list($index) = each($datas)) { reset($datas[$index]); list($id,$title) = each($datas[$index]); list($id,$value) = each($datas[$index]); $title = "$title ($value)"; $title = ucfirst($title); $angle = 360*$value/$tot; $angle0 = $anglestart; $angle1 = $anglestart+$angle; $anglem = $anglestart+($angle/2); imagearc ($image,$hcenter,$vcenter,$rayon*2,$rayon*2,$angle0,$angle1+1,$col_chart[$index]); $angle0 = $degtorad*$angle0; $angle1 = $degtorad*$angle1; $anglemid = $degtorad*$anglem; $x0 = $hcenter+$rayon*cos($angle0); $x1 = $hcenter+$rayon*cos($angle1); $xm = $hcenter+0.8*$rayon*cos($anglemid); $xmm = $hcenter+($rayon+10)*cos($anglemid); $y0 = $vcenter+$rayon*sin($angle0); $y1 = $vcenter+$rayon*sin($angle1); $ym = $vcenter+0.8*$rayon*sin($anglemid); $ymm = $vcenter+($rayon+10)*sin($anglemid); imageline($image,$hcenter,$vcenter,$x0,$y0,$col_chart[$index]); imageline($image,$hcenter,$vcenter,$x1,$y1,$col_chart[$index]); if ($value > 0) imagefilltoborder($image,$xm,$ym,$col_chart[$index],$col_chart[$index]); imageline($image,$xmm,$ymm,$xm,$ym,$col_black); $titlelen = strlen($title); if($anglem > 180) $more = 12; else $more = 0; if($anglem > 90 and $anglem <= 270) imagestring($image,3,(-$titlelen)*$scharspace+$xmm,$ymm-$more,$title,$col_black); else imagestring($image,3,$xmm+$scharspace,$ymm-$more,$title,$col_black); $anglestart += $angle; } imagestring($image,5,$hmargin+11,$legcenter-6,$id,$col_white); imagestring($image,5,$hmargin+10,$legcenter-7,$id,$col_black); break; case "histogram": $vspace = floor(($height-$topmargin-$botmargin-$legheight)/$rows); $rightspace = $hmargin; $leftspace = $hmargin+$scharspace*($maxchar+1); $maxlength = $width-$leftspace-$rightspace; reset($datas); while(list($index) = each($datas)) { reset ($col_chart); $top = $vspace*$index+$topmargin; $vinterval = floor(0.9*$vspace/($columns-1)); reset($datas[$index]); list($useless,$name) = each($datas[$index]); imagestring($image,3,1+$hmargin,1+$top,$name,$col_white); imagestring($image,3,$hmargin,$top,$name,$col_black); while(list($title,$value) = each($datas[$index])) { if ($max[$title] == 0) $max[$title] = 1; list($idcol,$color) = each($col_chart); settype($value,'integer'); imagefilledrectangle($image,$leftspace,$top+2,2+$leftspace+$value*($maxlength)/$max[$title],$top+$vinterval,$col_black); imagefilledrectangle($image,$leftspace,$top,$leftspace+$value*($maxlength)/$max[$title],$top+$vinterval-3,$color); imagestring($image,1,$leftspace+1,$top+1,$value,$col_white); imagestring($image,1,$leftspace,$top,$value,$col_black); $top += $vinterval; } } break; default:}header("Content-type: image/$type");switch($type){ case "gif" : imagegif($image); break; case "png" : imagepng($image); break; case "jpeg" : imagejpg($image); break;}?>
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?