|
|
茫茫網海中的冷日
發生過的事,不可能遺忘,只是想不起來而已! |
|
恭喜您是本站第 1729362
位訪客!
登入 | 註冊
|
|
|
|
發表者 |
討論內容 |
冷日 (冷日) |
發表時間:2010/2/10 3:05 |
- Webmaster

- 註冊日: 2008/2/19
- 來自:
- 發表數: 15771
|
- [分享]讓php jpgraph支持中文的例子
- 讓php jpgraph支持中文的例子
以前用PHP作圖時必須要掌握複雜抽像的畫圖函數,或者借助一些網上下載的花柱形圖、餅形圖的類來實現。沒有一個統一的chart類來實現圖表的快速開發。
JpGraph就是解決這個問題的一個不錯的類庫。
jpgraph的官網:http://www.aditus.nu/jpgraph/
最新版本:支持PHP4的v1.2、支持PHP5的v3。
讓php jpgraph支持中文的例子
PHP:
<?php
include (./graph/jpgraph.php);
include (./graph/jpgraph_bar.php);
// Some data
$databary=array(152,7,16,5,7,14,9,3);
$databarx= array(中文,德文, hi, d,dddd,a,b,e) ;
// New graph with a drop shadow
$graph = new Graph(300,200,auto);
//$graph->SetShadow();
// Use a text X-scale
$graph->SetScale(textlin);
/**
* X坐標的內容
*/
$graph->xaxis->SetTickLabels($databarx);
//$graph->xaxis->SetTextLabelInterval(3);
$graph->xaxis->SetFont(FF_SIMSUN,FS_NORMAL);
// Set title and subtitle
$graph->title->Set(測試數據);
// Use built in font
/**
* 使用中文字體支持中文的顯示
*/
$graph->title->SetFont(FF_SIMSUN,FS_BOLD,14);
// create the bar plot
$b1 = new BarPlot($databary);
/**
* 這個是 圖例
*/
$b1->SetLegend(Temperature);
/**
* 這個是 柱狀的寬度
*/
$b1->SetAbsWidth(6);
/**
* 這個是 柱狀的投影, 不要
*/
//$b1->SetShadow();
// The order the plots are added determines whos ontop
$graph->Add($b1);
// Finally output the image
$graph->Stroke();
?>
注意,如果使用的是linux服務器,如果沒有安裝truetype字體,則需要上傳相關的字體到linux的/usr/X11R6/lib/X11/fonts/truetype目錄,上面的例子就需要傳
/usr/X11R6/lib/X11/fonts/truetype/simhei.ttf
/usr/X11R6/lib/X11/fonts/truetype/simsun.ttc
原文出處:讓php jpgraph支持中文的例子
|
|
|
討論串
|