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 ΒΆ
- Project page, with documentation
- Try out a demo
If you have any questions, please ask in the forum instead.
Signup or Login in order to comment.