如何使用highchart正确构建多个向下钻取?

时间:2017-03-30 12:44:39

标签: yii highcharts yii2

我想使用框架Yii2制作多个向下钻取图表。我想根据年龄制作学生的图表。我已经通过composer安装了highcharts。我也已将其注册到我的php文件中,但我不知道为什么深入分析图表无法正常工作。我想,这是因为我的错误代码。

这是我的表格:

facultyin2011

enter image description here

department2011

enter image description here

major2011

enter image description here

这是我的控制器:

<?php
    namespace app\controllers;

    use yii\web\Controller;
    use yii\helpers\Json;



    class MagisterrinciController extends Controller
    {
         public function actionIndex()
    {


//data usia fakultas
        $faculty = (new \yii\db\Query())
            ->select(['Faculty'])
            ->from('facultyin2011')
            ->limit(10)
            ->column();

        $age1 = (new \yii\db\Query())
            ->select(['lessthan25'])
            ->from('facultyin2011')
            ->limit(10)
            ->column();

        $age2 = (new \yii\db\Query())
            ->select(['btween25to29'])
            ->from('facultyin2011')
            ->limit(10)
            ->column();


        $age1 = array_map('floatval', $age1);
        $age2 = array_map('floatval', $age2);


        $data['ageforfacultystudent'] = json_encode($faculty);
        $data['age1'] = json_encode($age1);
        $data['age2'] = json_encode($age2);


// next
        $department = (new \yii\db\Query())
            ->select(['Department'])
            ->from('department2011')
            ->limit(10)
            ->column();

        $agedepartment1 = (new \yii\db\Query())
            ->select(['lessthan25'])
            ->from('department2011')
            ->limit(10)
            ->column();

        $agedepartment2 = (new \yii\db\Query())
            ->select(['btween25to29'])
            ->from('department2011')
            ->limit(10)
            ->column();


        $agedepartment1 = array_map('floatval', $agedepartment1);
        $agedepartment2 = array_map('floatval', $agedepartment2);


        $data['agefordepartmentstudent'] = json_encode($department);
        $data['agedepartment1'] = json_encode($agedepartment1);
        $data['agedepartment2'] = json_encode($agedepartment2);


//next

        $majorstudent = (new \yii\db\Query())
            ->select(['major'])
            ->from('major2011')
            ->limit(10)
            ->column();

        $agemajor1 = (new \yii\db\Query())
            ->select(['lessthan25'])
            ->from('department2011')
            ->limit(10)
            ->column();

        $agemajor2 = (new \yii\db\Query())
            ->select(['btween25to29'])
            ->from('department2011')
            ->limit(10)
            ->column();


        $agemajor1 = array_map('floatval', $agemajor1);
        $agemajor2 = array_map('floatval', $agemajor2);


        $data['ageformajorstudent'] = json_encode($majorstudent);
        $data['agemajor1'] = json_encode($agemajor1);
        $data['agemajor2'] = json_encode($agemajor2);





        return $this->render('index',$data);
        }


    }

以下是我的索引视图:

<?php
    use app\assets\HighchartsAsset;


    HighchartsAsset::register($this);
    $this->title = 'Highcharts Test';
    ?>



<!-- data selanjutnya -->    
<div class="container">
<div class="row">
<div class="col-md-6 col-sm-6 col-xs-12">
<div class="x_panel">
<div id="container" style="min-width: 310px; height: 400px; margin: 0 auto"></div>
 <?php $this->registerJs("

$(function () {

    // Create the chart
    $('#container').highcharts({
        chart: {
            type: 'column'
        },
        title: {
            text: 'Basic drilldown'
        },
        xAxis: {
            categories: $ageforfacultystudent
        },

        legend: {
            enabled: false
        },

        plotOptions: {
            series: {
                borderWidth: 0,
                dataLabels: {
                    enabled: true,
                }
            }
        },

        series: [
            {
                name: 'lessthan25',
                data: $age1,
                drilldown: 'department1'
            },
            {
                name: 'btween25to29',
                data: $age2,
                drilldown: 'department2'
            }],

        drilldown: {
            series: [{
                id: 'department1',
                name: 'Departemen',
                data: [{
                    name: 'lessthan25',
                    data: $agedepartment1,
                    drilldown: 'major1'
                }, 
                {
                    name: 'btween25to29',
                    data: $agedepartment2,
                    drilldown: 'major2'
                }
                ]
            }, {

                id: 'major1',
                data: $agemajor1
            },
            {

                id: 'major2',
                data: $agemajor2
            }]
        }
    })
});
")?>

</div>
</div> 

结果如下:

enter image description here

这些图表无法向下钻取。

当我检查控制台时,没有错误消息。

enter image description here 有人可以更正我上面的代码吗?它会给我很多帮助。提前谢谢

0 个答案:

没有答案