138 lines
3.8 KiB
PHP
Executable File
138 lines
3.8 KiB
PHP
Executable File
<?php
|
|
//-----需要预先定义的变量,可以修改
|
|
$maxYNum=5000;
|
|
$legendArr=array(
|
|
//array('Name','ColorHex',$color),
|
|
array('Request','0000FF',0),
|
|
array('Success','00CC00',0)
|
|
);
|
|
$title="Download";
|
|
$imgFileName="cstaDownload_$randval.png";
|
|
@unlink($imgFileName);
|
|
|
|
//-----图片背景和坐标,标示等基本元素,请勿修改这部分
|
|
$DEBUG=0;
|
|
$sizex=400;
|
|
$sizey=180;
|
|
$bgcolor=F8F8F8;
|
|
$fgcolor=000000;
|
|
//$date=date("Y-m-d",mktime(0,0,0,date("m"),date("d"),date("Y")));
|
|
|
|
|
|
$im = ImageCreate ($sizex, $sizey);
|
|
|
|
$background_color = ImageColorAllocate ($im, hexdec(substr($bgcolor, 0, 2)), hexdec(substr($bgcolor, 2, 2)),hexdec(substr($bgcolor, 4, 2)));
|
|
|
|
$text_color = ImageColorAllocate ($im, hexdec(substr($fgcolor, 0, 2)), hexdec(substr($fgcolor, 2, 2)),hexdec(substr($fgcolor, 4, 2)));
|
|
|
|
//背景
|
|
ImageFilledRectangle($im,0,0,$sizex,$sizey,ImageColorAllocate ($im, 198, 198, 198));
|
|
ImageFilledRectangle($im,2,2,$sizex,$sizey,ImageColorAllocate ($im, 130, 130, 130));
|
|
$pointArr=array(0,$sizey-1,3,$sizey-4,4,$sizey-1);
|
|
Imagefilledpolygon($im, $pointArr, 3, ImageColorAllocate ($im, 130, 130, 130));
|
|
$pointArr=array($sizex-1,0,$sizex-4,3,$sizex,4);
|
|
Imagefilledpolygon($im, $pointArr, 3, ImageColorAllocate ($im, 130, 130, 130));
|
|
ImageFilledRectangle($im,2,2,$sizex-3,$sizey-3,$background_color);
|
|
|
|
//边框
|
|
$xBgn=75;
|
|
$yBgn=15;
|
|
$xEnd=383;
|
|
$yEnd=115;
|
|
$unitXPix=1;
|
|
ImageLine($im, $xBgn, $yBgn, $xBgn, $yEnd, $text_color);
|
|
ImageLine($im, $xBgn, $yBgn, $xEnd, $yBgn, $text_color);
|
|
ImageLine($im, $xBgn, $yEnd, $xEnd, $yEnd, $text_color);
|
|
ImageLine($im, $xEnd, $yBgn, $xEnd, $yEnd, $text_color);
|
|
|
|
//竖网格及标注
|
|
for($i=0;$i<25;$i++){
|
|
if($i % 2 == 0){
|
|
ImageDashedLine($im, $xBgn + $i*12, $yBgn, $xBgn + $i*12, $yEnd, $text_color);
|
|
Imagestring($im, 2, $xBgn + $i*12 - 4, $yEnd, "$i", $text_color);
|
|
}
|
|
}
|
|
|
|
//横网格及标注
|
|
for($i=0;$i<4;$i++){
|
|
ImageDashedLine($im, $xBgn, $yBgn + $i*25, $xEnd, $yBgn + $i*25, $text_color);
|
|
$yRemark=$maxYNum / 4 * (4 - $i);
|
|
Imagestring($im, 2, $xBgn - 50, $yBgn + $i*25 - 5, "$yRemark", $text_color);
|
|
}
|
|
|
|
for($i=0;$i<sizeof($legendArr);$i++){
|
|
$tmpName=$legendArr[$i][0];
|
|
$tmpColor=$legendArr[$i][1];
|
|
$color = ImageColorAllocate ($im, hexdec(substr($tmpColor, 0, 2)), hexdec(substr($tmpColor, 2, 2)),hexdec(substr($tmpColor, 4, 2)));
|
|
$legendArr[$i][2]=$color;
|
|
ImageFilledRectangle($im,82 + $i* 100,$yEnd + 22,80 + $i* 100 + 10,$yEnd + 30,$legendArr[$i][2]);
|
|
Imagestring($im, 2, 95 + $i* 100,$yEnd + 20, "$tmpName", $text_color);
|
|
}
|
|
|
|
//下部图表名称
|
|
//$title="This is a image tamplate.";
|
|
Imagestring($im, 2, 20,$yEnd + 40, $title, $text_color);
|
|
|
|
//右下角日期
|
|
Imagestring($im, 2, $xEnd-90,$yEnd + 40, "Date:$date", $text_color);
|
|
|
|
//-----开始画图(线或色块),需要修改
|
|
//-----开始画图
|
|
$i=0;
|
|
while($rows = mysqli_fetch_array($result)){
|
|
$pointArr_1[$i]=$rows[timeNo];
|
|
$pointArr_2[$i]=$rows[timeNo];
|
|
$pointArr_1[$i+1]=$rows[dnRequ];
|
|
$pointArr_2[$i+1]=$rows[dnSucc];
|
|
$i += 2;
|
|
}
|
|
|
|
$pointArr=getNewXY($pointArr_1);
|
|
if($DEBUG){
|
|
for($i=0;$i<sizeof($pointArr_1);$i++){
|
|
echo "<br>pointArr[$i]={$pointArr[$i]}";
|
|
}
|
|
}
|
|
$pointNum= sizeof($pointArr) / 2;
|
|
|
|
$tmpColor=$legendArr[0][2];
|
|
//线条
|
|
imagepolygon($im, $pointArr, $pointNum, $tmpColor);
|
|
|
|
$pointArr=getNewXY($pointArr_2);
|
|
if($DEBUG){
|
|
for($i=0;$i<sizeof($pointArr);$i++){
|
|
echo "<br>pointArr[$i]={$pointArr[$i]}";
|
|
}
|
|
}
|
|
$pointNum= sizeof($pointArr) / 2;
|
|
|
|
$tmpColor=$legendArr[1][2];
|
|
//色块
|
|
imagefilledpolygon($im, $pointArr, $pointNum, $tmpColor);
|
|
|
|
//-----输出图形文件,请勿修改
|
|
//再画一次边框
|
|
ImageLine($im, $xBgn, $yBgn, $xBgn, $yEnd, $text_color);
|
|
ImageLine($im, $xBgn, $yBgn, $xEnd, $yBgn, $text_color);
|
|
ImageLine($im, $xBgn, $yEnd, $xEnd, $yEnd, $text_color);
|
|
ImageLine($im, $xEnd, $yBgn, $xEnd, $yEnd, $text_color);
|
|
//输出图形文件
|
|
ImagePng ($im,"$imgFileName");
|
|
ImageDestroy($im);
|
|
|
|
/*
|
|
//-----显示图片
|
|
echo "<body topmargin=\"0\" leftmargin=\"5\">";
|
|
echo "<img src=\"$imgFileName\">";
|
|
echo "<br><br>";
|
|
echo "</body>";
|
|
*/
|
|
?>
|
|
|
|
|
|
|
|
|
|
|
|
|