phpレポート開発

7661 ワード

レポートとは
レポート(レポート:レポートテーブル:テーブルグラフ)
レポートとは、レポートデータを表またはグラフで表示することである.
jpgrapfの一例を実証した.
php図面の座標システム
php図形描画技術
1.php図面の基本原理と手順
キャンバスの作成
描画に必要な各種図形(円、直線、矩形、弧、扇形…)
画像をWebページに出力し、保存してもよい
当該画像の破棄(メモリの解放)
»現在、ウェブサイト開発でよく見られる画像フォーマットはgif jpg/jpeg png bmp....
まとめ:
gif画像は圧縮率が高いが、256色しか表示できないため、色が失われたり、動画を表示できる
jpg/jpegピクチャの圧縮率が高く(圧縮損失がある)、小さいファイルで表示できる、ウェブページでの比較図
png、このフォーマットはgifとjpgの優勢を総合して、欠点はアニメーションを表示できないことです
選択方法:
php図形描画技術快速入門
前提:まずgdライブラリがphpを有効にしていることを確認してください.ini
;ライブラリの有効化
extension=php_gd2.dll
apacheの起動を再開する必要があることを覚えておいてください.
image1.phpケース:
<?php
	$im=imagecreatetruecolor(400,300);
	$red=imagecolorallocate($im,255,0,0);
	// 
	//imageellipse($im,20,20,20,20,$red);
	//  
	//imageline($im,0,0,400,300,$red);
	//  
	//imagerectangle($im,2,2,40,50,$red);
	//    
	//imagefilledrectangle($im,2,2,40,50,$red);
	//  
	//imagearc($im,100,100,50,50,180,270,$red);
	//  
	//imagefilledarc($im,100,100,80,50,180,270,$red,IMG_ARC_PIE);
	
	//       
	//1.     
	//$srcImage=imagecreatefromgif("2.GIF");
	//          getimagesize()
	//$srcImageInfo=getimagesize("2.GIF");

	//          
	//imagecopy($im,$srcImage,0,0,0,0,$srcImageInfo[0],$srcImageInfo[1]);

	//  
	$str="hello,world,  ";
	//imagestring($im,5,0,0,"hello,world,  ",$red); 
	//         
	imagettftext($im,20,10,50,50,$red,"simhei.ttf",$str);
	header("content-type: image/png");
	imagepng($im);
	imagedestory($im);
?>

総合ケース:(総合使用)
コード:
<?php

	
	//    (     )


	//1.  
	$im=imagecreatetruecolor(400,300);

	//       (          )
	$white=imagecolorallocate($im,255,255,255);
	imagefill($im,0,0,$white);

	//2.    
	//      
	$red=imagecolorallocate($im,254,0,0);
	$darkred=imagecolorallocate($im,144,0,0);
	$blue=imagecolorallocate($im,0,0,128);
	$darkblue=imagecolorallocate($im,0,0,80);
	$gary=imagecolorallocate($im,192,192,192);
	$darkgary=imagecolorallocate($im,144,144,144);

	for($i=60;$i>=50;$i--){
	imagefilledarc($im,100,$i,100,50,0,35,$darkblue,IMG_ARC_PIE);
	imagefilledarc($im,100,$i,100,50,35,75,$darkgary,IMG_ARC_PIE);
	imagefilledarc($im,100,$i,100,50,75,360,$darkred,IMG_ARC_PIE);
	}

	//     
	imagefilledarc($im,100,50,100,50,0,35,$blue,IMG_ARC_PIE);
	imagefilledarc($im,100,50,100,50,35,75,$gary,IMG_ARC_PIE);
	imagefilledarc($im,100,50,100,50,75,360,$red,IMG_ARC_PIE);

	//    
	header("content-type: image/png");
	imagepng($im);
	imagedestory($im);
	
	//                 .


?>

