首页 > 开发 > PHP > 正文

php实现按天数、星期、月份查询的搜索框

2024-05-04 22:01:33
字体:大 中 小
来源:转载
供稿:网友

本文实例为大家分享了php实现按天数、星期、月份查询的搜索框,搜索时候展示数据的统计图,主要展示图形的效果,供大家参考,具体内容如下

1.ajax.php

  1. <?php 
  2.  
  3.     $year = $_GET['y']; 
  4.  
  5.     if(!isset($_GET['m'])){ 
  6.  
  7.        $month=1; 
  8.  
  9.     }else{ 
  10.  
  11.          $month = $_GET['m']; 
  12.  
  13.     } 
  14.  
  15.     $week_arr = getMonthWeekArr($year, $month); 
  16.  
  17.     echo json_encode($week_arr); 
  18.  
  19.     die; 
  20.  
  21.        
  22.  
  23.        
  24.  
  25.        
  26.  
  27.   /** 
  28.  
  29.  * 获得系统某月的周数组,第一周不足的需要补足 
  30.  
  31.  *  
  32.  
  33.  * @param int $current_year 
  34.  
  35.  * @param int $current_month 
  36.  
  37.  * @return string[][] 
  38.  
  39.  */ 
  40.  
  41. function getMonthWeekArr($current_year, $current_month){ 
  42.  
  43.      
  44.  
  45.   //该月第一天 
  46.  
  47.   $firstday = strtotime($current_year.'-'.$current_month.'-01'); 
  48.  
  49.   //该月的第一周有几天 
  50.  
  51.   $firstweekday = (7 - date('N',$firstday) +1); 
  52.  
  53.   //计算该月第一个周一的时间 
  54.  
  55.   $starttime = $firstday-3600*24*(7-$firstweekday); 
  56.  
  57.   //该月的最后一天 
  58.  
  59.   $lastday = strtotime($current_year.'-'.$current_month.'-01'." +1 month -1 day"); 
  60.  
  61.   //该月的最后一周有几天 
  62.  
  63.   $lastweekday = date('N',$lastday); 
  64.  
  65.   //该月的最后一个周末的时间 
  66.  
  67.   $endtime = $lastday-3600*24*($lastweekday%7); 
  68.  
  69.   $step = 3600*24*7;//步长值 
  70.  
  71.   $week_arr = array(); 
  72.  
  73.   for ($i=$starttime; $i<$endtime; $i= $i+3600*24*7){ 
  74.  
  75.     $week_arr[] = array('key'=>date('Y-m-d',$i).'|'.date('Y-m-d',$i+3600*24*6), 'val'=>date('Y-m-d',$i).'~'.date('Y-m-d',$i+3600*24*6)); 
  76.  
  77.   } 
  78. //Vevb.com 
  79.   return $week_arr; 
  80.  
  81. } 

