日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

jpgraph 实例文档

發布時間:2025/6/16 编程问答 31 豆豆
生活随笔 收集整理的這篇文章主要介紹了 jpgraph 实例文档 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
下載
在官方網站?http://www.aditus.nu/jpgraph/?下載jpgraph,其中1.X系列是用于PHP4的,2.X系列是用于PHP5的。

安裝
將下載的得到的jpgraph壓縮文件解壓至相應的路徑。 配置
首先需要注意的是:要想適用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.ttfsimsun.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.4\src\Examples中的例子。下面是一些常用的:
$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 = new Graph(500,300);????????????????????????????????????????????????????//創建新的Graph對象 $graph->SetScale("textlin");????????????????????????????????????????????????????//設置刻度樣式 $graph->img->SetMargin(30,30,80,30);????????????????????//設置圖表邊界 $graph->title->Set("CDN Traffic Total");????????//設置圖表標題 $graph->title->SetColor("blue"); $graph->title->SetMargin(20); // Create the linear plot $lineplot=new LinePlot($data);??????????????//?創建新的LinePlot對象 $lineplot->SetLegend("Line(Mbits)");???//設置圖例文字 $lineplot->SetColor("red");?????????????????//?設置曲線的顏色 // Add the plot to the graph $graph->Add($lineplot);?????????????????????//在統計圖上繪制曲線 // Display the graph $graph->Stroke();?????????????????????????//輸出圖像 ?>

例2. php Jpgraph繪制復雜的X-Y坐標圖

<?php include ("../jpgraph.php"); include ("../jpgraph_line.php"); $data1 = array(523,634,371,278,685,587,490,256,398,545,367,577);????????????????//第一條曲線的數組 $data2 = array(19,23,34,38,45,67,71,78,85,87,90,96);????????????????????????????????????//第二條曲線的數組 $graph = new Graph(500,300,auto);???????????????????????????????????????????????????????????????????????????????//創建新的Graph對象 $graph->SetScale("textlin"); $graph->SetShadow();????????????????????????????????????????????????????????????????????????????????????//設置圖像的陰影樣式 $graph->img->SetMargin(60,30,30,70);????????????????????????????????????????????????????????????//設置圖像邊距 $graph->title->Set("CDN流量圖");????????????????????????????????????????????????//設置圖像標題 $graph->title->SetMargin(10); $lineplot1=new LinePlot($data1);????????????????????????????????????????????????????????????????????????//創建設置兩條曲線對象 $lineplot2=new LinePlot($data2); $lineplot1->value->Show(); $lineplot1->value->SetColor("black"); $graph->Add($lineplot1);????????????????????????????????????????????????????????????????????????????????????????//將曲線放置到圖像上 $graph->Add($lineplot2); $graph->xaxis->title->Set("月份");??????????????????????????????????????????????????????????????????????//設置坐標軸名稱 $graph->yaxis->title->Set("?(Gbits)"); $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()); $lineplot1->SetColor("red");????????????????????????????????????????????????????????????????????????????//設置顏色 $lineplot2->SetColor("blue"); $lineplot1->SetLegend("Max");???????????????????????????????????????????????????????????//設置圖例名稱 $lineplot2->SetLegend("Min"); $graph->legend->SetLayout(LEGEND_HOR);??????????????????????????????????????????????????//設置圖例樣式和位置 $graph->legend->Pos(0.5,0.96,"center","bottom"); $graph->Stroke();???????????????????????????????????????????????????????????????????????????????????????????????//輸出圖像 ?>

例3. php Jpgraph繪制柱形圖

