Yii 1.1: eamchartwidget

Simple Widget to renderize Charts using AmCharts Javascript Library

This widget for use with the Yii Framework utilises the Amchart plugin visualize (http://www.amcharts.com/) to render graphs and charts for your web application.


  • Yii 1.1 or above


The following code is a simple instance of Widget, you can create the following chart types: - Pie - Line - Area - Column - Bar - Scatter

The configuration parameter have the same name of the Chart and Grpah defined by AmChart, you can the AmChart Doc and Amchart Examples

// DataProvider, you can use any Provider that implement IDataProvider
$dataProvider = new CActiveDataProvider('OlimpicMedals');
//Chart With bar & line graph
                        'width' => 700, // width of the Chart
                        'height' => 400, // height of the chart
                        'chart'=>array(// collections of grpah to display into the chart
                                    'dataProvider'=>$dataProvider, // DataProvider
                                    'categoryField' => 'Date' // Field of the DataProvider to set on the X Axis
                                    'valueField' => 'GoldMedals', // Field of the DataProvider to set the Y Axis
                                    'title'=>'Value', // Title of the , used on the Legend
                                    'type' => 'bar' // Type of Graph
                                    'valueField' => 'SilverMedals',
                                    'type' => 'line',
                                    'title'=>'Species Name'
    // Chart with pie   
                    'width' => 700,
                    'height' => 400,
                            'titleField' => 'Country',
                            'valueField' => 'Medals',
                            'type' => 'pie'


  • Download the widget from here
  • Extract the following Widget on /YourProject/protected/extensions/


Total 4 comments

#19394 report it
Dehghan at 2015/06/16 04:47am

This version can not import all attributes from query! For using all of theme you should import the array of dataProvider not attributes of that!

1-Open { EAmChartWidget.php } 2-Find { run() } method 3-Remove { ->attributes } from this statement:

foreach ($this->chart['dataProvider'] as $modelData->attributes)
#16197 report it
luckas at 2014/01/27 08:12am
Reply: Got Undefined Result

Hi Amjad Khan, making a faster review of your code your dataset retrieve the "projectname" field in lowercase and you are using with capital letter **Projectname** into the view

#16170 report it
Amjad Khan at 2014/01/25 02:49am
Got Undefined Result

I use this code to get the data from database

$sql="SELECT pkprojectid,projectname, count( * ) AS total_requests
                FROM `tblproject` , `tblinforequest`
                WHERE tblinforequest.fkprojectid = tblproject.pkprojectid
                GROUP BY projectname
                LIMIT 0 , 30";
             $result = Yii::app()->db->createCommand($sql)->queryAll(); 
             $dataProvider=new CArrayDataProvider($result,array(
                'keyField' => 'ID'));

and this is my view file

            'width' => 700, //height of the chart
            'height' => 400,//width of the chart
                'titleField' => 'Projectname',//Title Field
                'valueField' => 'total_requests',// Value Field
                'type' => 'pie'//Type of Chart

But i got just three verticals lines with undefined headings.

#14338 report it
Narender Negi at 2013/08/05 06:57am

Hi, good work.i used it and it works fine

Leave a comment

Please to leave your comment.

Create extension
No downloadable files yet