index.js 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. /**
  2. * Created by xuxueli on 17/4/24.
  3. */
  4. $(function () {
  5. // 过滤时间
  6. var _startDate = moment().subtract(1, 'months'); // 默认,最近一月
  7. var _endDate = moment();
  8. $('#filterTime').daterangepicker({
  9. autoApply:false,
  10. singleDatePicker:false,
  11. showDropdowns:false, // 是否显示年月选择条件
  12. timePicker: true, // 是否显示小时和分钟选择条件
  13. timePickerIncrement: 10, // 时间的增量,单位为分钟
  14. timePicker24Hour : true,
  15. opens : 'left', //日期选择框的弹出位置
  16. ranges: {
  17. //'最近1小时': [moment().subtract(1, 'hours'), moment()],
  18. '今日': [moment().startOf('day'), moment().endOf('day')],
  19. '昨日': [moment().subtract(1, 'days').startOf('day'), moment().subtract(1, 'days').endOf('day')],
  20. '本月': [moment().startOf('month'), moment().endOf('month')],
  21. '上个月': [moment().subtract(1, 'months').startOf('month'), moment().subtract(1, 'months').endOf('month')],
  22. '最近1周': [moment().subtract(1, 'weeks'), moment()],
  23. '最近1月': [_startDate, _endDate]
  24. },
  25. locale : {
  26. format: 'YYYY-MM-DD HH:mm:ss',
  27. separator : ' - ',
  28. customRangeLabel : '自定义',
  29. applyLabel : '确定',
  30. cancelLabel : '取消',
  31. fromLabel : '起始时间',
  32. toLabel : '结束时间',
  33. daysOfWeek : [ '日', '一', '二', '三', '四', '五', '六' ],
  34. monthNames : [ '一月', '二月', '三月', '四月', '五月', '六月', '七月', '八月', '九月', '十月', '十一月', '十二月' ],
  35. firstDay : 1
  36. },
  37. startDate:_startDate,
  38. endDate: _endDate
  39. }, function (start, end, label) {
  40. freshChartDate(start, end);
  41. });
  42. freshChartDate(_startDate, _endDate);
  43. /**
  44. * 刷新报表
  45. *
  46. * @param startDate
  47. * @param endDate
  48. */
  49. function freshChartDate(startDate, endDate) {
  50. $.ajax({
  51. type : 'POST',
  52. url : base_url + '/triggerChartDate',
  53. data : {
  54. 'startDate':startDate.format('YYYY-MM-DD HH:mm:ss'),
  55. 'endDate':endDate.format('YYYY-MM-DD HH:mm:ss')
  56. },
  57. dataType : "json",
  58. success : function(data){
  59. if (data.code == 200) {
  60. lineChartInit(data)
  61. pieChartInit(data);
  62. } else {
  63. layer.open({
  64. title: '系统提示',
  65. content: (data.msg || '调度报表数据加载异常'),
  66. icon: '2'
  67. });
  68. }
  69. }
  70. });
  71. }
  72. /**
  73. * 折线图
  74. */
  75. function lineChartInit(data) {
  76. var option = {
  77. title: {
  78. text: '日期分布图'
  79. },
  80. tooltip : {
  81. trigger: 'axis',
  82. axisPointer: {
  83. type: 'cross',
  84. label: {
  85. backgroundColor: '#6a7985'
  86. }
  87. }
  88. },
  89. legend: {
  90. data:['成功调度次数','失败调度次数']
  91. },
  92. toolbox: {
  93. feature: {
  94. /*saveAsImage: {}*/
  95. }
  96. },
  97. grid: {
  98. left: '3%',
  99. right: '4%',
  100. bottom: '3%',
  101. containLabel: true
  102. },
  103. xAxis : [
  104. {
  105. type : 'category',
  106. boundaryGap : false,
  107. data : data.content.triggerDayList
  108. }
  109. ],
  110. yAxis : [
  111. {
  112. type : 'value'
  113. }
  114. ],
  115. series : [
  116. {
  117. name:'成功调度次数',
  118. type:'line',
  119. stack: '总量',
  120. areaStyle: {normal: {}},
  121. data: data.content.triggerDayCountSucList
  122. },
  123. {
  124. name:'失败调度次数',
  125. type:'line',
  126. stack: '总量',
  127. label: {
  128. normal: {
  129. show: true,
  130. position: 'top'
  131. }
  132. },
  133. areaStyle: {normal: {}},
  134. data: data.content.triggerDayCountFailList
  135. }
  136. ],
  137. color:['#00A65A', '#F39C12']
  138. };
  139. var lineChart = echarts.init(document.getElementById('lineChart'));
  140. lineChart.setOption(option);
  141. }
  142. /**
  143. * 饼图
  144. */
  145. function pieChartInit(data) {
  146. var option = {
  147. title : {
  148. text: '成功比例图',
  149. /*subtext: 'subtext',*/
  150. x:'center'
  151. },
  152. tooltip : {
  153. trigger: 'item',
  154. formatter: "{a} <br/>{b} : {c} ({d}%)"
  155. },
  156. legend: {
  157. orient: 'vertical',
  158. left: 'left',
  159. data: ['成功调度次数','失败调度次数']
  160. },
  161. series : [
  162. {
  163. name: '分布比例',
  164. type: 'pie',
  165. radius : '55%',
  166. center: ['50%', '60%'],
  167. data:[
  168. {
  169. value:data.content.triggerCountSucTotal,
  170. name:'成功调度次数'
  171. },
  172. {
  173. value:data.content.triggerCountFailTotal,
  174. name:'失败调度次数'
  175. }
  176. ],
  177. itemStyle: {
  178. emphasis: {
  179. shadowBlur: 10,
  180. shadowOffsetX: 0,
  181. shadowColor: 'rgba(0, 0, 0, 0.5)'
  182. }
  183. }
  184. }
  185. ],
  186. color:['#00A65A', '#F39C12']
  187. };
  188. var pieChart = echarts.init(document.getElementById('pieChart'));
  189. pieChart.setOption(option);
  190. }
  191. });