如何解决不工作的高级图表?

时间:2017-04-01 11:33:51

标签: javascript charts highcharts yii2 drilldown

我想让highcharts多次向下钻取。第一是教师,第二钻是部门,第三是主要。我从数据库中获取数据。但是当我运行我的代码时,结果并没有像我预期的那样工作。下钻图表显示不完全如下图所示:

enter image description here

我期望的结果如下图所示。我按照此链接http://jsfiddle.net/rhhh2sg3/1/

手动输入,制作下面的图表

enter image description here

但我想让图表不是手动输入的,因为我想从数据库中获取数据。

这是我放到highcharts的表格:

facultyin2011

enter image description here

department2011

enter image description here

major2011

enter image description here

也许,我的代码中出现了问题:

CONTROLLER

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();
        $age1 = array_map('floatval', $age1);

        foreach ($age1 as $key => $age1_value) {
            $age1[$key] = [
                'name' => 'Fakultas',
                'y' => $age1_value,
                'drilldown' => 'department1'
            ];
        };

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


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

         foreach ($age2 as $key => $age2_value) {
            $age2[$key] = [
                'name' => 'Fakultas',
                'y' => $age2_value,
                'drilldown' => 'department2'
            ];
        };



        $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();
         $agedepartment1 = array_map('floatval', $agedepartment1);

        foreach ($agedepartment1 as $key => $agedepartment1_value) {
                $agedepartment1[$key] = [
                'name' => 'A'.($key+1),
                'y' => $agedepartment1_value,
                'drilldown' => 'major1'
            ];
            };



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



        $agedepartment2 = array_map('floatval', $agedepartment2);
        foreach ($agedepartment2 as $key => $agedepartment2_value) {
                $agedepartment2[$key] = [
                'name' => 'B'.($key+1),
                'y' => $agedepartment2_value,
                'drilldown' => 'major2'
            ];
            };


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

我的观点指数

$(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,

            },
            {
                name: 'btween25to29',
                data: $age2,

            }],

        drilldown: {

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

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

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

我也不知道如何对部门进行分类,因为部门是教职员工。 我可以像下面的例子一样对教员进行分类,因为教师图表不是任何图表的子图。

示例是这样的:

$('#containers').highcharts({


 chart: {
        type: 'column'
    },
    title: {
        text: 'Basic drilldown'
    },
    xAxis: {
        **categories: $ageforfacultystudent**

    },

表专业也是同样的问题。如何将专业分类到图表,因为专业是分部门?

请帮我解决这个问题。提前致谢

0 个答案:

没有答案