2017 © Pedro Peláez
 

yii2-extension yii2-chartjs-extended

Extended ChartJs v2 for Yii2 widget

image

cenotia/yii2-chartjs-extended

Extended ChartJs v2 for Yii2 widget

  • Thursday, November 23, 2017
  • by xavsio4
  • Repository
  • 2 Watchers
  • 0 Stars
  • 103 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 1 Versions
  • 0 % Grown

The README.md

ChartJs Widget

Based on ChartJs 2 for Yii2 widget, (*1)

Installation

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)

Usage

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;
                })
        ];

Credits

2amigos/yii2-chartjs-widget, (*9)

The Versions

23/11 2017

dev-master

9999999-dev

Extended ChartJs v2 for Yii2 widget

  Sources   Download

BSD-3-Clause

The Requires

 

extension yii2 widget chartjs