Entradas

Mostrando entradas de diciembre, 2020

Google Chart con Pjax

Imagen
1.- Crear la tabla: CREATE TABLE `yii2_proyecto`.`author_sales` ( `id` INT NOT NULL AUTO_INCREMENT , `author_id` INT NOT NULL , `dateSale` DATE NOT NULL , `quantityBook` INT NOT NULL , PRIMARY KEY (`id`)) ENGINE = InnoDB; ALTER TABLE `author_sales` ADD FOREIGN KEY (`author_id`) REFERENCES `author`(`id`) ON DELETE CASCADE ON UPDATE CASCADE; 2.- Crear Modelo Table Name: author_sales Model Class Name: AuthorSales Namespace: backend\modules\bookstore\models\AuthorSales 3.- En el model añadir el use con la tabla author que está relacionada: use backend\modules\bookstore\models\Author\Author; 4.- Generar el crud: Model Class: backend\modules\bookstore\models\AuthorSales\AuthorSales Search Model Class: backend\modules\bookstore\models\AuthorSales\AuthorSalesSearch Controller Class: backend\modules\bookstore\controllers\AuthorSalesController View Path: @backend/modules/bookstore/views/author-sales 5.- Ingresar valores a la tabla 6.- Añadir en el controlador:     public function actionChart()  

Implementación de Google Chart en Yii2 ("scotthuangzl/yii2-google-chart")

Imagen
 1.- Colocar en el archivo de composer.json: "scotthuangzl/yii2-google-chart": "dev-master" 2.- Ejecutar en el archivo de cmd:  composer update --prefer-dist 3.- Colocar en el Controlador: use scotthuangzl\googlechart\GoogleChart; 4.- En el controlador, en el método actionChart que se creó en una entrada anterior:         $dataSale[]= [Yii::t('app', 'Authors'),Yii::t('app', 'Total Sales')];         $modelArray =   Author::find()->orderBy('total_sale DESC')->limit(10)->all();          foreach ($modelArray as $value) {               $dataSale[] = [$value['name'],(double)$value['total_sale']];         }            $chartGoogleSale =  GoogleChart::widget(              array('visualization' => 'ColumnChart',                 'data' => $dataSale,                 'options' => array(                   'title' => '',                   'hAxis'=&g