Chart widgets for Yii2
This is the Yii2 widgets for echarts. You can use this widget to implement the all charts supported by echarts. Some quick class for Line,Pie and map implement. , (*1)
You can get detail of echarts from echarts official website :), (*2)
$ composer require "peterziv/yii2-echarts:dev-master"
Pie Chart, (*3)
$pieData = ['n1' => ['value' => 11.1], 'n2' => ['value' => 22.2]]; echo Pie::widget([ 'title'=>'Pie Chart Test', 'responsive' => true, 'htmlOptions' => ['style' => 'height: 300px;'], 'visualMap' => [ "show" => false, "min" => 80, "max" => 600 ], 'data' => $pieData ]);
Line Chart, (*4)
$lineData = ['serie1' => ['value' => [1, 2, 3], 'averageLine' => true, 'maxPoint' => true, 'minPoint' => true], 'serie2' => ['averageLine' => true, 'value' => [3, 6, 9]]]; echo Line::widget([ 'responsive' => true, 'htmlOptions' => ['style' => 'height: 300px;'], 'title' => 'Line Chart Test', 'unit'=>'度', 'axis'=>['小','中','大'], 'data'=>$lineData ]);
Zero data support, (*5)
$zero =[]; echo Line::widget([ 'htmlOptions' => ['style' => 'height: 300px;'], 'responsive' => true, 'title' => 'No Data Test', 'unit' => '度', 'axis' => ['小', '中', '大'], 'data' => $zero ]);
Also Support json and custom, (*6)
$theOptions = '{ "title": { "text": "Json data Support" }, "legend": { "data": ["bar1", "bar2"], "align": "left" }, "toolbox": { "feature": { "magicType": { "type": ["stack", "tiled"] } } }, "yAxis":[{"name":"SCORE","type":"value"}], "xAxis": { "data": ["测试1", "测试2", "测试3", "测试4"], "silent": false, "splitLine": { "show": false } }, "series": [{ "name": "bar1", "type": "bar", "data": [1, 2, 5, 8] }, { "name": "bar2", "type": "bar", "data": [9, 6, 5, 8] }] }'; echo Echarts::widget([ 'options'=>$theOptions, 'htmlOptions' => ['style' => 'height: 300px;'], ]);