dev-master
9999999-devExtended ChartJs v2 for Yii2 widget
BSD-3-Clause
The Requires
- yiisoft/yii2 *
 - bower-asset/chartjs ^2.1.3
 
by villamuera
extension yii2 widget chartjs
                         Wallogit.com
                    
                    2017 © Pedro Peláez
                    
                    
                    
                    
                
                
            
Extended ChartJs v2 for Yii2 widget
Based on ChartJs 2 for Yii2 widget, (*1)
The preferred way to install this extension is through composer., (*2)
Either run, (*3)
php composer.phar require --prefer-dist cenotia/yii2-chartjs-widget "*"
or add, (*4)
"cenotia/yii2-chartjs-widget": "*"
to the require section of your composer.json file., (*5)
Once the extension is installed, simply use it in your code like this :, (*6)
In the view, (*7)
= ChartJs::widget([
                   'type' => 'pie',//bar,line,pie,radar,polar, bubble
                   'options' => [
                       'height' => 180,
                       'width' => 180,
                   ],
                   'labelPercent' => true, //add percentage to the tooltips
                   'data' => [
                               'labels' => $data4['labels'],
                               'datasets' => [
                                       [
                                           'label'=> 'yourlables',
                                           'data'=> $data4['datasets'],
                                           'backgroundColor' => [
                                                              '#FF6384',
                                                              '#FFAA84',
                                                              '#56BB84',
                                                              '#87AA98',
                                                              '#8899AA',
                                                              '#5499CC'
                                                          ], //for 6 values. It could be set in the controller
                                       ]
                                   ]
                           ],
               ]);?>
In the controller, (*8)
        //your query returns 6 labels and 6 values
        //use function to get values and * 1 to turn then into numerals otherwise
        //it will strings and the if you use the percentages, it won't work.
        $command = $connection->createCommand("
                    select dimension, measure
                    from yourtable
                    where yourfilter
                    group by dimension
                    limit 6;                
                       ");   
        $result4 = $command->queryAll();
        $data4 = [
            'labels' => ArrayHelper::getColumn($result4,'dimension'),
            'datasets' => ArrayHelper::getColumn($result4,function ($element) {
                    return $element['measure']*1;
                })
        ];
Extended ChartJs v2 for Yii2 widget
BSD-3-Clause
extension yii2 widget chartjs