เขียนโปรแกรมกับ php แล้วจำเป็นต้องออกรายงานหรือ Graph แสดงข้อมูล ไม่อยากเสียเวลาเขียน function graph ให้วุ่นวาย ก็เรียกใช้บริการ jpgraph (http://www.aditus.nu/jpgraph/) ซึ่งมีรูปแบบของ graph ให้เลือกใช้อย่างมากมาย มากจนเลือกไม่ถูก แต่ไม่วายมีปัญหากับภาษาไทย ซะนี่ ออกมาเป็นภาษาต่างดาว
ทำงัยดีหล่ะ ต้องพึ่งพาพี่ Google และ document ของ jpgraph (http://www.aditus.nu/jpgraph/phptip04.php) ... กว่าจะได้ผลลัพธ์ตามต้องการก็ใช้เวลานิดหน่อย ดูรายละเอียดตามนี้เลยครับ ลองมาแล้วได้ผลจริงครับ
ใช้ jpgraph แล้วภาษาไทย ไม่ได้ ให้แก้ตามนี้ คือเพิ่ม font ภาษาไทย เข้าไปใน file
1. jpg-config.inc.php
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('TAHOMA_TTF_FONT', 'tahoma.ttf');
DEFINE('TAHOMAB_TTF_FONT', 'tahomabd.ttf');
2. jpgraph_ttf.inc.php
// Thai font ( Number 40-80 )
DEFINE("FF_ANGSA",47);
DEFINE("FF_CORDIA",48);
DEFINE("FF_TAHOMA",49);
และเพิ่มเติมใน class TTF ในไฟล์เดียวกัน
/* thai font */
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_TAHOMA => array(FS_NORMAL=>TAHOMA_TTF_FONT,
FS_BOLD=>TAHOMAB_TTF_FONT),
สำคัญอีกอย่างคือการแสดงผล ภาษาไทยใน graph ต้องแปลงให้เป็น unicode ก่อน เช่น
$title = iconv('TIS-620', 'UTF-8',"รายงาน Graph แสดงจำนวน");
ตัวอย่างเมื่อเรียกใช้งาน
<?php
ที่มา : narisa, jpgraph, และที่ google พาไป
ขอบคุณมากนะคะ
เนื้อหานี้ได้ copy มาจาก website หนึ่ง แต่จำไม่ได้แล้วว่าเอามาจากไหน ขอให้ credit คนเขียนคนแรกด้วยครับ. ขออภัยที่ไม่ได้อ้างถึงในตอนแรก
ดึงข้อมูลจาก database มาเขียนเป็นกราฟต้องทำยังไงค่ะ
รบกวนช่วยให้คำชี้เเนะ เพราะว่าเป็นมือใหม่อยู่อ่ะค่ะ
ขอบคุณครับ
ขอบคุณมากครับ **
ขอบคุณมากนะคะ ^^
มีประโยชน์ ขอบคุณครับ
เวลาผมใส่ค่าในแกน X จะเกิด Error ขึ้นครับ แต่ถ้าไม่ใส่($graph->xaxis->SetTickLabels($datax);
)รันได้ปกติ แต่แกน X จะขึ้นเป็นตัวเลขแทน คือผมต้องการให้ขึ้นเป็นตัวอักษรตามที่เรากำหนด เหมือนตัวอย่างที่พี่เขียนมาให้ดูครับ ไม่รู้จะแก้อย่างไง ขอความกรุณาด้วยครับ ผมใช้กราฟเบบบาร์เหมือนที่พี่เขียนเป็นตัวอย่าง ขอบคุณอย่างมากครับ
// We need some data
$datay=array(0.13,0.25,0.21,0.35,0.31,0.06);
$datax=array("Jan","Feb","Mar","Apr","May","June");
|
|
|
|
// Setup X-axis labels
$graph->xaxis->SetTickLabels($datax);
$graph->xaxis->SetLabelAngle(50);
ขอบคุณมากนะ
ขอบคุณมากครับ
JPGRAPH 3 ตอนนี้ทำภาษาไทยได้แล้ว
ขอบคุณครับ ไม่ได้ตาม update ตัวนี้นานเลยครับ
สุดยอดครับ JPGraph 3 ภาษาไทยได้ซะที
หุหุดีเลยครับ ขออนุญาต นำไปใช้นะครับ www.lamphuncenter.com
สำหรับคนที่ต้องการทราบว่าจะต้องเปลี่ยน font ที่ไหนบ้างลองดูที่นี่ครับ
แก้ยังไงค่ะ
Explanation:
HTTP headers have already been sent back to the browser indicating the data as text before the library got a chance to send it's image HTTP header to this browser. This makes it impossible for the library to send back image data to the browser (since that would be interpretated as text by the browser and show up as junk text).
Most likely you have some text in your script before the call to Graph::Stroke(). If this texts gets sent back to the browser the browser will assume that all data is plain text. Look for any text, even spaces and newlines, that might have been sent back to the browser.
For example it is a common mistake to leave a blank line before the opening "<?php".