程式碼如下:
// 引用相關類別檔
include("class/pDraw.class.php");
include("class/pImage.class.php");
include("class/pData.class.php");
// 使用圓餅圖需要引入這個類別檔
include("class/pPie.class.php");
// 建立資料集物件
$myData = new pData();
// 在資料集中新增資料
// 設定資列數列
$myData->addPoints(array(550,320,300,150,120));
// 新增一筆資料數列,並命名為 Area
$myData->addPoints(array("北部","中部", "南部", "東部", "離島"), "Area");
// 將 Area 設定為橫座標
$myData->setAbscissa("Area");
// 建立一個圖形物件,設立它的尺寸及相關的資料集
$myPicture = new pImage(400,400,$myData);
// 指定圖形中使用的字型和字體大小
$myPicture->setFontProperties(array("FontName"=>"fonts/NotoSansCJKtc-Regular.otf","FontSize"=>12));
// 畫出圖表的外框
$myPicture->drawRectangle(0,0,399,399);
// 畫出圖表的標題區域
$RectangleSettings = array("R"=>0,"G"=>0,"B"=>0);
$myPicture->drawFilledRectangle(0,0,400,25,$RectangleSettings);
// 寫出圖表的標題
$myPicture->drawText(150,22,"區域分布圖",array("R"=>255,"G"=>255,"B"=>255));
$PieChart = new pPie($myPicture,$myData);
// 設定圓餅圖在圖形中的位置及設定
$settings = array(
"Radius"=>120, // 圓餅圖半徑
"Border" => TRUE, // 區塊的框線
"DrawLabels"=>TRUE, // 畫出標籤
"WriteValues" => true, // 標示數值
"ValuePosition" => PIE_VALUE_INSIDE, // 數值的位置
);
$PieChart->draw2DPie(200,200, $settings);
// 如果我們要將生成的 png 存檔,可以用以下的方式;如果只想單純顯示,此行可省略
$myPicture->render('example_04.png');
// 將圖形輸出到瀏覽器
$myPicture->autoOutput();

沒有留言:
張貼留言