yii2-gcharts Google Charts the Yii Way

Use Google Charts to display data the way you would use a GridView. Put your data in a DataProvider, configure some columns, and you're ready to go.

For instance, to render a Pie Chart, first create an ActiveDataProvider like so:

<?php
// ...
public function actionPie() {
    $dataProvider = new ActiveDataProvider([
        'query' => Country::find(),
        'pagination' => false
    ]);

    return $this->render('pie', [
        'dataProvider' => $dataProvider
    ]);
}
// ...
?>

In the View, do something like this:

<?php
use sjaakp\gcharts\PieChart;
?>
...
<?= PieChart::widget([
    'height' => '400px',
    'dataProvider' => $dataProvider,
    'columns' => [
        'name:string',
        'population'
    ],
    'options' => [
        'title' => 'Countries by Population'
    ],
]) ?>
...

That's all there is in creating beautiful charts. Apart from the PieChart class, yii2-gcharts consists of the classes AreaChart, BarChart, BubbleChart, ColumnChart, GeoChart, LineChart and ScatterChart. There may be even more in the future.

Resources ΒΆ

2 0
4 followers
0 downloads
Yii Version: 2.0
License: MIT
Category: User Interface
Developed by: Sjaakp
Created on: Oct 29, 2015
Last updated: 8 years ago

Related Extensions