安裝
The preferred way to install this extension is through?composer.
項目根目錄下執行:
php composer.phar require --prefer-dist miloschuman/yii2-highcharts-widget "*"
或者在composer.json中添加
"miloschuman/yii2-highcharts-widget": "*"
后執行composer update.
使用
在view視圖中使用該widget:
use miloschuman\highcharts\Highcharts;
描繪餅狀圖(此處有兩種寫法,options中的參數可以為數組形式也可以為json格式,格式大致與highcharts中的例子:http://www.hcharts.cn/test/index.php?from=demo&p=39?格式對應):
echo Highcharts::widget(['options'=>'{"chart": {"plotBackgroundColor": null,"plotBorderWidth": null,"plotShadow": false},"title": {"text": "Browser market shares at a specific website, 2010"},"tooltip": {"pointFormat": "{series.name}: <b>{point.percentage:.1f}%</b>"},"plotOptions": {"pie": {"allowPointSelect": true,"cursor": "pointer","dataLabels": {"enabled": true,"color": "#000000","connectorColor": "#000000","format": "<b>{point.name}</b>: {point.percentage:.1f} %"}}},"series": [{"type": "pie","name": "Browser share","data": [["Firefox", 45.0],["IE", 26.8],{"name": "Chrome","y": 12.8,"sliced": true,"selected": true},["Safari", 8.5],["Opera", 6.2],["Others", 0.7]]}]}']);