函數(shù)名 | 作用 |
---|---|
new Graph | 創(chuàng)建一個(gè)新的Graph對(duì)象 |
jpgraph_bar.php | 加載畫出圓柱的文件 |
jpgraph.php | 加載使用jp庫的文件 |
SetScale | 設(shè)置刻度樣式 |
new BarPlot | 創(chuàng)建一個(gè)新的BarPlot對(duì)象 |
SetFillColor | 用于指定條形的填充顏色 |
SetFont | 設(shè)置字體 |
xaxis -> Set | 設(shè)置x軸標(biāo)題 |
yaxis -> Set | 設(shè)置y軸標(biāo)題 |
title -> Set | 設(shè)置主標(biāo)題 |
Stroke | 輸出圖像 |
SetColor | 設(shè)置標(biāo)題顏色 |
SetMargin | 設(shè)置間距 |
SetTickLabels | 獲取數(shù)組里的元素并輸出 |
value -> Show | 顯示值 |
graph_theme | 設(shè)置主題 |
這是我們本次需要用到的一些函數(shù),鑒于我的表達(dá)能力不是特別好,你們覺得有點(diǎn)看不懂的話,可以去看一下別的博客來幫助自己理解
首先,我們要輸出的是圓柱,那么我們則要輸入
require_once ("jpgraph/src/jpgraph.php"); require_once ("jpgraph/src/jpgraph_bar.php");
ok,這個(gè)時(shí)候文件已經(jīng)加載了,為了避免你們目錄和我不一致導(dǎo)致報(bào)錯(cuò)無法實(shí)現(xiàn),我把我的文件存在位置截了下來,如下:
接下來,我們要?jiǎng)?chuàng)建兩個(gè)數(shù)組,一個(gè)是圓柱數(shù)據(jù),另一個(gè)是x軸標(biāo)題數(shù)據(jù)
$date = array(19,23,34,38,45,67,71,78,85,87,90,96);//此處是圓柱數(shù)據(jù) $xdate = array("1","2","3","4","5","6","7","8","9","10","11","12");//此處是x軸的標(biāo)題數(shù)據(jù)
這個(gè)時(shí)候,我們已經(jīng)完成了我們繪制圖形所需要的數(shù)據(jù)了,接下來就是創(chuàng)建圓柱和調(diào)整它的顏色了
所要做的代碼如下:
$graph = new Graph (500,400);//創(chuàng)建一個(gè)新的Graph對(duì)象,其寬和高分別為500,300 $graph -> SetScale("textlin");//設(shè)置其刻印樣式 $graph -> SetShadow();//設(shè)置其陰影樣式 $graph -> img -> SetMargin(40,30,40,50);//設(shè)置其上間距40,右間距30,下間距40,左間距50 $graph -> graph_theme = null;//設(shè)置他的主題為空,使得下面的元素可實(shí)現(xiàn) $bplot = new BarPlot ($date);//創(chuàng)建BarPlot對(duì)象 $bplot -> SetColor("pink");//設(shè)置BarPlot的顏色 $bplot -> value -> Show("");//顯示他的值 $graph ->Add($bplot);//把他的值放入$graph里 $graph -> title -> Set(iconv("utf-8","gb2312//IGNORE","年度收支表"));//設(shè)置標(biāo)題名字并進(jìn)行轉(zhuǎn)換 $graph -> xaxis -> title -> Set(iconv("utf-8","gb2312//IGNORE","月份"));//同上,設(shè)置x軸標(biāo)題 $graph -> yaxis -> title -> Set(iconv("utf-8","gb2312//IGNORE","總金額(兆美元)"));//同上,設(shè)置y軸標(biāo)題 $graph -> title -> SetColor("red");//設(shè)置標(biāo)題顏色 $graph -> title -> SetMargin(10);//設(shè)置標(biāo)題間距 $graph -> xaxis -> title -> SetMargin(1);//設(shè)置x軸標(biāo)題間距 $graph -> xaxis ->SetTickLabels($xdate);//接收xdate數(shù)組里的元素 $graph -> title -> SetFont(FF_SIMSUN,FS_BOLD);//設(shè)置字體樣式 $graph -> xaxis -> title ->SetFont(FF_SIMSUN,FS_BOLD); $graph -> yaxis -> title ->SetFont(FF_SIMSUN,FS_BOLD); $graph -> xaxis -> SetFont(FF_SIMSUN,FS_BOLD);//設(shè)置x軸里所有的字體樣式 $graph -> Stroke();//輸出
到這里,我們的圓柱就已經(jīng)完成了,完整的代碼如下:
?php require_once ("jpgraph/src/jpgraph.php"); require_once ("jpgraph/src/jpgraph_bar.php"); $date = array(19,23,34,38,45,67,71,78,85,87,90,96); $xdate = array("1","2","3","4","5","6","7","8","9","10","11","12"); $graph = new Graph (500,400); $graph->SetScale("textlin"); $graph->SetShadow(); $graph->img->SetMargin(40,30,40,50); $graph->graph_theme = null; $barplot = new BarPlot($date); $barplot->SetFillColor("pink"); $barplot->value->Show(); $graph->Add($barplot); $graph->title->Set(iconv("utf-8","GB2312//IGNORE","年度收支表")); $graph->xaxis->title->Set(iconv("utf-8","GB2312//IGNORE","月份")); $graph->yaxis->title->Set(iconv("utf-8","GB2312//IGNORE","總金額(兆美元)")); $graph->title->SetColor("red"); $graph->title->SetMargin(10); $graph->xaxis->title->SetMargin(1); $graph->xaxis->SetTickLabels($xdate); $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(); ?>
最終效果如下圖:
更多關(guān)于PHP相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《PHP圖形與圖片操作技巧匯總》、《PHP基本語法入門教程》、《php面向?qū)ο蟪绦蛟O(shè)計(jì)入門教程》、《PHP網(wǎng)絡(luò)編程技巧總結(jié)》、《PHP數(shù)組(Array)操作技巧大全》、《php字符串(string)用法總結(jié)》、《php+mysql數(shù)據(jù)庫操作入門教程》及《php常見數(shù)據(jù)庫操作技巧匯總》
希望本文所述對(duì)大家PHP程序設(shè)計(jì)有所幫助。
標(biāo)簽:宜賓 黃南 銅川 婁底 湛江 寶雞 鎮(zhèn)江 南陽
巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《PHP使用JPGRAPH制作圓柱圖的方法詳解》,本文關(guān)鍵詞 PHP,使用,JPGRAPH,制作,圓柱,;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問題,煩請(qǐng)?zhí)峁┫嚓P(guān)信息告之我們,我們將及時(shí)溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無關(guān)。