2.datehelper.php

  1.  //获得系统年份数组 
  2.  
  3. /** 
  4.  
  5.  *  
  6.  
  7.  * @return string[] 
  8.  
  9.  */ 
  10.  
  11. function getSystemYearArr(){ 
  12.  
  13.   $year_arr = array('2010'=>'2010','2011'=>'2011','2012'=>'2012','2013'=>'2013','2014'=>'2014','2015'=>'2015','2016'=>'2016','2017'=>'2017','2018'=>'2018','2019'=>'2019','2020'=>'2020'); 
  14.  
  15.   return $year_arr; 
  16.  
  17. } 
  18.  
  19.    
  20.  
  21. /** 
  22.  
  23.  * 获得系统月份数组 
  24.  
  25.  *  
  26.  
  27.  * @return array 
  28.  
  29.  */ 
  30.  
  31. function getSystemMonthArr(){ 
  32.  
  33.      
  34.  
  35.   $month_arr = array('1'=>'01','2'=>'02','3'=>'03','4'=>'04','5'=>'05','6'=>'06','7'=>'07','8'=>'08','9'=>'09','10'=>'10','11'=>'11','12'=>'12'); 
  36.  
  37.   return $month_arr; 
  38.  
  39. } 
  40.  
  41.    
  42.  
  43. /** 
  44.  
  45.  * 获得系统周数组 
  46.  
  47.  *  
  48.  
  49.  * @return string[] 
  50.  
  51.  */ 
  52.  
  53. function getSystemWeekArr(){ 
  54.  
  55.   $week_arr = array('1'=>'周一','2'=>'周二','3'=>'周三','4'=>'周四','5'=>'周五','6'=>'周六','7'=>'周日'); 
  56.  
  57.   return $week_arr; 
  58.  
  59. } 
  60.  
  61.    
  62.  
  63. /** 
  64.  
  65.  * 获取某月的最后一天 
  66.  
  67.  *  
  68.  
  69.  * @param int $year 
  70.  
  71.  * @param int $month 
  72.  
  73.  * @return number 
  74.  
  75.  */ 
  76.  
  77. function getMonthLastDay($year, $month){ 
  78.  
  79.      
  80.  
  81.   $t = mktime(0, 0, 0, $month + 1, 1, $year); 
  82.  
  83.   $t = $t - 60 * 60 * 24; 
  84.  
  85.   return $t; 
  86.  
  87. } 
  88.  
  89.    
  90.  
  91. /** 
  92.  
  93.  * 获得系统某月的周数组,第一周不足的需要补足 
  94.  
  95.  *  
  96.  
  97.  * @param int $current_year 
  98.  
  99.  * @param int $current_month 
  100.  
  101.  * @return string[][] 
  102.  
  103.  */ 
  104.  
  105. function getMonthWeekArr($current_year, $current_month){ 
  106.  
  107.      
  108.  
  109.   //该月第一天 
  110.  
  111.   $firstday = strtotime($current_year.'-'.$current_month.'-01'); 
  112.  
  113.   //该月的第一周有几天 
  114.  
  115.   $firstweekday = (7 - date('N',$firstday) +1); 
  116.  
  117.   //计算该月第一个周一的时间 
  118.  
  119.   $starttime = $firstday-3600*24*(7-$firstweekday); 
  120.  
  121.   //该月的最后一天 
  122.  
  123.   $lastday = strtotime($current_year.'-'.$current_month.'-01'." +1 month -1 day"); 
  124.  
  125.   //该月的最后一周有几天 
  126.  
  127.   $lastweekday = date('N',$lastday); 
  128.  
  129.   //该月的最后一个周末的时间 
  130.  
  131.   $endtime = $lastday-3600*24*($lastweekday%7); 
  132.  
  133.   $step = 3600*24*7;//步长值 
  134.  
  135.   $week_arr = array(); 
  136.  
  137.   for ($i=$starttime; $i<$endtime; $i= $i+3600*24*7){ 
  138.  
  139.     $week_arr[] = array('key'=>date('Y-m-d',$i).'|'.date('Y-m-d',$i+3600*24*6), 'val'=>date('Y-m-d',$i).'~'.date('Y-m-d',$i+3600*24*6)); 
  140.  
  141.   } 
  142.  
  143.   return $week_arr; 
  144.  
  145. } 
  146.  
  147.    
  148.  
  149.    
  150.  
  151.    
  152.  
  153.  /** 
  154.  
  155.    * 处理搜索时间 
  156.  
  157.    */ 
  158.  
  159.  function dealwithSearchTime($search_arr=''){ 
  160.  
  161.     //初始化时间 
  162.  
  163.     //天 
  164.  
  165.     if(!isset($search_arr['search_time'])){ 
  166.  
  167.       $search_arr['search_time'] = date('Y-m-d', time()- 86400); 
  168.  
  169.     } 
  170.  
  171.    
  172.  
  173.     $search_arr['day']['search_time'] = strtotime($search_arr['search_time']);//搜索的时间 
  174.  
  175.     //周 
  176.  
  177.     if(!isset($search_arr['searchweek_year'])){ 
  178.  
  179.       $search_arr['searchweek_year'] = date('Y', time()); 
  180.  
  181.     } 
  182.  
  183.     if(!isset($search_arr['searchweek_month'])){ 
  184.  
  185.       $search_arr['searchweek_month'] = date('m', time()); 
  186.  
  187.     } 
  188.  
  189.     if(!isset($search_arr['searchweek_week'])){ 
  190.  
  191.       $search_arr['searchweek_week'] = implode('|', getWeek_SdateAndEdate(time())); 
  192.  
  193.     } 
  194.  
  195.    
  196.  
  197.    
  198.  
  199.     $weekcurrent_year = $search_arr['searchweek_year']; 
  200.  
  201.     $weekcurrent_month = $search_arr['searchweek_month']; 
  202.  
  203.     $weekcurrent_week = $search_arr['searchweek_week']; 
  204.  
  205.     $search_arr['week']['current_year'] = $weekcurrent_year; 
  206.  
  207.     $search_arr['week']['current_month'] = $weekcurrent_month; 
  208.  
  209.     $search_arr['week']['current_week'] = $weekcurrent_week; 
  210.  
  211.    
  212.  
  213.     //月 
  214.  
  215.     if(!isset($search_arr['searchmonth_year'])){ 
  216.  
  217.       $search_arr['searchmonth_year'] = date('Y', time()); 
  218.  
  219.     } 
  220.  
  221.     if(!isset($search_arr['searchmonth_month'])){ 
  222.  
  223.       $search_arr['searchmonth_month'] = date('m', time()); 
  224.  
  225.     } 
  226.  
  227.     $monthcurrent_year = $search_arr['searchmonth_year']; 
  228.  
  229.     $monthcurrent_month = $search_arr['searchmonth_month']; 
  230.  
  231.     $search_arr['month']['current_year'] = $monthcurrent_year; 
  232.  
  233.     $search_arr['month']['current_month'] = $monthcurrent_month; 
  234.  
  235.     return $search_arr; 
  236.  
  237.   } 
  238.  
  239.    
  240.  
  241.   /** 
  242.  
  243.    * 获取本周的开始时间和结束时间 
  244.  
  245.    *  
  246.  
  247.    * @param int $current_time 
  248.  
  249.    * @return string 
  250.  
  251.    */ 
  252.  
  253.   function getWeek_SdateAndEdate($current_time){ 
  254.  
  255.        
  256.  
  257.     $current_time = strtotime(date('Y-m-d',$current_time)); 
  258.  
  259.     $return_arr['sdate'] = date('Y-m-d', $current_time-86400*(date('N',$current_time) - 1)); 
  260.  
  261.     $return_arr['edate'] = date('Y-m-d', $current_time+86400*(7- date('N',$current_time))); 
  262.  
  263.        
  264.  
  265.     return $return_arr; 
  266.  
  267.   } 
  268.  
  269.   /** 
  270.  
  271.    * 查询每月的周数组 
  272.  
  273.    */ 
  274.  
  275.  function getweekofmonth(){ 
  276.  
  277.     $year = $_GET['y']; 
  278.  
  279.     $month = $_GET['m']; 
  280.  
  281.     $week_arr = getMonthWeekArr($year, $month); 
  282.  
  283.     echo json_encode($week_arr); 
  284.  
  285.     die; 
  286.  
  287.   } 

