欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

jquery tabs切换控制 hicharts 数据代码实例

程序员文章站 2024-01-24 10:48:16
html

html

<p style="text-align: center" id="call">
    <button class="layui-btn"   value="0">本周</button>
    <button class="layui-btn"   value="1">当月</button>
    <button class="layui-btn"   value="2">上月</button>
    <button class="layui-btn"   value="3">上上月</button>
</p>
 <p id="container_call_distribution" style="min-width:400px;height:400px"></p>

js

$(document).on('click','#call>button',function(){
    var dat = {
        mobilephone: "",
        time: this.value
    };
    console.log(dat);
    $.post('/index/user/calldistribution',dat,function(res){
        var start_times  = res.start_times;
        var sum_total  = res.sum_total;
        call(start_times,sum_total)
    });

});
$(document).ready(function() {
    var dat = {
        mobilephone: "",
        time: 4
    };
    console.log(dat);
    $.post('/index/user/calldistribution',dat,function(res){
        var start_times  = res.start_times;
        var sum_total  = res.sum_total;
        call(start_times,sum_total)
    });
});
//24小时通话分布
function call(start_times,sum_total){
    $(function () {
        $('#container_call_distribution').highcharts({
            chart: {
                type: 'column'
            },
            title: {
                text: '24小时通话分布'
            },
//            subtitle: {
//                text: ''
//            },
            xaxis: {
                categories: start_times,
                crosshair: true
            },
            yaxis: {
                min: 0,
                title: {
                    text: '次数'
                }
            },

            plotoptions: {
                column: {
                    borderwidth: 0
                }
            },
            series: [{
                name:'通话分布',
                data: sum_total
            }]
        });
    });
}

php

public function calldistribution($mobilephone='',$time='')
{
    //本周
    $where2 = '';
     if($time==0){
         $week = date('y-m-d',strtotime('this week monday',time()));
         $where2['start_time'] = ['>',$week];
    //当月
     }elseif($time==1){
         $lastmonth = date('y-m-01');
         $where2['start_time'] = ['>',$lastmonth];
     //上月
     }elseif($time==2){
         $lastmonth = date('y-m-01');
         $beforemonth = date('y-m-d',strtotime($lastmonth.' -1 month'));
         $where2['start_time'] = array('between',array($beforemonth,$lastmonth));
     }elseif($time==3){
         $month = date('y-m-01');
         $lastmonth = date('y-m-d',strtotime($month.' -1 month'));
         $beforemonth = date('y-m-d',strtotime($lastmonth.' -2 month'));
         $where2['start_time'] = array('between',array($beforemonth,$lastmonth));
     }elseif($time==4){
         $day = date('y-m-d',strtotime('-1 day'));
         $where2['start_time'] = ['>',$day];
     }else{
         $week = date('y-m-d',strtotime('this week monday',time()));

         $where2['start_time'] = ['>',$week];
     }


    $container_call_distribution = model('creditmobilecalls')->field("sum(cell_phone=$mobilephone) sum_total, left(right(start_time,8),2) start_times")
        ->where('cell_phone',$mobilephone)
        ->where($where2)
        ->group('start_times')
        ->select()->toarray();
    $data['start_times'] = string_conversion(array_column($container_call_distribution,'start_times'));
    $data['sum_total'] = string_conversion(array_column($container_call_distribution,'sum_total'));
    return  $data;
}

start_time 字段 是varchar(255)不能用thinkphp 的 wheretime