StarniC's Blog
|
|||
สร้างกราฟด้วย PHP เรื่องของเรื่องคืออยากได้วิธีสร้างกราฟด้วย PHP แล้วก็ search ไปเจอวิธีใน google เข้า ส่วนนี้ copy มาจาก //www.binarywebhost.com/forum/index.php?topic=2.msg2 เริ่มแรกเราต้องทำให้ PHP เรียกใช้ Graphic Library ที่เรียกว่า GD ให้ได้ก่อน โดยทำการค้นหาไฟล์ php.ini (สำหรับ Windows จะอยู่ที่ C:WINDOWSphp.ini ส่วน Linux ปกติจะอยู่ที่ /etc/php.ini) จากนั้นเปิดไฟล์ขึ้นมาเพื่อแก้ไข พอเข้าไปที่ jpgraph ก็ให้ดาวน์โหลด ต่อไปเป็นวิธีเซตให้แสดงภาษาไทยได้ การเซ็ต jpgraph ให้แสดงภาษาไทย 1.เข้าไปในไฟล์ jpgraph_ttf.inc.php ค้นหา // Actual name of the TTF file used together with FF_CHINESE aka FF_BIG5 // This is the TTF file being used when the font family is specified as // either FF_CHINESE or FF_BIG5 define('CHINESE_TTF_FONT','bkai00mp.ttf'); เพิ่ม ต่อจากด้านบน define('CORDIA_TTF_FONT', 'cordia.ttf'); define('CORDIAB_TTF_FONT', 'cordiab.ttf'); define('CORDIAI_TTF_FONT', 'cordiai.ttf'); define('CORDIAZ_TTF_FONT', 'cordiaz.ttf'); define('ANGSA_TTF_FONT', 'ANGSA.ttf'); define('ANGSAB_TTF_FONT', 'ANGSAB.ttf'); define('ANGSAI_TTF_FONT', 'ANGSAI.ttf'); define('ANGSAZ_TTF_FONT', 'ANGSAZ.ttf'); define('BROWA_TTF_FONT', 'BROWA.ttf'); define('BROWAB_TTF_FONT', 'BROWAB.ttf'); define('BROWAI_TTF_FONT', 'BROWAI.ttf'); define('BROWAZ_TTF_FONT', 'BROWAZ.ttf'); ค้นหา (จะอยู่ใน class TTF) /* Chinese fonts */ FF_SIMSUN => array( FS_NORMAL =>'simsun.ttc', FS_BOLD =>'simhei.ttf', FS_ITALIC =>'', FS_BOLDITALIC =>'' ), FF_CHINESE => array( FS_NORMAL =>CHINESE_TTF_FONT, FS_BOLD =>'', FS_ITALIC =>'', FS_BOLDITALIC =>'' ), เพิ่ม ต่อจากด้านบน /* Thai fonts */ FF_CORDIA => array( FS_NORMAL=>CORDIA_TTF_FONT, FS_BOLD=>CORDIAB_TTF_FONT, FS_ITALIC=>CORDIAI_TTF_FONT, FS_BOLDITALIC=>CORDIAZ_TTF_FONT ), FF_ANGSA => array(FS_NORMAL=>ANGSA_TTF_FONT, FS_BOLD=>ANGSAB_TTF_FONT, FS_ITALIC=>ANGSAI_TTF_FONT, FS_BOLDITALIC=>ANGSAZ_TTF_FONT ), FF_BROWA => array(FS_NORMAL=>BROWA_TTF_FONT, FS_BOLD=>BROWAB_TTF_FONT, FS_ITALIC=>BROWAI_TTF_FONT, FS_BOLDITALIC=>BROWAZ_TTF_FONT ), 2.เข้าไปในไฟล์ jpgraph.php ค้นหา // For internal use only define("_JPG_DEBUG",false); define("_FORCE_IMGTOFILE",false); define("_FORCE_IMGDIR",'/tmp/jpgimg/'); เพิ่ม ต่อจากด้านบน //thai font define("FF_ANGSA",18); define("FF_CORDIA",19); define("FF_BROWA",20); 3.เข้าไปในไฟล์ gd_image.inc.php เพิ่ม ไว้ส่วนบนๆ ต่อจาก require_once ก็ได้ //thai font define("FF_ANGSA",18); define("FF_CORDIA",19); define("FF_BROWA",20); 4.วิธีใช้ - เปลี่ยนค่าตรง SetFont เป็น SetFont(FF_ANGSA,FS_BOLD,20); ตัวเลขเป็นขนาดตัวอักษร - ข้อความที่จะแสดงให้แปลงเป็น UTF-8 ด้วย ตัวอย่าง // Setup the titles // แบบที่ 1 $title = iconv('TIS-620','UTF-8',"แสดงกราฟภาษาไทย"); $graph->title->Set($title); // แบบที่ 2 $graph->xaxis->title->Set(iconv('TIS-620','UTF-8',"แกน X")); $graph->yaxis->title->Set(iconv('TIS-620','UTF-8',"แกน Y")); ปล. 1 จะใช้กราฟรูปแบบไหน ก็เอา code จาก jpgraph/src/Examples มาปรับใช้ ปล. 2 เอามาลง blog เพื่อไว้เตือนตัวเองจ๊ะ ไม่ได้จะหาประโยชน์ มีอะไรก็แบ่งๆ กานนนน ------------------------------------------------------------- เพิ่มเติมภาพที่ได้จากการปรับให้แสดงภาษาไทย |
StarniC
Rss Feed Smember ผู้ติดตามบล็อก : 1 คน [?] Group Blog All Blog Friends Blog |
||
Pantip.com | PantipMarket.com | Pantown.com | © 2004 BlogGang.com allrights reserved. |
//faker-programmer.blogspot.com/2009/06/php.html