บทความ

กำลังแสดงโพสต์จาก กุมภาพันธ์, 2015

Jfree Chart วิธีทำ Custome Label ให้กับ Pie Chart

บทความเกี่ยวกับ : Jfree Chart วิธีทำ Custome Label ให้กับ Pie Chart วันนี้เจอโจทย์ยากมา ให้ทำ กราฟใหม่ แบบว่าต้อง Custom กัน นิสนุง ปรกติเราก็แสดงแบบ ตาม default ของมันอ่ะนะ ใน jfreechart  มันก็ง่ายๆ แค่ set Key , Value เข้าไปมันก็แสดงออกมาตามนั้นแหละ แต่วันนี้เรามีความจำเป็นต้อง ตกแต่งในส่วนของ Value มันซักหน่อย พูดง่ายๆ ว่าจัด format มันนั่นเอง วิธีการคือ ใช้ตัวนี้ครับ PieSectionLabelGenerator   ตัวนี้เป็น Interface นะครับ เราต้องสร้าง Class มาแล้ว implement method นี้ generateSectionLabel ตามตัวอย่าง static class CustomLabelGenerator implements PieSectionLabelGenerator {           public String generateSectionLabel (final PieDataset dataset, final Comparable key) {             String result = null;                if (dataset != null) {                    //Custom result ได้ตามสบาย จากตัวอย่างเราจะให้มันแสดงแค่ key                     result = key.toString();               }             return result;         }     } จากนั้นตอนเรียกใช้ก็ตามนี้