Yii Framework Forum: Membuat Grafik - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Membuat Grafik Rate Topic: -----

#1 User is offline   yudha77 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 3
  • Joined: 29-January 13

Posted 29 January 2013 - 11:40 PM

Minta bantuan dong,

saya mau buat grafik dari table yang saya punya, yaitu anggaran(gambar terlampir).

Lalu saya menggunakan highchart dengan code di view sepeti berikut
<?php
$this->Widget('ext.highcharts.HighchartsWidget', array(
'options'=>array(
'title' => array('text' => 'Grafik Anggaran'),
'xAxis' => array(
'categories' => array($model->tahun)
),
'yAxis' => array(
'title' => array('text' => 'Dana')
),
'series' => array(
array('name' => 'Dana', 'data' => array($model->dana))
)
)));
?>

kenapa gambarnya gak keluar ya(gambar terlampir)?

Mohon bantuannya.. Terima Kasih

Attached File(s)

  • Attached File  1.PNG (35.59K)
    Number of downloads: 25
  • Attached File  2.PNG (9.73K)
    Number of downloads: 23

0

#2 User is offline   mrkoeh 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 42
  • Joined: 31-October 12
  • Location:Indonesia

Posted 30 January 2013 - 03:36 AM

View Postyudha77, on 29 January 2013 - 11:40 PM, said:

Minta bantuan dong,

saya mau buat grafik dari table yang saya punya, yaitu anggaran(gambar terlampir).

Lalu saya menggunakan highchart dengan code di view sepeti berikut
<?php
$this->Widget('ext.highcharts.HighchartsWidget', array(
'options'=>array(
'title' => array('text' => 'Grafik Anggaran'),
'xAxis' => array(
'categories' => array($model->tahun)
),
'yAxis' => array(
'title' => array('text' => 'Dana')
),
'series' => array(
array('name' => 'Dana', 'data' => array($model->dana))
)
)));
?>

kenapa gambarnya gak keluar ya(gambar terlampir)?

Mohon bantuannya.. Terima Kasih



1. apakah data di tabel benar2 ada?? cba cek dahulu. .
2. di controller cba tambahin ini gan
public function actionIndex()
	{
		// renders the view file 'protected/views/site/index.php'
		// using the default layout 'protected/views/layouts/main.php'
		//$this->render('index');
		if (!Yii::app()->user->IsGuest){ 
			//$this->render('index');  
			$sql='SELECT * FROM anggaran';
		
			$dataProvider=new CSqlDataProvider($sql,array(
								'keyField' => 'id',
			));
			$this->render('index',array(
				'dataProvider'=>$dataProvider,
			));
			
		}else{                            
			$this->redirect(array('login'));  
		}
	}


3. di view agan
<?php

$bb=array();
foreach($dataProvider->getData() as $i=>$ii)
	$bb[$i]=array($ii['tahun'],doubleval($ii['dana']));

$this->Widget('ext.highcharts.HighchartsWidget', array(
   'options'=>array(
      'series' => array(
         array('type'=>'pie',
               'data' => $bb
              )
      ),
      'title' => array('text' => 'judul di sini'),
      'tooltip' => array(
		'formatter' => 'js:function(){ return "<b>"+this.point.name+"</b> :"+this.y; }'
      ),
      'plotOptions'=>array('pie'=>(array(
                    'allowPointSelect'=>true,
                    'showInLegend'=>true,
                    'cursor'=>'pointer',
                )
            )                       
        ),
      'credits'=>array('enabled'=>false),
   )
));

?>


CMIIW. . .
gak dicobain,hehe. . .
0

#3 User is offline   yudha77 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 3
  • Joined: 29-January 13

Posted 30 January 2013 - 03:58 AM

makasih gan sebelumnya udah repot2 ngebantuin :D

sudah ada gan datanya(gambar terlampir)..

ngikutin yang cara agan juga belum berhasil..

jadi rencananya grafiknya mau saya keluarkan di halaman admin,

berikut code di view admin

<?php
$this->breadcrumbs=array(
'Anggarans'=>array('index'),
'Manage',
);

$jabatan=Yii::app()->user->jabatan;
if($jabatan=='Admin')
{
$this->menu=array(
array('label'=>'Upload Program dan Anggaran', 'url'=>array('create')),
);
}
?>

<div id="submenu">Daftar Program dan Anggaran</div>

<?php
$this->Widget('ext.highcharts.HighchartsWidget', array(
'options'=>array(
'title' => array('text' => 'Grafik Anggaran'),
'xAxis' => array(
'categories' => array($model->tahun)
),
'yAxis' => array(
'title' => array('text' => 'Dana')
),
'series' => array(
array('name' => 'Dana', 'data' => array($model->dana))
)
)));
?>

<?php $this->widget('zii.widgets.grid.CGridView', array(
'id'=>'anggaran-grid',
'dataProvider'=>$model->search(),
'filter'=>$model,
'columns'=>array(
'judul_anggaran',
'tahun',
'penanggung_jawab',
'dana',
array(
'class'=>'CButtonColumn',
'template'=>'{view}',
),
),
)); ?>


dan ini code di controller anggaran
/**
* Manages all models.
*/
public function actionAdmin()
{
$model=new Anggaran('search');
$model->unsetAttributes(); // clear any default values
if(isset($_GET['Anggaran']))
$model->attributes=$_GET['Anggaran'];

$this->render('admin',array(
'model'=>$model,
));
}

Attached File(s)

  • Attached File  3.PNG (10.29K)
    Number of downloads: 17

0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users