思考
毎回自分で描かなければならない場合、このような図は、面倒なのではないでしょうか.グラフ開発に使えるライブラリはありますか.
->jpgrapf
jpgraphの紹介
jpgraphのインストールと構成
1.公式サイトをダウンロードする
2.解凍(htdocsディレクトリにコピー)
3.構成完了使用(emampleディレクトリの他のファイルをemamlpeフォルダに切り取り、新しいフォルダ名を作成するにはjpgraphに注意)
4.テスト
jpgraphの実際の使用例(ネット名調査統計図)
完了例の概略図は次のとおりです.
データベースとデータ
--有権者のリスト
create table elector(
electorId int,
name varchar(64),
voteNums int,
voteMonth int);
Insert into elector values(1,'ブッシュ',10,1);
Insert into elector values(1,'ブッシュ',12,2);
Insert into elector values(1,'ブッシュ',34,3);
insert into elector values(2,'オバマ',34,1);
insert into elector values(2,'オバマ',30,2);
insert into elector values(2,'オバマ',12,3);
insert into elector values(2,'オバマ',30,4);
注意jpgraphのグラフを他のphpファイルに埋め込む場合は
コード:
静的表示データ(リアルタイムのデータ取得なし)
リアルタイムデータ取得(動的更新)
vote.php
<html>
<head>
<title>   </title>
<script language="javascript">
function look(){
	window.location.href="showAll.php";
}
</script>
<meta http-equiv="content-type" content="text/html;charset=utf-8"/>
</head>
<form action="" method="">
<table>
<tr><td>   </td></tr>
<tr><td>
<input type="radio" name="vote" value="1">  
<input type="radio" name="vote" value="2">   
<input type="submit" value="  "/>
</td></tr>
</table>
</form>
<form action="" method="">
<tr>
<td><input type="button" onclick="look();" value="        "/></td>
</tr>
</form>
</html>

showAll.php
<html>
<head>
<title>  </title>
<meta http-equiv="content-type" content="text/html;charset=utf-8"/>
</head>
<body>
<h1>        </h1>
<img src="showVote.php?id=1" />
<img src="showvote.php?id=2" />
</body>
</html>

showVote.php(コア)
<?php // content="text/plain; charset=utf-8"
require_once ('jpgraph/jpgraph.php');
require_once ('jpgraph/jpgraph_bar.php');

//$datay1=array(13,8,119,7,17,6);
//$datay2=array(0,0,0,0,0,0);

//$datay1=array(13,8,11);
//$datay2=array(0,0,0);
// Create the graph.
$graph = new Graph(350,250);
$graph->SetScale('textlin');
$graph->SetMarginColor('silver');


// Setup title
/*$str="";
$id=$_REQUEST['id']; 
if($id==1){
	$str="         ( )";
}
else if($id==2){
	$str="          ( )";
}*/

//    

$id=$_REQUEST["id"];
//  sql
$sql="select * from elector where electorId=$id order by voteMonth";



$conn=mysql_connect("localhost","root","root") or die("    ".mysql_error());
mysql_select_db("test",$conn) or die(mysql_error());
mysql_query("set names gbk") or die(mysql_error());
$res=mysql_query($sql,$conn) or die(mysql_error());

$datay1=array();
$datay2=array();
$i=0;
$title="";
while($row=mysql_fetch_array($res))
{
	$datay1[$i]=$row[2];
	$datay2[$i]=0;
	
	if($i==0){
		$title="  ".$row[1]."     ";
	}
	$i++;
}
mysql_free_result($res);
mysql_close($conn);


$graph->title->Set($title);
$graph->title->setFont(FF_SIMSUN,FS_BOLD,14);
// Create the first bar
$bplot = new BarPlot($datay1);
$bplot->SetFillGradient('AntiqueWhite2','AntiqueWhite4:0.8',GRAD_VERT);
$bplot->SetColor('darkred');

// Create the second bar
$bplot2 = new BarPlot($datay2);
$bplot2->SetFillGradient('olivedrab1','olivedrab4',GRAD_VERT);
$bplot2->SetColor('darkgreen');

// And join them in an accumulated bar
$accbplot = new AccBarPlot(array($bplot,$bplot2));
$graph->Add($accbplot);

$graph->Stroke();
?>