成长型歌神 2018-02-24 11:12:16 3830次浏览 0条评论 3 0 0

//在yii框架里面使用heiahtchart插件,实现数据可视化显示
http://www.yiiframework.com/extension/yii2-highcharts-widget/
//将下面的代码添加到composer.json中require项中 如下:

"require": {
        "php": ">=5.4.0",
        "yiisoft/yii2": "~2.0.5",
        "yiisoft/yii2-bootstrap": "~2.0.0",
        "yiisoft/yii2-swiftmailer": "~2.0.0",
        "kartik-v/yii2-widget-datetimepicker": "*",
        "kartik-v/yii2-widget-datepicker": "@dev",
        "miloschuman/yii2-highcharts-widget": "*"
    },

然后需要在命令行中执行 conposer update 组件会自动下载到yii的verdor目录下

//具体代码如下
 <?php
    use miloschuman\highcharts\Highcharts;
     foreach($model as $myda):
         $time[] = $myda['time'];
         $allorder[] = intval($myda['allorder']);
         $number[] = intval($myda['number']);
         $money[] = intval($myda['money']);
     endforeach;
     //var_dump($money);die();
    echo Highcharts::widget([
        'options' => [
            'title' => ['text' => 'Fruit Consumption'],
            //如果需要的是柱状图则加上下面这个代码    
            'chart' => ['type' => 'column'],   
            'xAxis' => [
                'categories' => [date('Y-m-d',$time['0']), date('Y-m-d',$time['1']), date('Y-m-d',$time['2']),date('Y-m-d',$time['3']),date('Y-m-d',$time['4'])]
            ],
            'yAxis' => [
                'title' => ['text' => 'Fruit eaten']
            ],
            'series' => [
                ['name' => '订单总量', 'data' => $allorder],
                ['name' => '支付用户', 'data' => $number],
                ['name' => '支付金额', 'data' => $money],
            ]
            ]
    ]);
    ?>
    没有找到数据。
您需要登录后才可以评论。登录 | 立即注册