Menggunakan OpenFlashChart pada CodeIgniter

Seperti kita ketahui OpenFlashChart adalah tool cantik untuk membuat flash chart. OpenFlashChart bersifat opensource sehingga kita bebas menggunakan, menyebarkan dan memodifikasinya :) ..

Kali ini saya mencoba untuk berbagi pengalaman mengenai penggunaan OpenFlashChart pada CodeIgniter (sebagai library). Tentang bagaimana menggunakan OpenFlashChart itu sendiri anda bisa melihatnya di http://teethgrinder.co.uk/open-flash-chart/ .

Mohon koreksinya bila dalam entry ini terdapat kesalahan, mohon maaf juga kalau topiknya usang ....

Menggunakan OpenFlashChart sebagai Library di CI

- Download OpenFlashChart di http://teethgrinder.co.uk/open-flash-chart/
- Buat folder pada CI root assets/
--swf/
--js/
- Extract OpenFlashChart to temporary folder
- Copy file php-ofc-library/open-flash-chart.php ke system/application/library/ lalu rename menjadi graph.php
- Copy file open-flash-chart.swf ke assets/swf/
- Copy file js/swfobject.js ke assets/js/
- Edit file graph.php, temukan baris :
$this->js_path = 'js/';
$this->swf_path = '';
Edit menjadi :
$this->js_path = base_url().'assets/js/';
$this->swf_path = base_url().'assets/swf/';

- Contoh penggunaan :

Contoller :

<?php if (!defined('BASEPATH')) exit('No direct script access allowed');


Class 
Statistic extends Controller {
    
    function 
Statistic(){
        
parent::Controller();
        
//$this->freakauth_light->check('user');
        
        //load the models
        
$this->load->model('vouchermodel');
        
$this->load->model('postpaidmodel');
        
$this->load->model('billingplanmodel');
        
$this->load->model('statisticmodel');
        
        
//load radius helpers
        
$this->load->helper('radius');
    }
    
    function 
index(){
        
//security check
        
$this->freakauth_light->check('user');
        
        
$this->load->library('graph');
        
        
//get billingplan 
        
$bp_qty = array();
        
$bp_label = array();
        
$data['billingplans'] = $this->billingplanmodel->getBillingPlanStat();
        foreach (
$data['billingplans']->result() as $billingplan) {
            
$bp_qty[geshifilter-] = $billingplan-&gt;qty;
            
$bp_label[] = $billingplan-&gt;billingplan;
        }
        
        
//PIE chart, 60% alpha
        //
        
$this-&gt;graph-&gt;pie(80,'#505050','{font-size: 12px; color: #404040;');
        
//
        // pass in two arrays, one of data, the other data labels
        //
        
$this-&gt;graph-&gt;pie_values$bp_qty$bp_label );
        
//
        // Colours for each slice, in this case some of the colours
        // will be re-used (3 colurs for 5 slices means the last two
        // slices will have colours colour[0] and colour[1]):
        //
        
$this-&gt;graph-&gt;pie_slice_colours( array('#d9db35','#487daf','#d00000','#4ae331') );

        
$this-&gt;graph-&gt;set_tool_tip'#val# Vouchers' );
        
$this-&gt;graph-&gt;bg_colour '#040404';
        
$this-&gt;graph-&gt;title'Voucher Created''{font-size:14px; color: #7F7772}' );
        
$this-&gt;graph-&gt;set_output_type('js');
        
                
        
//get the vouchers data
        
$data['voucher'] = $this-&gt;vouchermodel-&gt;getVoucherStatistics();
        
        
//get the postpaid account data
        
$data['postpaid'] =  $this-&gt;postpaidmodel-&gt;getAccountStatistic();
        
        
//get the who's online list
        
$data['onlineuser'] = radius_get_online_users();
        
        
$data['title'] = &quot;Hotspot Statistics&quot;;
        
$data['h1'] = &quot;Hotspot Statistics&quot;;
        
        
//$this-&gt;output-&gt;enable_profiler();
        
        
$this-&gt;load-&gt;view('statistic/statistic_view',$data);
    }
    
}

?&
gt;
&
lt;/code&gt;
view :
&
lt;code&gt;
&
lt;?php $this-&gt;load-&gt;view('header') ?&gt;

&
lt;h1&gt;&lt;?=$h1?&gt;&lt;/h1&gt;

&
lt;div id='voucher_info'&gt;
&
lt;h3&gt;Vouchers Info&lt;/h3&gt;
&
lt;ul&gt;
    &
lt;li&gt;&lt;label&gt;Vouchers Created&lt;/label&gt;&lt;?=$voucher['created']?&gt;&lt;/li&gt;
    &
lt;li&gt;&lt;label&gt;Used&lt;/label&gt;&lt;?=$voucher['used']?&gt;&lt;/li&gt;
    &
lt;li&gt;&lt;label&gt;Expired&lt;/label&gt;&lt;?=$voucher['expired']?&gt;&lt;/li&gt;
&
lt;/ul&gt;
&
lt;h3&gt;Billing Plans&lt;/h3&gt;
&
lt;ul&gt;
    &
lt;?php foreach($billingplans-&gt;result() as $row):?&gt;
    &
lt;li&gt;&lt;label&gt;&lt;?=$row-&gt;billingplan?&gt;&lt;/label&gt;&lt;?=$row-&gt;qty?&gt;&lt;/li&gt;
    &
lt;?php endforeach; ?&gt;
&
lt;/ul&gt;
        &
lt;div id='graph'&gt;
            &
lt;?=$this-&gt;graph-&gt;render()?&gt;
        &
lt;/div&gt;
&
lt;/div&gt;


&
lt;div id='postpaid_info'&gt;
&
lt;h3&gt;Postpaid Account Info&lt;/h3&gt;
&
lt;ul&gt;
    &
lt;li&gt;&lt;label&gt;Account Created&lt;/label&gt;&lt;?=$postpaid['created']?&gt;&lt;/li&gt;
    &
lt;li&gt;&lt;label&gt;Used&lt;/label&gt;&lt;?=$postpaid['used']?&gt;&lt;/li&gt;
&
lt;/ul&gt;
&
lt;/div&gt;


&
lt;? $this-&gt;load-&gt;view('footer'); ?&gt;
&
lt;/code&gt;

lebih lanjut cara menggunakan openflashchart bisa dilihat di <a href="http://teethgrinder.co.uk/open-flash-chart/" title="http://teethgrinder.co.uk/open-flash-chart/">http://teethgrinder.co.uk/open-flash-chart/</a> .
Selamat Mencoba[/geshifilter-]?>