:::

6. PHP圖表pChart

一、pChart(http://pchart.sourceforge.net)

1.pChart.class(圖表物件檔)、pData.class(資料物件檔)、pCache.class(快取物件檔)

include_once("pChart/pData.class");
include_once("pChart/pChart.class");

二、匯入資料的二種方式:

1.直接寫在程式中:AddPoint($資料值,$資料組名稱="Serie1",$資料組說明="")

$DataSet = new pData;
$DataSet->AddPoint(array(128673,2889,1376,830,170),"count","造訪次數");
$DataSet->AddPoint(array("台灣","香港","中國","美國","德國"),"country","國家");
$DataSet->AddAllSeries();
$DataSet->SetAbsciseLabelSerie();

2.從CSV檔匯入:ImportFromCSV($CSV檔來源,$分隔符=",",$資料從第幾欄開始=-1,$是否有標題=FALSE,$當作標籤的是第幾欄=-1)

$DataSet->ImportFromCSV("Sample/ck2.csv",",",array(3),TRUE,0);

三、繪製圖表

1.產生圖表物件:new pChart(寬,高);

2.設定標記字型;setFontProperties("字型",大小);

3.設定繪圖區域:setGraphArea($X1,$Y1,$X2,$Y2)  ;

4.繪製圖表:drawScale($Data,$DataDescription,$模式,$R,$G,$B,$顯示標籤=TRUE,$X軸標籤角度=0,$小數幾位=1,$圖在邊界內=FALSE,$略過幾個標籤=1,$RightScale=FALSE)

    (1) SCALE_NORMAL:取得資料組的最大和最小值
    (2) SCALE_START0:最小值從0開始
    (3) SCALE_ADDALL:取得資料組累積的最大和最小值
    (4) SCALE_ADDALLSTART0:取得資料組累積的最大值,最小從0開始

5.繪製標線:drawGrid($LineWidth,$Mosaic=TRUE,$R=220,$G=220,$B=220,$Alpha=255)

$Test = new pChart(700,230);
$Test->setFontProperties("Fonts/cwyen.ttf",8);
$Test->setGraphArea(50,30,680,200);
$Test->drawScale($DataSet->GetData(),$DataSet->GetDataDescription(),SCALE_NORMAL,150,150,150,TRUE,0,2,TRUE);
$Test->drawGrid(4,TRUE,230,230,230,50);


6.長條圖:drawBarGraph($Data,$DataDescription,$陰影=FALSE)

7.曲線圖:drawCubicCurve($Data,$DataDescription,$圓滑度)

8.折線圖:drawLineGraph($Data,$DataDescription)

9.點圖:drawPlotGraph(&$Data,&$DataDescription,$大半徑=5,$小半徑=2,$R2=-1,$G2=-1,$B2=-1,$陰影=FALSE)

10.圓餅圖:drawPieGraph($Data,$DataDescription,$X,$Y,$半徑,$繪製標籤=PIE_NOLABEL,$加強顏色=TRUE,$透視角度=60,$高度=20,$分開距離=0,$小數幾位=0)

$Test->drawBarGraph($DataSet->GetData(),$DataSet->GetDataDescription(),TRUE);

11.繪製說明表:drawLegend($X,$Y,$DataDescription,$R,$G,$B,$Rs=-1,$Gs=-1,$Bs=-1,$Rt=0,$Gt=0,$Bt=0,$邊框=FALSE)

$Test->drawLegend(350,50,$DataSet->GetDataDescription(),255,255,255);

12.產生圖片Render("$檔名");

$Test->Render("demo1.png");

四、網頁或PHP使用:

echo "<img src='demo1.png'>";


:::

搜尋

QR Code 區塊

https%3A%2F%2Ftad0616.cp22.secserverpros.com%2Fmodules%2Ftad_book3%2Fpage.php%3Ftbdsn%3D198%26tbsn%3D8

書籍目錄

展開 | 闔起

線上使用者

580人線上 (115人在瀏覽線上書籍)

會員: 0

訪客: 580

更多…