如何使用Ajax JSON Codeigniter制作Morris甜甜圈图?

时间:2019-03-01 10:01:47

标签: javascript jquery json codeigniter-3 donut-chart

如何使用Ajax JSON Codeigniter制作莫里斯甜甜圈图?

<?php 
$connect = mysqli_connect("localhost", "root", "", "database_employee");
$sub_query ="SELECT name, COUNT(*) AS total FROM tabel_employee GROUP BY name";
$result = mysqli_query($connect, $sub_query);
$data = array();
while($row = mysqli_fetch_array($result))
{
 $data[] = array(
  'label'  => $row["name"],
  'value'  => $row["total"]
 );
}
$data = json_encode($data);
?>

Javascript     $(function(){

    $.ajax({
        url : 'dashboard/total-data',    
    }).done(function(data){
        initDonut(JSON.parse(data));
        console.log(data);
    }).fail(function(){

    });

    var initDonut = function(data){

        return Morris.Donut({
            element: 'morris-donut-chart',
            data: [ data ],
            // data: [ 
                    // {label: "Name", value: 4} ],
            resize: true,
            colors: ['#87d6c6', '#54cdb4','#1ab394', '#54cdb4','#1ab394', '#54cdb4','#1ab394'],
        });

    } });

我该如何制作控制器和模型?

请帮助。 谢谢。

0 个答案:

没有答案