3.statistics.php

  1. <?php 
  2.  
  3. /** 
  4.  
  5.  * 统计 
  6.  
  7.  * 
  8.  
  9.  * @abstract 
  10.  
  11.  * 
  12.  
  13.  * @copyright 格里西,2016 
  14.  
  15.  * 
  16.  
  17.  * @author liujun 
  18.  
  19.  * 
  20.  
  21.  * @version Id:statics v1.0 2016/2/5 
  22.  
  23.  */ 
  24.  
  25.    
  26.  
  27. /** 
  28.  
  29.  * 获得折线图统计图数据 
  30.  
  31.  *  
  32.  
  33.  * param $statarr 图表需要的设置项 
  34.  
  35.  * @return string 
  36.  
  37.  */ 
  38.  
  39. function getStatData_LineLabels($stat_arr){ 
  40.  
  41.      
  42.  
  43.   //图表区、图形区和通用图表配置选项 
  44.  
  45.   $stat_arr['chart']['type'] = 'line'; 
  46.  
  47.   //图表序列颜色数组 
  48.  
  49.   $stat_arr['colors']?'':$stat_arr['colors'] = array('#058DC7', '#ED561B', '#8bbc21', '#0d233a'); 
  50.  
  51.   //去除版权信息 
  52.  
  53.   $stat_arr['credits']['enabled'] = false; 
  54.  
  55.   //导出功能选项 
  56.  
  57.   $stat_arr['exporting']['enabled'] = false; 
  58.  
  59.   //标题如果为字符串则使用默认样式 
  60.  
  61.   is_string($stat_arr['title'])?$stat_arr['title'] = array('text'=>"<b>{$stat_arr['title']}</b>",'x'=>-20):''; 
  62.  
  63.   //子标题如果为字符串则使用默认样式 
  64.  
  65.   is_string($stat_arr['subtitle'])?$stat_arr['subtitle'] = array('text'=>"<b>{$stat_arr['subtitle']}</b>",'x'=>-20):''; 
  66.  
  67.   //Y轴如果为字符串则使用默认样式 
  68.  
  69.   if(is_string($stat_arr['yAxis'])){ 
  70.  
  71.     $text = $stat_arr['yAxis']; 
  72.  
  73.     unset($stat_arr['yAxis']); 
  74.  
  75.     $stat_arr['yAxis']['title']['text'] = $text; 
  76.  
  77.   } 
  78.  
  79.   return json_encode($stat_arr); 
  80.  
  81. } 
  82.  
  83.    
  84.  
  85. /** 
  86.  
  87.  * 获得Column2D统计图数据 
  88.  
  89.  *  
  90.  
  91.  * @param array $stat_arr 
  92.  
  93.  * @return string 
  94.  
  95.  */ 
  96.  
  97. function getStatData_Column2D($stat_arr){ 
  98.  
  99.      
  100.  
  101.   //图表区、图形区和通用图表配置选项 
  102.  
  103.   $stat_arr['chart']['type'] = 'column'; 
  104.  
  105.   //去除版权信息 
  106.  
  107.   $stat_arr['credits']['enabled'] = false; 
  108.  
  109.   //导出功能选项 
  110.  
  111.   $stat_arr['exporting']['enabled'] = false; 
  112.  
  113.   //标题如果为字符串则使用默认样式 
  114.  
  115.   is_string($stat_arr['title'])?$stat_arr['title'] = array('text'=>"<b>{$stat_arr['title']}</b>",'x'=>-20):''; 
  116.  
  117.   //子标题如果为字符串则使用默认样式 
  118.  
  119.   is_string($stat_arr['subtitle'])?$stat_arr['subtitle'] = array('text'=>"<b>{$stat_arr['subtitle']}</b>",'x'=>-20):''; 
  120.  
  121.   //Y轴如果为字符串则使用默认样式 
  122.  
  123.   if(is_string($stat_arr['yAxis'])){ 
  124.  
  125.     $text = $stat_arr['yAxis']; 
  126.  
  127.     unset($stat_arr['yAxis']); 
  128.  
  129.     $stat_arr['yAxis']['title']['text'] = $text; 
  130.  
  131.   } 
  132.  
  133.   //柱形的颜色数组 
  134.  
  135.   $color = array('#7a96a4','#cba952','#667b16','#a26642','#349898','#c04f51','#5c315e','#445a2b','#adae50','#14638a','#b56367','#a399bb','#070dfa','#47ff07','#f809b7'); 
  136.  
  137.      
  138.  
  139.   foreach ($stat_arr['series'] as $series_k=>$series_v){ 
  140.  
  141.     foreach ($series_v['data'] as $data_k=>$data_v){ 
  142.  
  143.       $data_v['color'] = $color[$data_k]; 
  144.  
  145.       $series_v['data'][$data_k] = $data_v; 
  146.  
  147.     } 
  148.  
  149.     $stat_arr['series'][$series_k]['data'] = $series_v['data']; 
  150.  
  151.   } 
  152.  
  153.   //print_r($stat_arr); die; 
  154.  
  155.   return json_encode($stat_arr); 
  156.  
  157. } 
  158.  
  159.    
  160.  
  161. /** 
  162.  
  163.  * 获得Basicbar统计图数据 
  164.  
  165.  *  
  166.  
  167.  * @param array $stat_arr 
  168.  
  169.  * @return string 
  170.  
  171.  */ 
  172.  
  173. function getStatData_Basicbar($stat_arr){ 
  174.  
  175.      
  176.  
  177.   //图表区、图形区和通用图表配置选项 
  178.  
  179.   $stat_arr['chart']['type'] = 'bar'; 
  180.  
  181.   //去除版权信息 
  182.  
  183.   $stat_arr['credits']['enabled'] = false; 
  184.  
  185.   //导出功能选项 
  186.  
  187.   $stat_arr['exporting']['enabled'] = false; 
  188.  
  189.   //显示datalabel 
  190.  
  191.   $stat_arr['plotOptions']['bar']['dataLabels']['enabled'] = true; 
  192.  
  193.   //标题如果为字符串则使用默认样式 
  194.  
  195.   is_string($stat_arr['title'])?$stat_arr['title'] = array('text'=>"<b>{$stat_arr['title']}</b>",'x'=>-20):''; 
  196.  
  197.   //子标题如果为字符串则使用默认样式 
  198.  
  199.   is_string($stat_arr['subtitle'])?$stat_arr['subtitle'] = array('text'=>"<b>{$stat_arr['subtitle']}</b>",'x'=>-20):''; 
  200.  
  201.   //Y轴如果为字符串则使用默认样式 
  202.  
  203.   if(is_string($stat_arr['yAxis'])){ 
  204.  
  205.     $text = $stat_arr['yAxis']; 
  206.  
  207.     unset($stat_arr['yAxis']); 
  208.  
  209.     $stat_arr['yAxis']['title']['text'] = $text; 
  210.  
  211.   } 
  212.  
  213.   //柱形的颜色数组 
  214.  
  215.   $color = array('#7a96a4','#cba952','#667b16','#a26642','#349898','#c04f51','#5c315e','#445a2b','#adae50','#14638a','#b56367','#a399bb','#070dfa','#47ff07','#f809b7'); 
  216.  
  217.      
  218.  
  219.   foreach ($stat_arr['series'] as $series_k=>$series_v){ 
  220.  
  221.     foreach ($series_v['data'] as $data_k=>$data_v){ 
  222.  
  223.       if (!$data_v['color']){ 
  224.  
  225.         $data_v['color'] = $color[$data_k%15]; 
  226.  
  227.       } 
  228.  
  229.       $series_v['data'][$data_k] = $data_v; 
  230.  
  231.     } 
  232.  
  233.     $stat_arr['series'][$series_k]['data'] = $series_v['data']; 
  234.  
  235.   } 
  236.  
  237.   //print_r($stat_arr); die; 
  238.  
  239.   return json_encode($stat_arr); 
  240.  
  241. } 
  242.  
  243.    
  244.  
  245. /** 
  246.  
  247.  * 计算环比 
  248.  
  249.  *  
  250.  
  251.  * @param array $updata 
  252.  
  253.  * @param array $currentdata 
  254.  
  255.  * @return string 
  256.  
  257.  */ 
  258.  
  259. function getHb($updata, $currentdata){ 
  260.  
  261.      
  262.  
  263.   if($updata != 0){ 
  264.  
  265.     $mtomrate = round(($currentdata - $updata)/$updata*100, 2).'%'; 
  266.  
  267.   } else { 
  268.  
  269.     $mtomrate = '-'; 
  270.  
  271.   } 
  272.  
  273.   return $mtomrate;  
  274.  
  275. } 
  276.  
  277.    
  278.  
  279. /** 
  280.  
  281.  * 计算同比 
  282.  
  283.  *  
  284.  
  285.  * @param array $updata 
  286.  
  287.  * @param array $currentdata 
  288.  
  289.  * @return string 
  290.  
  291.  */ 
  292.  
  293. function getTb($updata, $currentdata){ 
  294.  
  295.      
  296.  
  297.   if($updata != 0){ 
  298.  
  299.     $ytoyrate = round(($currentdata - $updata)/$updata*100, 2).'%'; 
  300.  
  301.   } else { 
  302.  
  303.     $ytoyrate = '-'; 
  304.  
  305.   } 
  306.  
  307.   return $ytoyrate;  
  308.  
  309. } 
  310.  
  311.    
  312.  
  313. /** 
  314.  
  315.  * 地图统计图 
  316.  
  317.  *  
  318.  
  319.  * @param array $stat_arr 
  320.  
  321.  * @return string 
  322.  
  323.  */ 
  324.  
  325. function getStatData_Map($stat_arr){ 
  326.  
  327.      
  328.  
  329.   //$color_arr = array('#f63a3a','#ff5858','#ff9191','#ffc3c3','#ffd5d5'); 
  330.  
  331.   $color_arr = array('#fd0b07','#ff9191','#f7ba17','#fef406','#25aae2'); 
  332.  
  333.   $stat_arrnew = array(); 
  334.  
  335.   foreach ($stat_arr as $k=>$v){ 
  336.  
  337.     $stat_arrnew[] = array('cha'=>$v['cha'],'name'=>$v['name'],'des'=>$v['des'],'color'=>$color_arr[$v['level']]); 
  338.  
  339.   } 
  340.  
  341.   return json_encode($stat_arrnew); 
  342.  
  343. } 
  344.  
  345.    
  346.  
  347. /** 
  348.  
  349.  * 获得饼形图数据 
  350.  
  351.  *  
  352.  
  353.  * @param array $data 
  354.  
  355.  * @return string 
  356.  
  357.  */ 
  358.  
  359. function getStatData_Pie($data){ 
  360.  
  361.      
  362.  
  363.   $stat_arr['chart']['type'] = 'pie'; 
  364.  
  365.   $stat_arr['credits']['enabled'] = false; 
  366.  
  367.   $stat_arr['title']['text'] = $data['title']; 
  368.  
  369.   $stat_arr['tooltip']['pointFormat'] = '{series.name}: <b>{point.y}</b>'; 
  370.  
  371.   $stat_arr['plotOptions']['pie'] = array( 
  372.  
  373.     'allowPointSelect'=>true, 
  374.  
  375.     'cursor'=>'pointer', 
  376.  
  377.     'dataLabels'=>array( 
  378.  
  379.       'enabled'=>$data['label_show'], 
  380.  
  381.       'color'=>'#000000', 
  382.  
  383.       'connectorColor'=>'#000000', 
  384.  
  385.       'format'=>'<b>{point.name}</b>: {point.percentage:.1f} %' 
  386.  
  387.     ) 
  388.  
  389.   ); 
  390.  
  391.   $stat_arr['series'][0]['name'] = $data['name']; 
  392.  
  393.   $stat_arr['series'][0]['data'] = array(); 
  394.  
  395.   foreach ($data['series'] as $k=>$v){ 
  396.  
  397.     $stat_arr['series'][0]['data'][] = array($v['p_name'],$v['allnum']); 
  398. //Vevb.com 
  399.   } 
  400.  
  401.   //exit(json_encode($stat_arr)); 
  402.  
  403.   return json_encode($stat_arr); 
  404.  
  405. } 

