如何正确使用钻取图表?

时间:2017-03-31 00:57:23

标签: charts yii highcharts yii2 drilldown

我通过手动输入使这个highcharts多次向下钻取。这是链接http://jsfiddle.net/Vf3yT/1107/。但是,我需要制作从数据库中获取数据的图表。我从谷歌搜索和stackoverflow的其他问题,但我仍然没有得到答案。人们询问他们的数据手动输入到他们的高图代码的钻取问题,并且它与我的问题不同,因为我从数据库中获取数据。

以下是我要放到我的图表中的表格:

facultyin2011

enter image description here

department2011

enter image description here

major2011

enter image description here

这是我的代码:

控制器

        $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);



        $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);




        $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);

索引

$(function () {

    // Create the chart
    $('#containers').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
            }]
        }
    })
});
")?>

我想制作一级图表是教师,第二级是部门,第三级是专业。

上面的代码结果如下图所示:

enter image description here

上面我的图表的问题:图表无法向下钻取,因为我仍然没有放下钻取代码。我不知道怎么把它,因为我拿的数据来自数据库中的表。有人可以帮我解决这个问题吗?我该怎么做才能解决这个问题?这对我很有帮助。提前致谢

0 个答案:

没有答案