Skip to main content

Menggunakan OpenFlashChart pada CodeIgniter

March 5, 2008 by rafeequl

rafeequl's picture

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[] = $billingplan->qty;
			$bp_label[] = $billingplan->billingplan;
		}
 
		//PIE chart, 60% alpha
		//
		$this->graph->pie(80,'#505050','{font-size: 12px; color: #404040;');
		//
		// pass in two arrays, one of data, the other data labels
		//
		$this->graph->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->graph->pie_slice_colours( array('#d9db35','#487daf','#d00000','#4ae331') );
 
		$this->graph->set_tool_tip( '#val# Vouchers' );
		$this->graph->bg_colour = '#040404';
		$this->graph->title( 'Voucher Created', '{font-size:14px; color: #7F7772}' );
		$this->graph->set_output_type('js');
 
 
		//get the vouchers data
		$data['voucher'] = $this->vouchermodel->getVoucherStatistics();
 
		//get the postpaid account data
		$data['postpaid'] =  $this->postpaidmodel->getAccountStatistic();
 
		//get the who's online list
		$data['onlineuser'] = radius_get_online_users();
 
		$data['title'] = "Hotspot Statistics";
		$data['h1'] = "Hotspot Statistics";
 
		//$this->output->enable_profiler();
 
		$this->load->view('statistic/statistic_view',$data);
	}
 
}
 
?>

view :
<?php $this->load->view('header') ?>
 
<h1><?=$h1?></h1>
 
<div id='voucher_info'>
<h3>Vouchers Info</h3>
<ul>
	<li><label>Vouchers Created</label><?=$voucher['created']?></li>
	<li><label>Used</label><?=$voucher['used']?></li>
	<li><label>Expired</label><?=$voucher['expired']?></li>
</ul>
<h3>Billing Plans</h3>
<ul>
	<?php foreach($billingplans->result() as $row):?>
	<li><label><?=$row->billingplan?></label><?=$row->qty?></li>
	<?php endforeach; ?>
</ul>
		<div id='graph'>
			<?=$this->graph->render()?>
		</div>
</div>
 
 
<div id='postpaid_info'>
<h3>Postpaid Account Info</h3>
<ul>
	<li><label>Account Created</label><?=$postpaid['created']?></li>
	<li><label>Used</label><?=$postpaid['used']?></li>
</ul>
</div>
 
 
<? $this->load->view('footer'); ?>

lebih lanjut cara menggunakan openflashchart bisa dilihat di http://teethgrinder.co.uk/open-flash-chart/ .
Selamat Mencoba

Comments

error message

April 3, 2010 by gutasaputra, 1 year 6 weeks ago
Comment: 6238

gutasaputra's picture

maaf. saya memang sedang membutuhkan grafik pada website yang saya buat. saya mempraktekan tutorial ini berkali berkali untuk mengurangi human error yang ada pada diri saya sendiri.

tiap kali saya mempraktekan tutorial ini selalu muncul pesan berikut :

>>>>>
Parse error: parse error in C:\xampp\htdocs\codeigniter\system\application\controllers\graph.php on line 31

line 31 :
>>>>>
//get billingplan
$bp_qty = array();
$bp_label = array();
$data['billingplans'] = $this->billingplanmodel->getBillingPlanStat();
foreach ($data['billingplans']->result() as $billingplan) {
>>>line 31 $bp_qty[geshifilter-] = $billingplan->qty;
$bp_label[] = $billingplan->billingplan;
}

mohon bantuannya ya pak. terimakasih.
regards.

# Pertama-tama, aturlah

January 11, 2010 by jhhyt, 1 year 17 weeks ago
Comment: 5818

jhhyt's picture

# Pertama-tama, aturlah config didalam application/config/config.php. Sebagai contoh : $config['base_url'] = "http://andhana2/coid/";.
# Lalu rubah CISSP exam juga file application/config/routes.php. Sebagai contoh : $route['default_controller'] 1z0-042 exam = "welcome";. Ini berfungsi untuk menjadikan controller welcome sebagai halaman utama pada 70-238 exam web coid yang telah kita buat.

Premium Drupal Themes by Adaptivethemes