4.theline.php

  1. <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> 
  2.  
  3. <!--引入ECharts文件--> 
  4.  
  5. <title>Echarts</title> 
  6.  
  7. <script src="js/echarts.common.min.js"></script> 
  8.  
  9.   
  10.  
  11. <script src="js/jquery.js"></script> 
  12.  
  13. <?php include('php/datehelper.php');include('php/statistics.php');?> 
  14.  
  15. <?php  
  16.  
  17.    
  18.  
  19.       //获得系统年份 
  20.  
  21.       $year_arr = getSystemYearArr(); 
  22.  
  23.       //获得系统月份 
  24.  
  25.       $month_arr = getSystemMonthArr(); 
  26.  
  27.       //存储参数 
  28.  
  29.       $search_arr = $_REQUEST; 
  30.  
  31.       $search_arr =dealwithSearchTime($search_arr); 
  32.  
  33.       //获得本月的周时间段 
  34.  
  35.       $week_arr = getMonthWeekArr($search_arr['week']['current_year'],$search_arr['week']['current_month']); 
  36.  
  37.       //天数 
  38.  
  39.       if(!isset($_REQUEST['search_time'])){ 
  40.  
  41.         $_REQUEST['search_time'] = date('Y-m-d', time()-86400); 
  42.  
  43.       } 
  44.  
  45.       $search_time = $_REQUEST['search_time'];//搜索的时间 
  46.  
  47.         //周 
  48.  
  49.       if(!isset($_REQUEST['search_time_year'])){ 
  50.  
  51.         $_REQUEST['search_time_year'] = date('Y', time()); 
  52.  
  53.       } 
  54.  
  55.       if(!isset($_REQUEST['search_time_month'])){ 
  56.  
  57.         $_REQUEST['search_time_month'] = date('m', time()); 
  58.  
  59.       } 
  60.  
  61.       if(!isset($_REQUEST['search_time_week'])){ 
  62.  
  63.         $_REQUEST['search_time_week'] = implode('|', getWeek_SdateAndEdate(time())); 
  64.  
  65.       } 
  66.  
  67.          
  68.  
  69.       $current_year = $_REQUEST['search_time_year']; 
  70.  
  71.       $current_month = $_REQUEST['search_time_month']; 
  72.  
  73.       $current_week = $_REQUEST['search_time_week']; 
  74.  
  75.        
  76.  
  77. ?> 
  78.  
  79. <style> 
  80.  
  81. #search_type{float:left} 
  82.  
  83. #searchtype_day{float:left} 
  84.  
  85. #searchtype_week{float:left} 
  86.  
  87. #searchtype_month{float:left} 
  88.  
  89.    
  90.  
  91.    
  92.  
  93. </style> 
  94.  
  95.   
  96.  
  97.   <select name="search_type" id="search_type"> 
  98.  
  99.          <option value="day">按照天统计</option> 
  100.  
  101.          <option value="week">按照周统计</option> 
  102.  
  103.          <option value="month">按照月统计</option> 
  104.  
  105.     </select> 
  106.  
  107.     <div class="w140" id="searchtype_day"> 
  108.  
  109.       <div class="input-group date" id="datetimepicker1">   
  110.  
  111.         <input id="stime" class="form-control" type="text" value="<?php echo $search_time;?>" name="search_time"> 
  112.  
  113.         <span class="input-group-addon"><span class="glyphicon glyphicon-calendar"></span></span>  
  114.  
  115.       </div>  
  116.  
  117.     </div>   
  118.  
  119.      <div id="searchtype_week" style="display:none;"> 
  120.  
  121.         <select name="search_time_year" id="searchweek_year"> 
  122.  
  123.           <?php foreach ($year_arr as $k=>$v){?> 
  124.  
  125.           <option value="<?php echo $k;?>" <?php="" echo="" $current_year="=" $k?'selected':'';?="">><?php echo $v; ?></option> 
  126.  
  127.           <?php } ?> 
  128.  
  129.         </select> 
  130.  
  131.         <select name="search_time_month" id="searchweek_mouth"> 
  132.  
  133.           <?php foreach ($month_arr as $k=>$v){?> 
  134.  
  135.           <option value="<?php echo $k;?>" <?php="" echo="" $current_month="=" $k?'selected':'';?="">><?php echo $v; ?></option> 
  136.  
  137.           <?php } ?> 
  138.  
  139.         </select> 
  140.  
  141.         <select name="search_time_week" id="searchweek_week"> 
  142.  
  143.           <?php foreach ($week_arr as $k=>$v){?> 
  144.  
  145.           <option value="<?php echo $v['key'];?>" <?php="" echo="" $current_week="=" $v['key']?'selected':'';?=""> ><?php echo $v['val']; ?></option> 
  146.  
  147.           <?php } ?> 
  148.  
  149.         </select> 
  150.  
  151.        </div>  
  152.  
  153.        
  154.  
  155.       <div id="searchtype_month" style="display:none;"> 
  156.  
  157.           <select name="search_time_year" class="querySelect"> 
  158.  
  159.           <?php foreach ($year_arr as $k=>$v){?> 
  160.  
  161.           <option value="<?php echo $k;?>" <?php="" echo="" $current_year="=" $k?'selected':'';?=""> ><?php echo $v; ?></option> 
  162.  
  163.           <?php } ?> 
  164.  
  165.         </select> 
  166.  
  167.         <select name="search_time_month" class="querySelect"> 
  168.  
  169.           <?php foreach ($month_arr as $k=>$v){?> 
  170.  
  171.           <option value="<?php echo $k;?>" <?php="" echo="" $current_month="=" $k?'selected':'';?="">><?php echo $v; ?></option> 
  172.  
  173.           <?php } ?> 
  174.  
  175.         </select> 
  176.  
  177.       </div>  
  178.  
  179.    <div id="line_chart" style="width:600px;height:400px;"></div> 
  180.  
  181.    <?php $thearray=array(11,11,15,13,12,13,10);?> 
  182.  
  183.    <script type="text/javascript"> 
  184.  
  185.     // 基于准备好的dom,初始化echarts实例 
  186.  
  187.    
  188.  
  189.     var mylineChart=echarts.init(document.getElementById('line_chart')); 
  190.  
  191.    
  192.  
  193.     option1 = { 
  194.  
  195.   title: { 
  196.  
  197.     text: '未来一周气温变化', 
  198.  
  199.     subtext: '纯属虚构' 
  200.  
  201.   }, 
  202.  
  203.   tooltip: { 
  204.  
  205.     trigger: 'axis' 
  206.  
  207.   }, 
  208.  
  209.   legend: { 
  210.  
  211.     data:['最高气温','最低气温'] 
  212.  
  213.   }, 
  214.  
  215.   toolbox: { 
  216.  
  217.     show: true, 
  218.  
  219.     feature: { 
  220.  
  221.       dataZoom: {}, 
  222.  
  223.       // dataView: {readOnly: false}, 
  224.  
  225.       magicType: {type: ['line', 'bar']}, 
  226.  
  227.       restore: {}, 
  228.  
  229.       saveAsImage: {} 
  230.  
  231.     } 
  232.  
  233.   }, 
  234.  
  235.   xAxis: { 
  236.  
  237.     type: 'category', 
  238.  
  239.     boundaryGap: false, 
  240.  
  241.     data: ['周一','周二','周三','周四','周五','周六','周日'] 
  242.  
  243.   }, 
  244.  
  245.   yAxis: { 
  246.  
  247.     type: 'value', 
  248.  
  249.     axisLabel: { 
  250.  
  251.       formatter: '{value} °C' 
  252.  
  253.     } 
  254.  
  255.   }, 
  256.  
  257.   series: [ 
  258.  
  259.     { 
  260.  
  261.       name:'最高气温', 
  262.  
  263.       type:'line', 
  264.  
  265.       data:<?php echo(json_encode($thearray)); ?>, 
  266.  
  267.       markPoint: { 
  268.  
  269.         data: [ 
  270.  
  271.           {type: 'max', name: '最大值'}, 
  272.  
  273.           {type: 'min', name: '最小值'} 
  274.  
  275.         ] 
  276.  
  277.       }, 
  278.  
  279.       markLine: { 
  280.  
  281.         data: [ 
  282.  
  283.           {type: 'average', name: '平均值'} 
  284.  
  285.         ] 
  286.  
  287.       } 
  288.  
  289.     }, 
  290.  
  291.     { 
  292.  
  293.       name:'最低气温', 
  294.  
  295.       type:'line', 
  296.  
  297.       data:[1, 4, 2, 5, 3, 2, 0], 
  298.  
  299.       markPoint: { 
  300.  
  301.         data: [ 
  302.  
  303.           {name: '周最低', value: -2, xAxis: 1, yAxis: -1.5} 
  304.  
  305.         ] 
  306.  
  307.       }, 
  308.  
  309.       markLine: { 
  310.  
  311.         data: [ 
  312.  
  313.           {type: 'average', name: '平均值'} 
  314.  
  315.         ] 
  316.  
  317.       } 
  318.  
  319.     } 
  320.  
  321.   ] 
  322.  
  323. }; 
  324.  
  325.     // 使用刚指定的配置项和数据显示图表。 
  326.  
  327.     mylineChart.setOption(option1); 
  328.  
  329.   </script> 
  330.  
  331.   <script> 
  332.  
  333.   //展示搜索时间框 
  334.  
  335. function show_searchtime(){ 
  336.  
  337.   s_type = $("#search_type").val(); 
  338.  
  339.   $("[id^='searchtype_']").hide(); 
  340.  
  341.   $("#searchtype_"+s_type).show(); 
  342.  
  343. } 
  344.  
  345.   $(function(){ 
  346.  
  347.       
  348.  
  349.     show_searchtime(); 
  350.  
  351.   $("#search_type").change(function(){ 
  352.  
  353.     show_searchtime(); 
  354.  
  355.   }); 
  356.  
  357.       
  358.  
  359.   //更新周数组 
  360.  
  361.   $("[name='search_time_month']").change(function(){ 
  362.  
  363.      
  364.  
  365.     var year = $("[name='search_time_year']").val(); 
  366.  
  367.     var month = $("[name='search_time_month']").val(); 
  368.  
  369.    
  370.  
  371.     $("[name='search_time_week']").emptyempty(); 
  372.  
  373.     $.getJSON('php/ajax.php',{y:year,m:month},function(data){ 
  374.  
  375.       if(data != null){ 
  376.  
  377.         for(var i = 0; i < data.length; i++) { 
  378.  
  379.           $("[name='search_time_week']").append('<option value="'+data[i].key+'">'+data[i].val+'</option>'); 
  380.  
  381.         } 
  382.  
  383.       } 
  384.  
  385.     }); 
  386.  
  387.   }); 
  388.  
  389.   //更新年数组 
  390.  
  391.     $("[name='search_time_year']").change(function(){ 
  392.  
  393.     var year = $("[name='search_time_year']").val(); 
  394.  
  395.        
  396.  
  397.     $("[name='search_time_week']").emptyempty(); 
  398.  
  399.     $("#searchweek_mouth option:first").prop("selected", 'selected');  
  400.  
  401.     $.getJSON('php/ajax.php',{y:year},function(data){ 
  402.  
  403.       if(data != null){ 
  404.  
  405.         for(var i = 0; i < data.length; i++) { 
  406.  
  407.           $("[name='search_time_week']").append('<option value="'+data[i].key+'">'+data[i].val+'</option>');          
  408.  
  409.         } 
  410.  
  411.       } 
  412.  
  413.     }); 
  414.  
  415.   }); 
  416.  
  417.   }); 
  418.  
  419.   </script> 

