make chart from custome queries using amcharts widget

0 0
3
Viewed: 11 322 times
Version: Unknown (update)
Category: How-tos
Written by: Narender Negi Narender Negi
Updated by: trond trond
Created: Aug 5, 2013
Updated: 13 years ago

You are viewing revision #2 of this wiki article.
This version may not be up to date with the latest version.
You may want to view the differences to the latest version or see the changes made in this revision.

« previous (#1)next (#3) »

Use this code in your view,make sure to put EAmChartWidget in your extension folder. here is the url of widget http://www.yiiframework.com/extension/eamchartwidget/

<?php $query ="SELECT count(*) as totalCalls,prov_destname as destination FROM calls WHERE status LIKE 'HUNGUP' AND startdate BETWEEN '$dateFrom' AND '$dateTo' AND customerID ='".Yii::app()->session['customerID']."' GROUP BY prov_destname ORDER BY totalCalls DESC LIMIT 5"; $connection = Yii::app()->db; $command = $connection->createCommand($query); $Results = $command->queryAll();

$filedlabel ='This week'; $dataProvider=new CArrayDataProvider($Results, array( 'keyField' =>'callID') ); $this->widget('ext.amcharts.EAmChartWidget', array(

  'width' => 500,
  'height' => 200,
  'chart'=>array( 
                'dataProvider'=>$dataProvider,
                'categoryField' =>'destination',
                'columnWidth'=>'0.2',
                'angle' =>'30',
                'depth3D' => '15'
                 ),
  'chartType' => "AmSerialChart",
  'graphs'=>array(
                   array(                                       
                         'valueField' => 'totalCalls',                                                      

'title'=>'Call', 'type' => 'column',

                                                                    'balloonText'=>"[[destination]]: [[totalCalls]] call",

'lineAlpha' => '0',

                                                                    'fillAlphas'=>'0.8',
                                                                    'fillColors'=>'#B0DE09',
                                                                ),
                                                            ),
                                                            
					'categoryAxis'=>array(
								'title'=>ucfirst($filedlabel)
                                                                ),
					'valueAxis'=>array(
                                                                'title'=>'Total'
                                                                )
                                        ));
                       ?>