如何使用Codeigniter中的高图查询数据库中的数据?

问题描述 投票:0回答:1

我有全职和兼职员工的数据。我得到了使用select_sum的双方总数。问题是我如何使用高图显示他们的数据,包括部门分配的全职和总人数。

我是一个新手,不知道如何让它充满活力。这就是为什么我会尝试在静态数据中使用它。提前致谢。

DB:

_____________________________________________________________
| id | account_id  |   fulltime   |  partime  |  department  |
|____|_____________|______________|___________|______________|
| 1  |      3      |      1       |   null    |      3       |
|____|_____________|______________|___________|______________|
| 2  |      5      |     null     |     1     |      1       |
|____|_____________|______________|___________|______________|
| 3  |      6      |       1      |    null   |      2       |
|____|_____________|______________|___________|______________|

LEGEND :

department : 1 = 'COF'
           : 2 = 'CAS'
           : 3 = 'CCS'

我使用以下内容:

JS:

$(function(){

    var full= $.getJSON('<?php echo base_url('public/employee/fulltime');?>', 
        function (data1){
            console.log(data1);
    });

    var data = [
     { y: 'COF', z0: 'Part Time' , a0: 275, z1: 'Full Time' , a1: full},
     { y: 'CAS', z0: 'Part Time' , a0: 440, z1: 'Full Time' , a1: 332},
     { y: 'CCS', z0: 'Part Time' , a0: 450, z1: 'Full Time' , a1: 425},
     { y: 'CFND', z0: 'Part Time' , a0: 462, z1: 'Full Time' , a1: 435},
     { y: 'CHMT', z0: 'Part Time' , a0: 504, z1: 'Full Time' , a1: 162},
     { y: 'CTE', z0: 'Part Time' , a0: 400, z1: 'Full Time' , a1: 162},
     { y: 'CBMA', z0: 'Part Time' , a0: 260, z1: 'Full Time' , a1: 79},
     { y: 'CCJE', z0: 'Part Time' , a0: 129, z1: 'Full Time' , a1: 42},
     { y: 'ADMIN', z0: 'Part Time' , a0: 129, z1: 'Full Time' , a1: 42}

    ]

    Morris.Bar({
      element: 'chart',
      data: data,
        xkey: 'y',
        ykeys: ['a0', 'a1'],
        labels: ['Label1', 'Label2'],
        fillOpacity: 0.6,
        hideHover: 'auto',
        behaveLikeLine: true,
        resize: true,
        stacked: true,
        pointFillColors:['#ffffff'],
        pointStrokeColors: ['black'],
        lineColors:['lime', 'blue', 'red', 'cyan', '#909090'],
        xLabelAngle: 60,
        hoverCallback: function (index, options, content, row) {
        var currentDiv = "";
        var finalContent = $("<div/>");

        $(content).each(function () {
            currentDiv = $(this);
            currentDiv.html(currentDiv.html().replace("Label1", data[index].z0).replace("Label2", data[index].z1))
            $(finalContent).append(currentDiv);
        });

        $(finalContent)
        return finalContent;    
      }
    });

});

控制器:

public function fulltime()
{

    $fulltime = $this->account_model->get_fulltime();
        echo json_encode($fulltime);
}

型号:

public function get_fulltime()
{
    $this->db->select_sum('fulltime');
    $this->db->from('list_of_employee');

    return $this->db->get()->result();
}

php jquery highcharts codeigniter-3
1个回答
0
投票

将从Ajax响应中获取的数据作为输入数据放入Highcharts脚本中 1-将您的数据查询作为Highcharts的结构。 2-在Controller中创建一个PHP Action来调用上一个查询。 3-在Ajax Call中使用PHP Action并通过Highchats的输入释放响应数据。

© www.soinside.com 2019 - 2024. All rights reserved.