Re: [請益] 關於PHP圓餅圖...
如果只是單純把資料來源從資料庫改成陣列的話...
先把關於db的程式碼都砍掉,也就是Deg2Arc函數之前以及"圓餅圖控制項結束"以後
再來就是修改類別pikelet的建構子,假設輸入的陣列像這樣子:
$res = array("taipei" => 20,"taichung" => 10, "taiwan" => 30);
建構子就可以這麼寫:
function pikelet($res, $length = 100) // 扇形建構子
{
$this->radius = $length; // 設定圓半徑
$this->num = count($res);
$this->sellData = array_values($res); // 產品銷售量
$this->productID = array_keys($res); // 產品序號
$this->DataTotal = array_sum($this->sellData); // 總銷售量
//******************************圓餅圖控制項開始**********************
}
再來就可以使用類別了。用法跟範例一樣,如:
$res = array("taipei" => 20,"taichung" => 10, "taiwan" => 30);
header("Content-type: image/png");
$pie = new pikelet($res); // 宣告 pie 為一個 pikelet 物件
$pie->DrawPie();
以上~
個人是覺得類別的屬性名稱可以換一下比較好讀XD
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 221.169.118.182
推
10/14 21:44, , 1F
10/14 21:44, 1F
討論串 (同標題文章)
完整討論串 (本文為第 2 之 2 篇):
1
5
PHP 近期熱門文章
PTT數位生活區 即時熱門文章