statistics.php 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. <?php
  2. /**
  3. * 获得折线图统计图数据
  4. * param $statarr 图表需要的设置项
  5. */
  6. function getStatData_LineLabels($stat_arr){
  7. //图表区、图形区和通用图表配置选项
  8. $stat_arr['chart']['type'] = 'line';
  9. //图表序列颜色数组
  10. isset($stat_arr['colors'])?'':$stat_arr['colors'] = array('#058DC7', '#ED561B', '#8bbc21', '#0d233a');
  11. //去除版权信息
  12. $stat_arr['credits']['enabled'] = false;
  13. //导出功能选项
  14. $stat_arr['exporting']['enabled'] = false;
  15. //标题如果为字符串则使用默认样式
  16. is_string($stat_arr['title'])?$stat_arr['title'] = array('text'=>"<b>{$stat_arr['title']}</b>",'x'=>-20):'';
  17. //子标题如果为字符串则使用默认样式
  18. if(isset($stat_arr['subtitle'])) {
  19. is_string($stat_arr['subtitle']) ? $stat_arr['subtitle'] = array(
  20. 'text' => "<b>{$stat_arr['subtitle']}</b>", 'x' => -20
  21. ) : '';
  22. }
  23. //Y轴如果为字符串则使用默认样式
  24. if(is_string($stat_arr['yAxis'])){
  25. $text = $stat_arr['yAxis'];
  26. unset($stat_arr['yAxis']);
  27. $stat_arr['yAxis']['title']['text'] = $text;
  28. }
  29. return json_encode($stat_arr);
  30. }
  31. /**
  32. * 获得Column2D统计图数据
  33. */
  34. function getStatData_Column2D($stat_arr){
  35. //图表区、图形区和通用图表配置选项
  36. $stat_arr['chart']['type'] = 'column';
  37. //去除版权信息
  38. $stat_arr['credits']['enabled'] = false;
  39. //导出功能选项
  40. $stat_arr['exporting']['enabled'] = false;
  41. //标题如果为字符串则使用默认样式
  42. is_string($stat_arr['title'])?$stat_arr['title'] = array('text'=>"<b>{$stat_arr['title']}</b>",'x'=>-20):'';
  43. //子标题如果为字符串则使用默认样式
  44. if(isset($stat_arr['subtitle'])) {
  45. is_string($stat_arr['subtitle']) ? $stat_arr['subtitle'] = array(
  46. 'text' => "<b>{$stat_arr['subtitle']}</b>", 'x' => -20
  47. ) : '';
  48. }
  49. //Y轴如果为字符串则使用默认样式
  50. if(is_string($stat_arr['yAxis'])){
  51. $text = $stat_arr['yAxis'];
  52. unset($stat_arr['yAxis']);
  53. $stat_arr['yAxis']['title']['text'] = $text;
  54. }
  55. //柱形的颜色数组
  56. $color = array('#7a96a4','#cba952','#667b16','#a26642','#349898','#c04f51','#5c315e','#445a2b','#adae50','#14638a','#b56367','#a399bb','#070dfa','#47ff07','#f809b7');
  57. foreach ($stat_arr['series'] as $series_k=>$series_v){
  58. foreach ($series_v['data'] as $data_k=>$data_v){
  59. $data_v['color'] = $color[$data_k%15];
  60. $series_v['data'][$data_k] = $data_v;
  61. }
  62. $stat_arr['series'][$series_k]['data'] = $series_v['data'];
  63. }
  64. //print_r($stat_arr); die;
  65. return json_encode($stat_arr);
  66. }
  67. /**
  68. * 获得Basicbar统计图数据
  69. */
  70. function getStatData_Basicbar($stat_arr){
  71. //图表区、图形区和通用图表配置选项
  72. $stat_arr['chart']['type'] = 'bar';
  73. //去除版权信息
  74. $stat_arr['credits']['enabled'] = false;
  75. //导出功能选项
  76. $stat_arr['exporting']['enabled'] = false;
  77. //显示datalabel
  78. $stat_arr['plotOptions']['bar']['dataLabels']['enabled'] = true;
  79. //标题如果为字符串则使用默认样式
  80. is_string($stat_arr['title'])?$stat_arr['title'] = array('text'=>"<b>{$stat_arr['title']}</b>",'x'=>-20):'';
  81. //子标题如果为字符串则使用默认样式
  82. if (isset($stat_arr['subtitle'])) {
  83. is_string($stat_arr['subtitle']) ? $stat_arr['subtitle'] = array(
  84. 'text' => "<b>{$stat_arr['subtitle']}</b>", 'x' => -20
  85. ) : '';
  86. }
  87. //Y轴如果为字符串则使用默认样式
  88. if(is_string($stat_arr['yAxis'])){
  89. $text = $stat_arr['yAxis'];
  90. unset($stat_arr['yAxis']);
  91. $stat_arr['yAxis']['title']['text'] = $text;
  92. }
  93. //柱形的颜色数组1
  94. $color = array('#7a96a4','#cba952','#667b16','#a26642','#349898','#c04f51','#5c315e','#445a2b','#adae50','#14638a','#b56367','#a399bb','#070dfa','#47ff07','#f809b7');
  95. foreach ($stat_arr['series'] as $series_k=>$series_v){
  96. foreach ($series_v['data'] as $data_k=>$data_v){
  97. if (!isset($data_v['color'])){
  98. $data_v['color'] = $color[$data_k%15];
  99. }
  100. $series_v['data'][$data_k] = $data_v;
  101. }
  102. $stat_arr['series'][$series_k]['data'] = $series_v['data'];
  103. }
  104. //print_r($stat_arr); die;
  105. return json_encode($stat_arr);
  106. }
  107. /**
  108. * 计算环比
  109. */
  110. function getHb($updata, $currentdata){
  111. if($updata != 0){
  112. $mtomrate = round(($currentdata - $updata)/$updata*100, 2).'%';
  113. } else {
  114. $mtomrate = '-';
  115. }
  116. return $mtomrate;
  117. }
  118. /**
  119. * 计算同比
  120. */
  121. function getTb($updata, $currentdata){
  122. if($updata != 0){
  123. $ytoyrate = round(($currentdata - $updata)/$updata*100, 2).'%';
  124. } else {
  125. $ytoyrate = '-';
  126. }
  127. return $ytoyrate;
  128. }
  129. /**
  130. * 地图统计图
  131. */
  132. function getStatData_Map($stat_arr){
  133. //$color_arr = array('#f63a3a','#ff5858','#ff9191','#ffc3c3','#ffd5d5');
  134. $color_arr = array('#fd0b07','#ff9191','#f7ba17','#fef406','#25aae2');
  135. $stat_arrnew = array();
  136. foreach ($stat_arr as $k=>$v){
  137. $stat_arrnew[] = array('cha'=>$v['cha'],'name'=>$v['name'],'des'=>$v['des'],'color'=>$color_arr[$v['level']]);
  138. }
  139. return json_encode($stat_arrnew);
  140. }
  141. /**
  142. * 获得饼形图数据
  143. */
  144. function getStatData_Pie($data){
  145. $stat_arr['chart']['type'] = 'pie';
  146. $stat_arr['credits']['enabled'] = false;
  147. $stat_arr['title']['text'] = $data['title'];
  148. $stat_arr['tooltip']['pointFormat'] = '{series.name}: <b>{point.y}</b>';
  149. $stat_arr['plotOptions']['pie'] = array(
  150. 'allowPointSelect'=>true,
  151. 'cursor'=>'pointer',
  152. 'dataLabels'=>array(
  153. 'enabled'=>$data['label_show'],
  154. 'color'=>'#000000',
  155. 'connectorColor'=>'#000000',
  156. 'format'=>'<b>{point.name}</b>: {point.percentage:.1f} %'
  157. )
  158. );
  159. $stat_arr['series'][0]['name'] = $data['name'];
  160. $stat_arr['series'][0]['data'] = array();
  161. foreach ($data['series'] as $k=>$v){
  162. $stat_arr['series'][0]['data'][] = array($v['p_name'],$v['allnum']);
  163. }
  164. //exit(json_encode($stat_arr));
  165. return json_encode($stat_arr);
  166. }