scotthuangzl / yii2-google-chart
Google 图表的包装器
dev-master
2015-06-11 12:13 UTC
Requires
- yiisoft/yii2: *
This package is not auto-updated.
Last update: 2024-09-14 18:04:05 UTC
README
Google 图表的包装器
安装
安装此扩展的首选方式是通过 composer。
运行以下命令之一
php composer.phar require scotthuangzl/yii2-google-chart "dev-master"
或
"scotthuangzl/yii2-google-chart": "dev-master"
将以下内容添加到您的 composer.json
文件的 require 部分。
使用方法
一旦安装了扩展,您可以通过以下方式在代码中使用它:顺便说一下,如果您无法访问 https://www.google.com/jsapi,那么在中国可能无法使用。谢谢。
您还可以参考 https://developers.google.com/chart/interactive/docs/quick_start
<div class="col-sm-5"> <?php use scotthuangzl\googlechart\GoogleChart; echo GoogleChart::widget(array('visualization' => 'PieChart', 'data' => array( array('Task', 'Hours per Day'), array('Work', 11), array('Eat', 2), array('Commute', 2), array('Watch TV', 2), array('Sleep', 7) ), 'options' => array('title' => 'My Daily Activity'))); echo GoogleChart::widget(array('visualization' => 'LineChart', 'data' => array( array('Task', 'Hours per Day'), array('Work', 11), array('Eat', 2), array('Commute', 2), array('Watch TV', 2), array('Sleep', 7) ), 'options' => array('title' => 'My Daily Activity'))); echo GoogleChart::widget(array('visualization' => 'LineChart', 'data' => array( array('Year', 'Sales', 'Expenses'), array('2004', 1000, 400), array('2005', 1170, 460), array('2006', 660, 1120), array('2007', 1030, 540), ), 'options' => array( 'title' => 'My Company Performance2', 'titleTextStyle' => array('color' => '#FF0000'), 'vAxis' => array( 'title' => 'Scott vAxis', 'gridlines' => array( 'color' => 'transparent' //set grid line transparent )), 'hAxis' => array('title' => 'Scott hAixs'), 'curveType' => 'function', //smooth curve or not 'legend' => array('position' => 'bottom'), ))); echo GoogleChart::widget(array('visualization' => 'ScatterChart', 'data' => array( array('Sales', 'Expenses', 'Quarter'), array(1000, 400, '2015 Q1'), array(1170, 460, '2015 Q2'), array(660, 1120, '2015 Q3'), array(1030, 540, '2015 Q4'), ), 'scriptAfterArrayToDataTable' => "data.setColumnProperty(2, 'role', 'tooltip');", 'options' => array( 'title' => 'Expenses vs Sales', ))); echo GoogleChart::widget( array('visualization' => 'Gauge', 'packages' => 'gauge', 'data' => array( array('Label', 'Value'), array('Memory', 80), array('CPU', 55), array('Network', 68), ), 'options' => array( 'width' => 400, 'height' => 120, 'redFrom' => 90, 'redTo' => 100, 'yellowFrom' => 75, 'yellowTo' => 90, 'minorTicks' => 5 ) )); echo GoogleChart::widget( array('visualization' => 'Map', 'packages'=>'map',//default is corechart 'loadVersion'=>1,//default is 1. As for Calendar, you need change to 1.1 'data' => array( ['Country', 'Population'], ['China', 'China: 1,363,800,000'], ['India', 'India: 1,242,620,000'], ['US', 'US: 317,842,000'], ['Indonesia', 'Indonesia: 247,424,598'], ['Brazil', 'Brazil: 201,032,714'], ['Pakistan', 'Pakistan: 186,134,000'], ['Nigeria', 'Nigeria: 173,615,000'], ['Bangladesh', 'Bangladesh: 152,518,015'], ['Russia', 'Russia: 146,019,512'], ['Japan', 'Japan: 127,120,000'] ), 'options' => array('title' => 'My Daily Activity', 'showTip'=>true, ))); ?> </div>
示例图片
您还可以从以下链接找到演示结果: https://yiiframework.cn/extension/yii2-google-chart/