php餅圖
A. 有哪些比較好用的php圖標插件(生成折線圖、柱狀圖、餅狀圖) 多多益善 類似highcharts和jpgraph
HighCharts
jqPlot
dygraphs
Protovis
fusioncharts
ECharts
Google Chart Tools
JS Charts
chart.js
jQuery Sparklines
Cubism.js
xcharts
B. php jpgraph 餅圖 圖例 中文亂碼 怎麼解決
標題轉換成了gb2312 的編碼,下邊的也轉換下就行了.
C. PHP實現柱狀圖,餅狀圖
這種圖應該可以使用php jpgraph類庫來完成,具體的開源類庫下載,以及示例、演示情況,你可以訪問其官方網站,下載的類庫代碼里有完整的示例代碼。
jpgraphp 官方下載地址
http://jpgraph.net/download/
JpGraph簡介
以前用PHP作圖時必須要掌握復雜抽象的畫圖函數,或者藉助一些網上下載的花柱形圖、餅形圖的類來實現。沒有一個統一的chart類來實現圖表的快速開發。
現在我們有了一個新的選擇:JpGraph。專門提供圖表的類庫。它使得作圖變成了一件非常簡單的事情,你只需從資料庫中取出相關數據,定義標題,圖表類型,然後的事情就交給JpGraph,只需掌握為數不多的JpGraph內置函數(可以參照JpGraph附帶例子學習),就可以畫出非常炫目的圖表!
D. 如何使用PHP動態生成餅狀圖,柱狀圖和折線圖
PHP自帶的繪圖函數來做特別麻煩,用jpgrah,封裝好了的 。傳入參數自動生成餅狀圖,柱狀圖之類的 特變方便
E. php統計,如何生成餅圖演算法
餅狀圖表對於查看一個值占總值的百分比是一個好的方法。我們就用PHP來實現一個餅形圖表。
它的設計思想是:
1 接受參數,得到所有數值的和,得到每一個值占數值總和的比例。
2 根據比例計算每一個色塊在圖中的圓周角度
3 要產生立體效果,只需要用深顏色畫出陰影就可以了
F. 怎麼不安裝類庫用php畫曲線圖和餅圖
php本身沒有畫圖功能。都是通過GD庫等外部擴展實現的。如果只是單純的曲線圖和餅圖,可以考慮使用前端js代碼實現,比如iChart等插件都能做出很漂亮的示意圖。比GD搞出來的要漂亮,而且是動態的,可以根據點擊進行交互。
G. php如何在一個頁面同時顯示柱狀圖 折線圖 餅圖 能給個例子嗎
樓住你想要干什麼吖,把問題說清楚才行吖
你是想要利用PHP程序生程你所需要的圖形
還是在一個網頁裡面同時顯示那幾個圖形吖.
H. php三維餅圖怎麼做要調入資料庫的數據!請高手指點!不會的別來混經驗!
這是個2D的。
其中有一個自定義函數,用於繪制餅圖,參數是一個鍵值對數組。
每項內容是由數組定義的。你調入資料庫中的內容後讀入數組即可。
前提是你當然要開啟GD擴展,要不是沒得畫得。呵。
<?php
function pie2d($a) //創建自定義函數
{
$im=imagecreate(420,300); //建立圖像
$back=imagecolorallocate($im,255,255,200); //背景色
$color[]=imagecolorallocate($im,0,0,255); //定義10個顏色,可以最多處理10項
$color[]=imagecolorallocate($im,255,0,0);
$color[]=imagecolorallocate($im,0,255,0);
$color[]=imagecolorallocate($im,100,100,255);
$color[]=imagecolorallocate($im,255,0,255);
$color[]=imagecolorallocate($im,150,0,0);
$color[]=imagecolorallocate($im,0,0,150);
$color[]=imagecolorallocate($im,0,150,0);
$color[]=imagecolorallocate($im,0,0,0);
$color[]=imagecolorallocate($im,150,150,150);
$value_a=array_values($a); //獲取參數數組所有值到新數組
$all=array_sum($value_a); //統計新數組的和
$i=0; //循環標記
foreach($a as $key=>$value) //遍歷數組
{
$angle[]=$value/$all*360; //獲取當前角度
$str=$key.":".round($value/$all*100,2)."%"; //需要輸出的內容
imagestring($im,5,10,($i*20+10),$str,$color[$i]); //畫字元串
$i++; //標記自增
}
$s=0; //當前角度標記
$i=0;
foreach($angle as $temp) //遍歷所有項角度
{
imagefilledarc($im,285,150,240,120,$s,($s+$temp),$color[$i],4); //畫橢圓弧
//imagefillellipse();
$s=$s+$temp; //角度增加為當前角度
$i++;
}
imagepng($im); //輸出PNG
imagedestroy($im); //銷毀圖像
}
$arr=array(
"perfect"=>1,
"excellent"=>2,
"very good"=>4,
"good"=>1,
"not bad"=>1,
"normal"=>1,
"bad"=>1,
"very bad"=>1,
"god save me"=>1,
"hell"=>1
); //定義數組,數組內容為選項內容與選項數量的鍵值對
$re=pie2d($arr); //調用自定義函數
?>
I. 求php生成餅圖的類或例子,圖上要有算百分比的
<?php
//公用函數
//把角度轉換為弧度
function deg2Arc($degrees) {
return($degrees * (pi()/180.0));
}
//RGB
function getRGB($color){
$R=($color>>16) & 0xff;
$G=($color>>8) & 0xff;
$B=($color) & 0xff;
return (array($R,$G,$B));
}
// 取得在橢圓心為(0,0)的橢圓上 x,y點的值
function pie_point($deg,$va,$vb){
$x= cos(deg2Arc($deg)) * $va;
$y= sin(deg2Arc($deg)) * $vb;
return (array($x, $y));
}
//3D餅圖類
class Pie3d{
var $a; //橢圓長半軸
var $b; //橢圓短半軸
var $DataArray; //每個扇形的數據
var $ColorArray; //每個扇形的顏色 要求按照十六進制書寫但前面不加0x
//為邊緣及陰影為黑色
function Pie3d($pa=150,$pb=100,$sData="10,20,30,40,50", $sColor="#4472A6,#395F8C,#BAC6DE,#91A7CE,#4E7FBA")
{
$this->a=$pa;
$this->b=$pb;
$this->DataArray=split(",",$sData);
$this->ColorArray=split(",",$sColor);
}
function setA($v){
$this->a=$v;
}
function getA(){
return $this->a;
}
function setB($v){
$this->b=$v;
}
function getB(){
return $this->b;
}
function setDataArray($v){
$this->DataArray=split(",",$v);
}
function getDataArray($v){
return $this->DataArray;
}
function setColorArray($v){
$this->ColorArray=split(",",$v);
}
function getColorArray(){
return $this->ColorArray;
}
function DrawPie(){
$image=imagecreate($this->a*2+40,$this->b*2+40);
$PieCenterX=$this->a+10;
$PieCenterY=$this->b+10;
$DoubleA=$this->a*2;
$DoubleB=$this->b*2;
list($R,$G,$B)=getRGB(0);
$colorBorder=imagecolorallocate($image,$R,$G,$B);
$DataNumber=count($this->DataArray);
//$DataTotal
for($i=0;$i<$DataNumber;$i++) $DataTotal+=$this->DataArray[$i]; //算出數據和
//填充背境
imagefill($image, 0, 0, imagecolorallocate($image, 0xFF, 0xFF, 0xFF));
/*
** 畫每一個扇形
*/
$Degrees = 0;
for($i = 0; $i < $DataNumber; $i++){
$StartDegrees = round($Degrees);
$Degrees += (($this->DataArray[$i]/$DataTotal)*360);
$EndDegrees = round($Degrees);
$percent = number_format($this->DataArray[$i]/$DataTotal*100, 1);
list($R,$G,$B)=getRGB(hexdec($this->ColorArray[$i]));
$CurrentColor=imagecolorallocate($image,$R,$G,$B);
if ($R>60 and $R<256) $R=$R-60;
if ($G>60 and $G<256) $G=$G-60;
if ($B>60 and $B<256) $B=$B-60;
$CurrentDarkColor=imagecolorallocate($image,$R,$G,$B);
//畫扇形弧
imagearc($image,$PieCenterX,$PieCenterY,$DoubleA,$DoubleB,$StartDegrees,$EndDegrees,$CurrentColor);
//畫直線
list($ArcX, $ArcY) = pie_point($StartDegrees , $this->a , $this->b);
imageline($image,$PieCenterX,$PieCenterY,floor($PieCenterX + $ArcX),floor($PieCenterY + $ArcY),$CurrentColor);
//畫直線
list($ArcX, $ArcY) = pie_point($EndDegrees,$this->a , $this->b);
imageline($image,$PieCenterX,$PieCenterY,ceil($PieCenterX + $ArcX),ceil($PieCenterY + $ArcY),$CurrentColor);
//填充扇形
$MidPoint = round((($EndDegrees - $StartDegrees)/2) + $StartDegrees);
list($ArcX, $ArcY) = Pie_point($MidPoint, $this->a*3/4 , $this->b*3/4);
imagefilltoborder($image,floor($PieCenterX + $ArcX),floor($PieCenterY + $ArcY), $CurrentColor,$CurrentColor);
imagestring($image,2,floor($PieCenterX + $ArcX-5),floor($PieCenterY + $ArcY-5),$percent."%",$colorBorder);
//畫陰影
if ($StartDegrees>=0 and $StartDegrees<=180){
if($EndDegrees<=180){
for($k = 1; $k < 15; $k++)
imagearc($image,$PieCenterX, $PieCenterY+$k,$DoubleA, $DoubleB, $StartDegrees, $EndDegrees, $CurrentDarkColor);
}else{
for($k = 1; $k < 15; $k++)
imagearc($image,$PieCenterX, $PieCenterY+$k,$DoubleA, $DoubleB, $StartDegrees, 180, $CurrentDarkColor);
}
}
}
/*到此腳本已經生了一幅圖像了
**現在需要的是把它發到瀏覽器上,重要的一點是要將標頭發給瀏覽器,讓它知道是一個GIF文件。不然的話你只能看到一堆奇怪的亂碼
*/
//輸出生成的圖片
header("Content-type: image/gif");
imagegif($image);
imagedestroy($image);
}//End drawPie()
}//End class
//實現
$objp = new Pie3d();
$objp->DrawPie();
?>
J. 請問jpgraph餅圖如何實現如圖中的紅圈所圈內容一行顯示8個項目謝謝
配置
首先需要注意的是:要想適用jpgraph,你的PHP必須開啟了GD2擴展。
在jpgraph.php中有以下這樣一段代碼是設置字體文件路徑的
if (!defined('TTF_DIR')) {
if (strstr( PHP_OS, 'WIN') ) {
$sroot = getenv('SystemRoot');
if( empty($sroot) ) {
$t = new ErrMsgText();
$msg = $t->Get(12,$file,$lineno);
die($msg);
}
else {
define('TTF_DIR', $sroot.'/fonts/');
}
} else {
define('TTF_DIR','/usr/share/fonts/truetype/');ç(我的作法是將windows下的fonts文件夾下的字體全部COPY到/usr/local/fonts/truetype)
}
}
要支持中文需要用到simhei.ttf和simsun.ttc這兩個字體,在使用中文的時候需要使用SetFont(FF_SIMSUN,FS_BOLD)設置字體。
如果你的文件編碼為utf-8,修改方法如下:
代碼:
方法一,在程序中修改
$title="流量圖";
$title = iconv("UTF-8", "gb2312", $title);
$graph->title->Set($title);
方法二,修改源文件jpgraph_ttf.inc.php
在第99-106行,改成下面這樣子
elseif( $aFF === FF_SIMSUN ) {
// Do Chinese conversion
/*
if( $this->g2312 == null ) {
include_once 'jpgraph_gb2312.php' ;
$this->g2312 = new GB2312toUTF8();
}
return $this->g2312->gb2utf8($aTxt);
*/
return $aTxt;
}
jpgraph默認顯示漢字時是把漢字編碼認為gb2312,轉化為utf-8以後再顯示。
這樣的話,如果你的文件編碼是gb2312,SetFont方法的第一個參數為FF_SIMSUN即可。
如果你是utf-8編碼你還需要先把漢字編碼轉化為gb2312,這樣你的漢字才可以正常顯示。
使用
可以參照jpgraph-2.3.4srcExamples中的例子。下面是一些常用的:
$graph->title->Set(『設置圖表的標題』);
$graph->xaxis->title->Set("設置X軸的標題");
$graph->yaxis->title->Set("設置Y軸的標題");
//設置字體如果是中文,第一個參數一般設置為FF_SIMSUN
SetFont(FF_SIMSUN,FS_BOLD,14);
//如設置圖表標題的字體
$graph->title->SetFont(FF_SIMSUN,FS_BOLD,14);
//設置顏色
SetColor('red');
Example:
例1. php Jpgraph繪制簡單的X-Y坐標圖
<?php
include ("../jpgraph.php");
include ("../jpgraph_line.php");
//將要用於圖表創建的數據存放在數組中
$data=array(19,23,34,38,45,67,71,78,85,90,96,145);
$graph=newGraph(500,300);//創建新的Graph對象
$graph->SetScale("textlin");//設置刻度樣式
$graph->img->SetMargin(30,30,80,30);//設置圖表邊界
$graph->title->Set("CDNTrafficTotal");//設置圖表標題
$graph->title->SetColor("blue");
$graph->title->SetMargin(20);
//Createthelinearplot
$lineplot=newLinePlot($data);//創建新的LinePlot對象
$lineplot->SetLegend("Line(Mbits)");//設置圖例文字
$lineplot->SetColor("red");//設置曲線的顏色
//Addtheplottothegraph
$graph->Add($lineplot);//在統計圖上繪制曲線
//Displaythegraph
$graph->Stroke();//輸出圖像
?>
例6.
index.html
<html>
<head>
<title>CDN流量查詢系統統計</title>
<metahttp-equiv="Content-Type"content="text/html;charset=gb2312">
<mce:styletype="text/css"><!--
.style1{
font-size:16px;
font-weight:bold;
}
--></mce:style><styletype="text/css"mce_bogus="1">.style1{
font-size:16px;
font-weight:bold;
}</style>
</head>
<body>
<formname="form1"method="get"action="result.php">
<palign="center"class="style1">CDN流量查詢系統統計</p>
<tablewidth="300"border="1"align="center"cellpadding="3"cellspacing="3">
<tr>
<tdwidth="85"><strong>查詢年份</strong></td>
<tdwidth="188"><selectname="acct_yr"id="acct_yr">
<optionvalue="2009"selected>2008</option>
<optionvalue="2009"selected>2009</option>
</select></td>
</tr>
<tr>
<td><strong>起始月份</strong></td>
<td><selectname="start_mth"id="start_mth">
<optionselected>01</option>
<option>02</option>
<option>03</option>
<option>04</option>
<option>05</option>
<option>06</option>
<option>07</option>
<option>08</option>
<option>09</option>
<option>10</option>
<option>11</option>
<option>12</option>
</select></td>
</tr>
<tr>
<td><strong>終止月份</strong></td>
<td><selectname="end_mth"id="end_mth">
<option>01</option>
<option>02</option>
<option>03</option>
<option>04</option>
<option>05</option>
<option>06</option>
<option>07</option>
<option>08</option>
<option>09</option>
<option>10</option>
<option>11</option>
<optionselected>12</option>
</select></td>
</tr>
<tr>
<td><strong>統計圖類別</strong></td>
<td><selectname="graph"id="graph">
<optionvalue="1"selected>線型圖</option>
<optionvalue="2">柱形圖</option>
<optionvalue="3">餅圖</option>
<optionvalue="4">3D餅圖</option>
</select></td>
</tr>
</table>
<palign="center">
<inputtype="submit"value="Submit">
<inputtype="reset"name="Submit2"value="Reset">
</p>
</form>
</body>
</html>
case1:
$graph=newGraph(400,300);//創建新的Graph對象
$graph->SetScale("textlin");//設置刻度樣式
$graph->img->SetMargin(30,30,80,30);//設置圖表邊界
$graph->title->SetFont(FF_SIMSUN,FS_BOLD);//設置字體
$graph->title->Set("CDN流量查詢");//設置圖表標題
$lineplot=newLinePlot($data);
$lineplot->SetLegend("Line");
$lineplot->SetColor("red");
$graph->Add($lineplot);
break;
case2:
$graph=newGraph(400,300);
$graph->SetScale("textlin");
$graph->SetShadow();
$graph->img->SetMargin(40,30,20,40);
$barplot=newBarPlot($data);//創建BarPlot對象
$barplot->SetFillColor('blue');//設置顏色
$barplot->value->Show();//設置顯示數字
$graph->Add($barplot);//將柱形圖添加到圖像中
$graph->title->Set("CDN流量查詢");//設置標題和X-Y軸標題
$graph->xaxis->title->Set("月份");
$graph->yaxis->title->Set("流量(Gbits)");
$graph->title->SetFont(FF_SIMSUN,FS_BOLD);//設置字體
$graph->yaxis->title->SetFont(FF_SIMSUN,FS_BOLD);
$graph->xaxis->title->SetFont(FF_SIMSUN,FS_BOLD);
break;
case3:
$graph=newPieGraph(400,300);
$graph->SetShadow();
$graph->title->Set("CDN流量查詢");
$graph->title->SetFont(FF_SIMSUN,FS_BOLD);
$pieplot=newhttps://www.guwengl.com#data);
$pieplot->SetLegends($gDateLocale->GetShortMonth());//設置圖例
$graph->Add($pieplot);
break;
default:
echo"graph參數錯誤";
exit;
}
$graph->Stroke();
?>