<link rel="stylesheet" href="<?php echo base_url();?>public/js/vendor/bootstrap-datepicker/css/bootstrap-datepicker.standalone.min.css">
<script src="<?php echo base_url();?>public/js/vendor/bootstrap-datepicker/js/bootstrap-datepicker.min.js"></script>
<script src="<?php echo base_url();?>public/js/vendor/bootstrap-datepicker/locales/bootstrap-datepicker.zh-CN.min.js"></script>

<div class="content_wrapper">
    <div class="container-fluid">
        <div class="row">
            <div class="col-sm-12">
                <aside>
                    <section>
                        <div class="container-fluid">
                        	<div class="row">
		                        <div class="col-sm-12">
		                            <a style="margin:5px;" class="btn btn-primary " href="#advertisement/sta/1" role="button">数值</a>
		                            <a style="margin:5px;" class="btn btn-primary " href="#advertisement/sta/2" role="button">概率</a>
		                        </div>
		                    </div>
                            <div class="row">
                                <div class="col-sm-12">
                                    <form class="form-inline" role="form" method="POST" action="#Advertisement/sta">
                                        <span class="gap"></span>
										<input type="hidden" name="detail_post" value="1">
                                        <div class="form-group">
                                            <label>开始时间: </label>
                                            <input type="text" class="form-control datetimepicker" value="<?php if($stime) echo $stime;?>" placeholder="开始时间" name="detail_stime" />
                                        </div>
                                        <span class="gap"></span>
                                        <div class="form-group">
                                            <label>结束时间: </label>
                                            <input type="text" class="form-control datetimepicker" value="<?php if($etime) echo $etime;?>" placeholder="结束时间" name="detail_etime" />
                                        </div>
                                        <button type="submit" class="btn btn-primary">查询</button>
                                    </form>
                                </div>
                            </div>
                        </div>
                    </section>
                </aside>
            </div>
        </div>
        <div class="row">
            <div class="col-sm-12">
                <aside>
                    <header><i class="fa fa-fw fa-file"></i>广告统计</header>
                    <section>
                        <div class="container-fluid">
                            <div class="row">
                                <div id="container" style="min-width: 310px; height: 400px; margin: 0 auto"></div>
                            </div>
                            <button type="button" class="btn btn-primary" id="all_checked1">全选</button>
                            <button type="button" class="btn btn-primary" id="all_no_checked1">全不选</button>
                        </div>
                    </section>
                </aside>
            </div>
        </div>


        <div class="row">
            <div class="col-sm-12">
                <aside>
                    <header><i class="fa fa-fw fa-file"></i>安卓</header>
                    <section>
                        <div class="container-fluid">
                            <div class="row">
                                <div id="container1" style="min-width: 310px; height: 400px; margin: 0 auto"></div>
                            </div>
                            <button type="button" class="btn btn-primary" id="all_checked2">全选</button>
                            <button type="button" class="btn btn-primary" id="all_no_checked2">全不选</button>
                        </div>
                    </section>
                </aside>
            </div>
        </div>

        <div class="row">
            <div class="col-sm-12">
                <aside>
                    <header><i class="fa fa-fw fa-file"></i>IOS</header>
                    <section>
                        <div class="container-fluid">
                            <div class="row">
                                <div id="container2" style="min-width: 310px; height: 400px; margin: 0 auto"></div>
                            </div>
                            <button type="button" class="btn btn-primary" id="all_checked3">全选</button>
                            <button type="button" class="btn btn-primary" id="all_no_checked3">全不选</button>
                        </div>
                    </section>
                </aside>
            </div>
        </div>
    </div>
