PHP 板


LINE

› 看板 PHP  RSS
之前感謝這裡的高手 幫我改成可以使用正列顯示圓餅圖 但是因為我們是要使用中文介面顯示 所以現在我想要問...該如何使用中文 來顯示 圓餅圖裡的資料... 還有一個問題是 當資料量太小 EX:1 時 圓餅圖的角度會太小 資料會被蓋到 有沒有其他方法可以改善... 以下為程式碼 /********************************************************************* function Deg2Arc($degrees) { return($degrees * (pi()/180.0)); } // 定義一把角度轉換為弳度的函式 END // 定義一取得圓弧上之 x,y 點的函式 BEGIN function Center2Pie($deg,$length) { $x= cos(Deg2Arc($deg)) * $length; $y= sin(Deg2Arc($deg)) * $length; return (array($x, $y)); } // 定義一取得圓弧上之 x,y 點的函式 END class pikelet // 宣告一個 pikelet 的類別 { var $radius; // 圓半徑 var $DataArray; // 每個扇形所代表的資料 var $NumberData; var $place; // 序號 var $Number; // 總數 var $num; // 各數 function pikelet($res, $length = 100) // 扇形建構子 { $this->radius = $length; // 設定圓半徑 $this->num = count($res); $this->NumberData = array_values($res); // 產品銷售量 $this->place = array_keys($res); // 產品序號 $this->Number = array_sum($this->NumberData); // 總銷售量 } //******************************圓餅圖控制項開始********************** function DrawPie() // 畫圓餅圖 { $im = ImageCreate($this->radius*2+40,$this->radius*2+40); $PieCenterX=$this->radius+10; // 圓心 X座標 $PieCenterY=$this->radius+10; // 圓心 Y座標 $radius=$this->radius*2; // 圓半徑 // 定義所使欲使用的顏色 BEGIN $colorBorder = ImageColorAllocate($im, 0, 0, 0); // 黑 $colorback = ImageColorAllocate($im, 255, 255, 255); // 白 $colors[0] = ImageColorAllocate($im, 255, 128, 128); // 粉紅 $colors[1] = ImageColorAllocate($im, 100, 149, 237); // 粉藍 $colors[2] = ImageColorAllocate($im, 50, 205, 50); // 亮綠 $colors[3] = ImageColorAllocate($im, 244, 20, 190); // 紫 $colors[4] = ImageColorAllocate($im, 255, 215, 0); // 米黃 $colors[5] = ImageColorAllocate($im, 144, 238, 144); // 淺綠 $colors[6] = ImageColorAllocate($im, 70, 130, 180); // 海軍藍 $colors[7] = ImageColorAllocate($im, 244, 164, 96); // 棕 $colors[8] = ImageColorAllocate($im, 139, 121, 94); // 土 $colors[9] = ImageColorAllocate($im, 190, 190, 190); // 灰 // 定義所使欲使用的顏色 END ImageFill($im, 0, 0, $colorback); // 填充背景 // 開始畫每一個扇形 for($i=0;$i<$this->num;$i++) { // 四捨五入畫弧的起始角度 $StartDegrees = round($Degrees); // 累積角度 $Degrees += (($this->NumberData[$i] / $this->Number)*360); // 四捨五入畫弧的結束角度 $EndDegrees = round($Degrees); // 算出每一產品所佔的百分比 $percent = number_format(($this->NumberData[$i] / $this->Number)*100, 1); // 分配顏色 BEGIN $tmp_color = $i%10; // 取10的餘數 $CurrentColor = $colors[$tmp_color]; // 指定顏色 // 分配顏色 END // 畫扇形的弧 ImageArc($im, $PieCenterX, $PieCenterY, $radius, $radius, $StartDegrees, $EndDegrees, $CurrentColor); // 畫扇形的一邊直線 BEGIN list($ArcX, $ArcY) = Center2Pie($StartDegrees, $this->radius, $this->radius); ImageLine($im, $PieCenterX, $PieCenterY, floor($PieCenterX + $ArcX), floor($PieCenterY + $ArcY), $CurrentColor); // 畫扇形的一邊直線 END // 畫畫扇形的另一邊直線 BEGIN list($ArcX, $ArcY) = Center2Pie($EndDegrees, $this->radius, $this->radius); ImageLine($im, $PieCenterX, $PieCenterY, ceil($PieCenterX + $ArcX), ceil($PieCenterY + $ArcY), $CurrentColor); // 畫畫扇形的另一邊直線 END // 填充扇形 BEGIN $MidPoint = round((($EndDegrees - $StartDegrees)/2) + $StartDegrees); list($ArcX, $ArcY) = Center2Pie($MidPoint, $this->radius*3/4, $this->radius*3/4); ImageFilltoBorder($im, floor($PieCenterX + $ArcX), floor($PieCenterY + $ArcY), $CurrentColor, $CurrentColor); // 填充扇形 END // 寫上字串 ImageString($im, 2, floor($PieCenterX + $ArcX-20), floor($PieCenterY + $ArcY-2),$this->place[$i] . " - " . $this->NumberData[$i], $colorBorder); ImageString($im, 2, floor($PieCenterX + $ArcX-10), floor($PieCenterY + $ArcY-20), $percent . "%" , $colorback); // 寫上字串 END } Imagepng($im); // 做出png檔 ImageDestroy($im); // 移除圖形所佔的記憶體 } } //******************************圓餅圖控制項結束********************** $res = array("90分" => 1,"90~80分" => 5,"80~70分" => 10, "70~60分" => 10,"60以 下" => 17) ; mysql_close($link); header("Content-type: image/png"); $pie = new pikelet($res); // 宣告 pie 為一個 pikelet 物件 $pie->DrawPie(); /*******************************程式碼結束******************************** 這就是全部的程式碼 主要問題就是前面所說的那幾項囉... 1. 在陣列中 "分" 無法顯示 會變成亂碼顯示在圓餅圖中 2. 90分的人數只有1 在圓餅圖中的弧度太小 無法全部顯示 有無方法可以讓他全部顯示 主要就是這兩個問題了>< 拜託可以幫我想想辦法嗎 先謝謝各位了 >< --



※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 124.8.83.161 ※ 編輯: claire0810 來自: 124.8.83.161 (12/05 16:32) ※ 編輯: claire0810 來自: 124.8.83.161 (12/05 16:35) ※ 編輯: claire0810 來自: 124.8.83.161 (12/05 16:35)
1F:→ cttlee :ImageString換掉 12/05 18:17
2F:推 cttlee :imagettftext 12/05 18:19
改了之後程式會錯誤喔... ※ 編輯: claire0810 來自: 124.8.83.161 (12/05 18:59)
3F:→ cttlee :引數不太一樣自己對應一下 12/05 19:14
4F:→ crazybad :imagettftext只接受utf-8記得中文要先用iconv()去轉 12/06 21:28
5F:→ claire0810 :那這樣我要在哪裡改編碼方式呢? 12/07 17:38
6F:→ claire0810 :因為我現在連錯誤訊息都沒有了 12/07 17:38







like.gif 您可能會有興趣的文章
icon.png[問題/行為] 貓晚上進房間會不會有憋尿問題
icon.pngRe: [閒聊] 選了錯誤的女孩成為魔法少女 XDDDDDDDDDD
icon.png[正妹] 瑞典 一張
icon.png[心得] EMS高領長版毛衣.墨小樓MC1002
icon.png[分享] 丹龍隔熱紙GE55+33+22
icon.png[問題] 清洗洗衣機
icon.png[尋物] 窗台下的空間
icon.png[閒聊] 双極の女神1 木魔爵
icon.png[售車] 新竹 1997 march 1297cc 白色 四門
icon.png[討論] 能從照片感受到攝影者心情嗎
icon.png[狂賀] 賀賀賀賀 賀!島村卯月!總選舉NO.1
icon.png[難過] 羨慕白皮膚的女生
icon.png閱讀文章
icon.png[黑特]
icon.png[問題] SBK S1安裝於安全帽位置
icon.png[分享] 舊woo100絕版開箱!!
icon.pngRe: [無言] 關於小包衛生紙
icon.png[開箱] E5-2683V3 RX480Strix 快睿C1 簡單測試
icon.png[心得] 蒼の海賊龍 地獄 執行者16PT
icon.png[售車] 1999年Virage iO 1.8EXi
icon.png[心得] 挑戰33 LV10 獅子座pt solo
icon.png[閒聊] 手把手教你不被桶之新手主購教學
icon.png[分享] Civic Type R 量產版官方照無預警流出
icon.png[售車] Golf 4 2.0 銀色 自排
icon.png[出售] Graco提籃汽座(有底座)2000元誠可議
icon.png[問題] 請問補牙材質掉了還能再補嗎?(台中半年內
icon.png[問題] 44th 單曲 生寫竟然都給重複的啊啊!
icon.png[心得] 華南紅卡/icash 核卡
icon.png[問題] 拔牙矯正這樣正常嗎
icon.png[贈送] 老莫高業 初業 102年版
icon.png[情報] 三大行動支付 本季掀戰火
icon.png[寶寶] 博客來Amos水蠟筆5/1特價五折
icon.pngRe: [心得] 新鮮人一些面試分享
icon.png[心得] 蒼の海賊龍 地獄 麒麟25PT
icon.pngRe: [閒聊] (君の名は。雷慎入) 君名二創漫畫翻譯
icon.pngRe: [閒聊] OGN中場影片:失蹤人口局 (英文字幕)
icon.png[問題] 台灣大哥大4G訊號差
icon.png[出售] [全國]全新千尋侘草LED燈, 水草

請輸入看板名稱,例如:e-shopping 或 站內搜尋

TOP