PHP code example of mrlco / yii2-google-charts
1. Go to this page and download the library: Download mrlco/yii2-google-charts library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
mrlco / yii2-google-charts example snippets
use mrlco\googlecharts\GoogleCharts;
/* For more info on usage of any type of charts, see the google charts documentation */
// PieChart
echo GoogleCharts::widget([
'visualization' => 'PieChart',
'containerId' => 'chart-container',
'data' => [
['Task', 'Hours per Day'],
['Work', 11],
['Eat', 2],
['Commute', 2],
['Watch TV', 2],
['Sleep', 7]
],
'options' => ['title' => 'My Daily Activity']
]);
// LineChart
echo GoogleCharts::widget([
'visualization' => 'LineChart',
'containerId' => 'chart-container',
'data' => [
['Task', 'Hours per Day'],
['Work', 11],
['Eat', 2],
['Commute', 2],
['Watch TV', 2],
['Sleep', 7]
],
'options' => ['title' => 'My Daily Activity']
]);
// Another LineChart example
echo GoogleCharts::widget([
'visualization' => 'LineChart',
'containerId' => 'chart-container',
'data' => [
['Year', 'Sales', 'Expenses'],
['2004', 1000, 400],
['2005', 1170, 460],
['2006', 660, 1120],
['2007', 1030, 540],
],
'options' => [
'title' => 'My Company Performance',
'titleTextStyle' => ['color' => '#FF0000'],
'vAxis' => [
'title' => 'Vertical Axis',
'gridlines' => [
'color' => 'transparent' //set grid line transparent
]
],
'hAxis' => ['title' => 'Horizontal Aixs'],
'curveType' => 'function', //smooth curve or not
'legend' => ['position' => 'bottom'],
]
]);
// ScatterChart
echo GoogleCharts::widget([
'visualization' => 'ScatterChart',
'containerId' => 'chart-container',
'data' => [
['Sales', 'Expenses', 'Quarter'],
[1000, 400, '2015 Q1'],
[1170, 460, '2015 Q2'],
[660, 1120, '2015 Q3'],
[1030, 540, '2015 Q4'],
],
'scriptAfterArrayToDataTable' => "data.setColumnProperty(2, 'role', 'tooltip');",
'options' => [
'title' => 'Expenses vs Sales',
]
]);
// Gauge
echo GoogleCharts::widget([
'visualization' => 'Gauge',
'containerId' => 'chart-container',
'packages' => 'gauge',
'data' => [
['Label', 'Value'],
['Memory', 80],
['CPU', 55],
['Network', 68],
],
'options' => [
'width' => 400,
'height' => 120,
'redFrom' => 90,
'redTo' => 100,
'yellowFrom' => 75,
'yellowTo' => 90,
'greenFrom' => 50,
'greenTo' => 75,
'minorTicks' => 5
]
]);
php composer.phar