Yii 2.0: yii2-highcharts-widget创建饼状图

安装

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]
                                ]
                            }]
                        }'
                    ]);

  

  

转载于:https://www.cnblogs.com/seafood/p/yii2-highcharts-widget.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值