您好,登錄后才能下訂單哦!
這篇文章主要介紹了PHP中jpgraph庫如何配置使用,具有一定借鑒價值,感興趣的朋友可以參考下,希望大家閱讀完這篇文章之后大有收獲,下面讓小編帶著大家一起了解一下。
JpGraph簡介
JpGraph是開源的PHP統計圖表生成庫,基于PHP的GD2圖形庫構建,把生成統計圖的相關操作封裝,隱藏了部分復雜的操作,使在PHP頁面上輸出統計圖表變得更加容易。JpGraph的官方網站為:http://jpgraph.net,開發者可以在上面免費下載最新版的JpGraph和閱讀相關幫助文檔或示例程序。
JpGraph的配置
(1)修改文件php.ini
在include_path中添加jpgraph的目錄路徑,并將jpgraph解壓后的src目錄名稱更改為jpgraph。
(2)檢查PHP是否支持GD庫
在php.ini文件中找到語句;extension=php_gd2.dll。把上述語句前的;號去掉,即去掉注釋。如果因為PHP版本不同而找不到此語句,則可直接添加extension=php_gd2.dll
(3)修改文件jpgraph_gb2312.php
找到函數:function gb2utf8($gb)
把函數修改為:
function gb2utf8($gb) { return $gb; }
即不使用gb2編碼方式轉utf8方式的那段代碼。
折線圖
<?php require_once ("jpgraph/jpgraph.php"); require_once ("jpgraph/jpgraph_line.php"); $data1 = array(523,634,371,278,685,587,490,256,398,545,367,577); //第一條曲線的數組 $graph = new Graph(500,300); $graph->SetScale("textlin"); $graph->SetShadow(); $graph->img->SetMargin(60,30,30,70); //設置圖像邊距 $graph->graph_theme = null; //設置主題為null,否則value->Show(); 無效 $lineplot1=new LinePlot($data1); //創建設置兩條曲線對象 $lineplot1->value->SetColor("red"); $lineplot1->value->Show(); $graph->Add($lineplot1); //將曲線放置到圖像上 $graph->title->Set("CDN流量圖"); //設置圖像標題 $graph->xaxis->title->Set("月份"); //設置坐標軸名稱 $graph->yaxis->title->Set("流 量(Gbits)"); $graph->title->SetMargin(10); $graph->xaxis->title->SetMargin(10); $graph->yaxis->title->SetMargin(10); $graph->title->SetFont(FF_SIMSUN,FS_BOLD); //設置字體 $graph->yaxis->title->SetFont(FF_SIMSUN,FS_BOLD); $graph->xaxis->title->SetFont(FF_SIMSUN,FS_BOLD); $graph->xaxis->SetTickLabels($gDateLocale->GetShortMonth()); $graph->Stroke(); //輸出圖像 ?>
柱狀圖
<?php require_once ("jpgraph/jpgraph.php"); require_once ("jpgraph/jpgraph_bar.php"); $data = array(19,23,34,38,45,67,71,78,85,87,96,145); $ydata = array("一","二","三","四","五","六","七","八","九","十","十一","十二"); $graph = new Graph(500,300); //創建新的Graph對象 $graph->SetScale("textlin"); //刻度樣式 $graph->SetShadow(); //設置陰影 $graph->img->SetMargin(40,30,40,50); //設置邊距 $graph->graph_theme = null; //設置主題為null,否則value->Show(); 無效 $barplot = new BarPlot($data); //創建BarPlot對象 $barplot->SetFillColor('blue'); //設置顏色 $barplot->value->Show(); //設置顯示數字 $graph->Add($barplot); //將柱形圖添加到圖像中 $graph->title->Set("CDN流量圖"); $graph->xaxis->title->Set("月份"); //設置標題和X-Y軸標題 $graph->yaxis->title->Set("流 量(Mbits)"); $graph->title->SetColor("red"); $graph->title->SetMargin(10); $graph->xaxis->title->SetMargin(5); $graph->xaxis->SetTickLabels($ydata); $graph->title->SetFont(FF_SIMSUN,FS_BOLD); //設置字體 $graph->yaxis->title->SetFont(FF_SIMSUN,FS_BOLD); $graph->xaxis->title->SetFont(FF_SIMSUN,FS_BOLD); $graph->xaxis->SetFont(FF_SIMSUN,FS_BOLD); $graph->Stroke(); ?>
餅狀圖
<?php require_once ("jpgraph/jpgraph.php"); require_once ("jpgraph/jpgraph_pie.php"); require_once ("jpgraph/jpgraph_pie3d.php"); $data = array(19,23,34,38,45,67,71,78,85,87,90,96); $graph = new PieGraph(550,500); $graph->SetShadow(); $graph->title->Set("CDN流量比例"); $graph->title->SetFont(FF_SIMSUN,FS_BOLD); $pieplot = new PiePlot3D($data); //創建PiePlot3D對象 $pieplot->SetCenter(0.4, 0.5); //設置餅圖中心的位置 $pieplot->SetLegends($gDateLocale->GetShortMonth()); //設置圖例 $graph->Add($pieplot); $graph->Stroke(); ?>
感謝你能夠認真閱讀完這篇文章,希望小編分享的“PHP中jpgraph庫如何配置使用”這篇文章對大家有幫助,同時也希望大家多多支持億速云,關注億速云行業資訊頻道,更多相關知識等著你來學習!
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。