</div>
<script type="text/javascript" src="<?php echo base_url();?>public/js/highcharts/highcharts.js"></script>
<script type="text/javascript" src="<?php echo base_url();?>public/js/highcharts/modules/exporting.js"></script>
<script type="text/javascript">
    //选择日期
    $('.datetimepicker').datepicker({
        language:'zh-CN',
        format:'yyyy-mm-dd',
        zIndexOffset:906  //控制z-index
    });

    var chart1 = Highcharts.chart('container', {
        chart: {
            type: 'line'
        },
        title: {
            text: '按设备划分的广告数量'
        },
        xAxis: {
            categories: [<?php echo $date; ?>]
        },
        yAxis: {
            allowDecimals: false,
            min: 0,
            title: {
                text: '广告数量'
            }
        },
		/*
        tooltip: {
            formatter: function () {
                return '<br/>' +
                    this.series.name + ': ' + this.y + '<br/>' +
                    '总量: ' + this.point.stackTotal;
            }
        },
		*/
		tooltip: {
            shared: true
        },
        plotOptions: {
            column: {
                stacking: 'normal'
            }
        },
        series: [{
            name: '安卓(成功)',
            data: [<?php 
            	foreach($success['android'] as $k => $v){
            		if(empty($v)){
            			echo "0,";	
            		}else{
            			echo $v.",";
            		}
            	}
            ?>],
            stack: '成功' // stack 值相同的为同一组
        }, {
            name: 'IOS(成功)',
            data: [<?php 
            	foreach($success['ios'] as $k => $v){
            		if(empty($v)){
            			echo "0,";	
            		}else{
            			echo $v.",";
            		}
            	}
            ?>],
            stack: '成功'
        }, {
            name: '安卓(点击)',
            data: [<?php echo implode(',',$click['android']);?>],
            stack: 'click'
        }, {
            name: 'IOS(点击)',
            data: [<?php echo implode(',',$click['ios']);?>],
            stack: 'click'
        },{
            name: '安卓(播放)',
            data: [<?php echo implode(',',$play['android']);?>],
            stack: 'play'
        }, {
            name: 'IOS(播放)',
            data: [<?php echo implode(',',$play['ios']);?>],
            stack: 'play'
        }]
    });

    var chart2 = Highcharts.chart('container1', {
        chart: {
            type: 'line'
        },
        title: {
            text: '按ID划分的广告数量'
        },
        xAxis: {
            categories: [<?php echo $date; ?>]
        },
        yAxis: {
            allowDecimals: false,
            min: 0,
            title: {
                text: '广告数量'
            }
        },
        tooltip: {
            shared: true
        },
        plotOptions: {
            column: {
                stacking: 'normal'
            }
        },
        series: [<?php foreach ($android as $row){?>{
                    name: '<?php echo $row['name']; ?>(成功)',
                    data: [<?php echo implode(',',$row['success']);?>],
                    stack: '成功' // stack 值相同的为同一组
                },<?php }?>
                <?php foreach ($android as $row){?>{
                    name: '<?php echo $row['name']; ?>(点击)',
                    data: [<?php echo implode(',',$row['click']);?>],
                    stack: '点击' // stack 值相同的为同一组
                },<?php }?>
                <?php foreach ($android as $row){?>{
                    name: '<?php echo $row['name']; ?>(播放)',
                    data: [<?php echo implode(',',$row['play']);?>],
                    stack: '播放' // stack 值相同的为同一组
                },<?php }?>]
    });

    var chart3 = Highcharts.chart('container2', {
        chart: {
            type: 'line'
        },
        title: {
            text: '按ID划分的广告数量'
        },
        xAxis: {
            categories: [<?php echo $date; ?>]
        },
        yAxis: {
            allowDecimals: false,
            min: 0,
            title: {
                text: '广告数量'
            }
        },
        tooltip: {
            shared: true
        },
        plotOptions: {
            column: {
                stacking: 'normal'
            }
        },
        series: [<?php foreach ($ios as $row){?>{
                    name: '<?php echo $row['name']; ?>(成功)',
                    data: [<?php echo implode(',',$row['success']);?>],
                    stack: '成功' // stack 值相同的为同一组
                },<?php }?>
                <?php foreach ($ios as $row){?>{
                    name: '<?php echo $row['name']; ?>(点击)',
                    data: [<?php echo implode(',',$row['click']);?>],
                    stack: '点击' // stack 值相同的为同一组
                },<?php }?>
                <?php foreach ($ios as $row){?>{
                    name: '<?php echo $row['name']; ?>(播放)',
                    data: [<?php echo implode(',',$row['play']);?>],
                    stack: '播放' // stack 值相同的为同一组
                },<?php }?>]
    });

	$(document).on("click","#all_checked1",function(){
    	$(".highcharts-legend-item").each(function(index){
    		chart1.series[index].show();//显示
    	})
    })
    $(document).on("click","#all_no_checked1",function(){
    	$(".highcharts-legend-item").each(function(index){
    		chart1.series[index].hide();//隐藏
    	})
    })
    $(document).on("click","#all_checked2",function(){
    	$(".highcharts-legend-item").each(function(index){
    		chart2.series[index].show();//显示
    	})
    })
    $(document).on("click","#all_no_checked2",function(){
    	$(".highcharts-legend-item").each(function(index){
    		chart2.series[index].hide();//隐藏
    	})
    })
    $(document).on("click","#all_checked3",function(){
    	$(".highcharts-legend-item").each(function(index){
    		chart3.series[index].show();//显示
    	})
    })
    $(document).on("click","#all_no_checked3",function(){
    	$(".highcharts-legend-item").each(function(index){
    		chart3.series[index].hide();//隐藏
    	})
    })
</script>