對這文章發表回應
發表限制: 非會員 可以發表
發表者: 冷日 發表時間: 2010/2/10 3:00:50
	[php] JPGraph
簡介 ::
作網頁需要使用到自動生成的圖片製作報表的時候,是否常常被 image function 一堆長長的指令搞暈頭,而在算幾個px的時候又再一次暈頭。來嚐試這個方便的繪圖物件吧!
	official
	方法:
	
<img src="graphing.php"/>
當作圖片宣告
graphing.php:
		<?
		//jpgraph的使用方法
		//這頁會輸出一張圖片, 欲使用的話插入圖片, src是這頁的URL即可
		require("config.php");
		include_once ("./jpgraph/src/jpgraph.php");
		include_once ("./jpgraph/src/jpgraph_bar.php");
		$SQL = "SELECT UID, COUNT(UID) AS count FROM `performance` GROUP BY UID ORDER BY COUNT(UID) DESC";
		$query = mysql_query($SQL);
		while($result = mysql_fetch_array($query)){
		  $name[] .= $result['UID'];
		  $count[] .= $result['count'];
		}
		// Create the graph. These two calls are always required
		$graph = new Graph(600,400,"auto");
		$graph->SetScale("textint");
		$graph->SetColor("lightyellow");
		// Add a drop shadow
		$graph->SetShadow();
		// Adjust the margin a bit to make more room for titles
		$graph->img->SetMargin(60,30,30,50);
		// Create a bar pot
		$bplot = new BarPlot($count);
		// 長條的顏色
		$bplot->SetFillColor('navy');
		// 長條的寬度
		$bplot->SetWidth(70);
		$graph->Add($bplot);
		// Setup the titles
		$graph->title->Set("performance of pilotTV");
		//設定字體 設成中文字
		$graph->title->SetFont(FF_CHINESE, FS_NORMAL, 12);
		$graph->yaxis->SetFont(FF_CHINESE);
		$graph->xaxis->SetFont(FF_CHINESE);
		$graph->xaxis->title->SetFont(FF_CHINESE, FS_NORMAL, 12);
		$graph->yaxis->title->SetFont(FF_CHINESE, FS_NORMAL, 12);
		$graph->xaxis->title->Set("姓名");
		$graph->yaxis->title->Set("業績");
		$graph->yaxis->title->SetAngle(0);
		$graph->yaxis->title->Align('left');
		$graph->xaxis->SetTickLabels($name);
		// Display the graph
		$graph->Stroke();
		?>
	參考文件:
JpGraph :: php的繪圖物件 :: 幻想的世界
在世界的中心呼喊正太 - [php] 用php製作圖表 - JpGraph
minealan's tech: [php] JPGraph
 
			