<?php include ("../jpgraph.php"); include ("../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);????????????????????????//設置邊距 $barplot = new BarPlot($data);??????????????????????????????????????????????????????????//創建BarPlot對象 $barplot->SetFillColor('blue');?????????????????????????????????????????????????????????//設置顏色 $barplot->value->Show();????????????????????????????????????????????????????????????????????????????????????????//設置顯示數字 $graph->Add($barplot);???????????????????????????????????????????????????????????????????????????????????????//將柱形圖添加到圖像中 $graph->title->Set("CDN流量圖");????????????????????????????????????????????????????????????????????????//設置標題和X-Y軸標題 $graph->title->SetColor("red"); $graph->title->SetMargin(10); $graph->xaxis->title->Set("月份"); $graph->xaxis->title->SetMargin(5); $graph->xaxis->SetTickLabels($ydata); $graph->yaxis->title->Set("?(Mbits)"); $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(); ?>

例4. php Jpgraph繪制餅圖

<?php include ("../jpgraph.php"); include ("../jpgraph_pie.php"); $data = array(19,23,34,38,45,67,71,78,85,87,90,96); $lable_data = range(1,12); $graph = new PieGraph(400,300); $graph->SetShadow(); $graph->title->Set("CDN流量比例"); $graph->title->SetFont(FF_SIMSUN,FS_BOLD); $pieplot = new PiePlot($data); $pieplot->SetLegends($lable_data); $pieplot->SetCenter(0.4); $graph->Add($pieplot); $graph->Stroke(); ?>

例5. php Jpgraph繪制3D餅圖

<?php include ("../jpgraph.php"); include ("../jpgraph_pie.php"); include ("../jpgraph_pie3d.php"); $data = array(19,23,34,38,45,67,71,78,85,87,90,96); $graph = new PieGraph(550,400); $graph->SetShadow(); $graph->title->Set("CDN流量比例"); $graph->title->SetFont(FF_SIMSUN,FS_BOLD); $pieplot = new PiePlot3D($data);????????????????????????????????????????????????????????????????????????//創建PiePlot3D對象 $pieplot->SetCenter(0.4);???????????????????????????????????????????????????????????????????????????????????????????????????????// 置餅圖中心的位置 $pieplot->SetLegends($gDateLocale->GetShortMonth());????????????//設置圖例 $graph->Add($pieplot); $graph->Stroke(); ?>

例6.

index.html <html> <head> <title>CDN流量查詢系統統計</title> <meta http-equiv="Content-Type" content="text/html; charset=gb2312"> <mce:style type="text/css"><!-- .style1 { font-size: 16px; font-weight: bold; } --></mce:style><style type="text/css" mce_bogus="1">.style1 { font-size: 16px; font-weight: bold; }</style> </head> <body> <form name="form1" method="get" action="result.php"> <p align="center" class="style1"> CDN流量查詢系統統計</p> <table width="300" border="1" align="center" cellpadding="3" cellspacing="3"> <tr> <td width="85"><strong>查詢年份</strong></td> <td width="188"><select name="acct_yr" id="acct_yr"> <option value="2009" selected>2008</option> <option value="2009" selected>2009</option> </select></td> </tr> <tr> <td><strong>起始月份</strong></td> <td><select name="start_mth" id="start_mth"> <option selected>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><select name="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> <option selected >12</option> </select></td> </tr> <tr> <td><strong>統計圖類別</strong></td> <td><select name="graph" id="graph"> <option value="1" selected>線型圖</option> <option value="2">柱形圖</option> <option value="3">餅圖</option> <option value="4">3D餅圖</option> </select></td> </tr> </table> <p align="center"> <input type="submit" value="Submit"> <input type="reset" name="Submit2" value="Reset"> </p> </form> </body> </html> result.php <?php include ("../jpgraph.php"); include ("../jpgraph_line.php"); include ("../jpgraph_bar.php"); include ("../jpgraph_pie.php"); include ("../jpgraph_pie3d.php"); $conn = mysql_connect("localhost", "root", "woxiangnileyali");?????????//連接數據庫 $acct_yr = $_GET['acct_yr'];????????????????????????????//獲取年份 $start_mth = $_GET['start_mth'];??????????????????????//獲取超始月份 $end_mth = $_GET['end_mth'];?????????????????????????//獲取結束月份 $choose = $_GET['graph'];????????????????????????//獲取圖形類型 mysql_select_db("test", $conn);????????????????????????????????//執行SQL,?獲得銷量值 $query_rs_prod = "SELECT acct_mth, amount FROM traffic WHERE acct_yr = '$acct_yr' and acct_mth between '$start_mth' and '$end_mth'"; $rs_prod = mysql_query($query_rs_prod, $conn) or die(mysql_error()); $row_rs_prod = mysql_fetch_assoc($rs_prod); $totalRows_rs_prod = mysql_num_rows($rs_prod); $data = array(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);???????????????????//初始化數組 do????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????//循環設置各月份數值 { $i = (int)$row_rs_prod['acct_mth']-1; $data[$i] = $row_rs_prod['amount']; } while($row_rs_prod = mysql_fetch_assoc($rs_prod)); switch($choose) { case 1: $graph = new Graph(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=new LinePlot($data); $lineplot->SetLegend("Line"); $lineplot->SetColor("red"); $graph->Add($lineplot); break; case 2: $graph = new Graph(400,300);???? $graph->SetScale("textlin");????????? $graph->SetShadow();????????? $graph->img->SetMargin(40,30,20,40); $barplot = new BarPlot($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; case 3: $graph = new PieGraph(400,300); $graph->SetShadow(); $graph->title->Set("CDN流量查詢"); $graph->title->SetFont(FF_SIMSUN,FS_BOLD); $pieplot = new PiePlot($data); $pieplot->SetLegends($gDateLocale->GetShortMonth());??????????//設置圖例 $graph->Add($pieplot); break; case 4: $graph = new PieGraph(400,300); $graph->SetShadow(); $graph->title->Set("CDN流量查詢"); $graph->title->SetFont(FF_SIMSUN,FS_BOLD); $pieplot = new PiePlot3D($data);??????????????????????????????????????????????????????????//創建PiePlot3D對象 $pieplot->SetCenter(0.4);??????????????????????????????????????????????????????????????????????????????????????????//設置餅圖中心的位置 $pieplot->SetLegends($gDateLocale->GetShortMonth());??????????//設置圖例 $graph->Add($pieplot); break; default: echo "graph參數錯誤"; exit; } $graph->Stroke(); ?>








本文出自 “壞男孩” 博客,請務必保留此出處http://5ydycm.blog.51cto.com/115934/177498








本文轉自yunlielai51CTO博客,原文鏈接:http://blog.51cto.com/4925054/1104459,如需轉載請自行聯系原作者

總結

以上是生活随笔為你收集整理的jpgraph 实例文档的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。