5.time_deal.php

  1. <?php  
  2.  
  3.    
  4.  
  5. //获取系统年份 
  6.  
  7. /** 
  8.  
  9.  *  
  10.  
  11.  * @return string[] 
  12.  
  13.  */ 
  14.  
  15. function getSystemYearArr(){ 
  16.  
  17.      
  18.  
  19.   $year_arr = array('2010'=>'2010','2011'=>'2011','2012'=>'2012','2013'=>'2013','2014'=>'2014','2015'=>'2015','2016'=>'2016','2017'=>'2017','2018'=>'2018','2019'=>'2019','2020'=>'2020'); 
  20.  
  21.   return $year_arr; 
  22.  
  23. } 
  24.  
  25.    
  26.  
  27. /** 
  28.  
  29.  * 获得系统月份数组 
  30.  
  31.  *  
  32.  
  33.  * @return array 
  34.  
  35.  */ 
  36.  
  37. function getSystemMonthArr(){ 
  38.  
  39.      
  40.  
  41.   $month_arr = array('1'=>'01','2'=>'02','3'=>'03','4'=>'04','5'=>'05','6'=>'06','7'=>'07','8'=>'08','9'=>'09','10'=>'10','11'=>'11','12'=>'12'); 
  42.  
  43.   return $month_arr; 
  44.  
  45. } 
  46.  
  47.    
  48.  
  49.   /** 
  50.  
  51.    * 处理搜索时间 
  52.  
  53.    */ 
  54.  
  55.   public function dealwithSearchTime($search_arr){ 
  56.  
  57.     //初始化时间 
  58.  
  59.     //天 
  60.  
  61.     if(!$search_arr['search_time']){ 
  62.  
  63.       $search_arr['search_time'] = date('Y-m-d', time()- 86400); 
  64.  
  65.     } 
  66.  
  67.     $search_arr['day']['search_time'] = strtotime($search_arr['search_time']);//搜索的时间 
  68.  
  69.      
  70.  
  71.     //周 
  72.  
  73.     if(!$search_arr['searchweek_year']){ 
  74.  
  75.       $search_arr['searchweek_year'] = date('Y', time()); 
  76.  
  77.     } 
  78.  
  79.     if(!$search_arr['searchweek_month']){ 
  80.  
  81.       $search_arr['searchweek_month'] = date('m', time()); 
  82.  
  83.     } 
  84.  
  85.     if(!$search_arr['searchweek_week']){ 
  86.  
  87.       $search_arr['searchweek_week'] = implode('|', getWeek_SdateAndEdate(time())); 
  88.  
  89.     } 
  90.  
  91.     $weekcurrent_year = $search_arr['searchweek_year']; 
  92.  
  93.     $weekcurrent_month = $search_arr['searchweek_month']; 
  94.  
  95.     $weekcurrent_week = $search_arr['searchweek_week']; 
  96.  
  97.     $search_arr['week']['current_year'] = $weekcurrent_year; 
  98.  
  99.     $search_arr['week']['current_month'] = $weekcurrent_month; 
  100.  
  101.     $search_arr['week']['current_week'] = $weekcurrent_week; 
  102.  
  103.      
  104.  
  105.     //月 
  106.  
  107.     if(!$search_arr['searchmonth_year']){ 
  108.  
  109.       $search_arr['searchmonth_year'] = date('Y', time()); 
  110.  
  111.     } 
  112.  
  113.     if(!$search_arr['searchmonth_month']){ 
  114.  
  115.       $search_arr['searchmonth_month'] = date('m', time()); 
  116.  
  117.     } 
  118.  
  119.     $monthcurrent_year = $search_arr['searchmonth_year']; 
  120.  
  121.     $monthcurrent_month = $search_arr['searchmonth_month']; 
  122.  
  123.     $search_arr['month']['current_year'] = $monthcurrent_year; 
  124.  
  125.     $search_arr['month']['current_month'] = $monthcurrent_month; 
  126.  
  127.     return $search_arr; 
  128.  
  129.   } 

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表