common.js 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. function getStartDate(chooseYear){
  2. // 按年度来计算的时候,开始时间是该年度7月1号还是到下一个年的6月30号结束
  3. if(chooseYear == 2016){
  4. return chooseYear + "-08-01";
  5. }else{
  6. return chooseYear+'-07-01';
  7. }
  8. }
  9. //获取结束时间
  10. function getEndDate(chooseYear){
  11. chooseYear = parseInt(chooseYear);
  12. var endDate = new Date((chooseYear+1) + '-06-30'),
  13. now = new Date();
  14. if(now <= endDate){
  15. return now.format("yyyy-MM-dd");
  16. }else{
  17. return (chooseYear+1) + '-06-30';
  18. }
  19. }
  20. /**
  21. * 获取多少天前的日期
  22. */
  23. function getDateBefore(days) {
  24. var now = new Date();
  25. var date = new Date(now.getTime() - days * 24 * 3600 * 1000);
  26. var year = date.getFullYear();
  27. var month = date.getMonth() + 1;
  28. var day = date.getDate();
  29. var hour = date.getHours();
  30. var minute = date.getMinutes();
  31. var second = date.getSeconds();
  32. return year + '-' + (month < 10 ? '0' + month : month) + '-' + (day < 10 ? '0' + day : day);
  33. }
  34. /*
  35. * 获取用来排序的字段值,返回数组
  36. * 参数: list - 列表, key - 字段的名称
  37. */
  38. function getKeyValueArr(list, key){
  39. var arr = [];
  40. for(var k in list){
  41. arr.push(list[k][key]);
  42. }
  43. return arr;
  44. }
  45. /*
  46. * 排名
  47. */
  48. function soreRank(arr){
  49. var temp = [];
  50. var lis = [];
  51. for(var i=0;i<arr.length;i++){
  52. lis.push(arr[i]);
  53. }
  54. lis = _.uniq(lis);
  55. for(var i=0;i<arr.length;i++){
  56. temp[i] = lis.indexOf(arr[i])+1;
  57. }
  58. return temp;
  59. }
  60. /*
  61. * 绘制饼图
  62. * arry [{name: '', value: ''}]
  63. * color ['#ffc800', '#17b3ec']
  64. * silent 图形是否不响应和触发鼠标事件,默认为 false,即响应和触发鼠标事件
  65. */
  66. function drawPieChart(elId, arry, color, silent){
  67. var myChart = echarts.init(document.getElementById(elId));
  68. var option = {
  69. tooltip: {
  70. trigger: 'item',
  71. formatter: "{b} : {c} ({d}%)",
  72. position: ['50%', '50%']
  73. },
  74. color: color,
  75. series: [
  76. {
  77. type:'pie',
  78. radius: ['80%', '99%'],
  79. startAngle: 270,
  80. legendHoverLink: false,
  81. hoverAnimation: false,
  82. avoidLabelOverlap: false,
  83. silent: silent,
  84. label: {
  85. normal: {
  86. show: false,
  87. textStyle: {
  88. color: "#000"
  89. }
  90. }
  91. },
  92. labelLine: {
  93. normal: {
  94. show: false
  95. }
  96. },
  97. data:arry
  98. }]
  99. };
  100. $("#"+elId).removeAttr("_echarts_instance_");
  101. myChart.setOption(option);
  102. return myChart;
  103. }
  104. /**
  105. * 绘制柱状图
  106. */
  107. function drawBarChart(el, xData, yData, color, name){
  108. var myChart = echarts.init(document.getElementById(el));
  109. // 指定图表的配置项和数据
  110. var option = {
  111. tooltip: {
  112. trigger: 'item'
  113. },
  114. toolbox: {
  115. dataZoom: true,
  116. show: true,
  117. orient: 'vertical',
  118. x: 'right',
  119. y: 'center'
  120. },
  121. grid: {
  122. left: '20px',
  123. right: '20px',
  124. bottom: '20px',
  125. top: '20px',
  126. containLabel: true
  127. },
  128. xAxis: [{
  129. type: 'category',
  130. data: xData,
  131. axisLabel: {
  132. interval:0,//横轴信息全部显示
  133. },
  134. splitLine: {
  135. show: false
  136. }
  137. }],
  138. yAxis: [{
  139. type: 'value',
  140. splitLine: {show:false}
  141. }],
  142. series: [{
  143. clickable: true,
  144. name: name,
  145. itemStyle : {
  146. normal: {
  147. label : {
  148. show: true, position: 'top'
  149. },
  150. color: color
  151. }
  152. },
  153. barWidth: 20,
  154. type: 'bar',
  155. data: yData
  156. }]
  157. };
  158. // 使用刚指定的配置项和数据显示图表。
  159. myChart.setOption(option);
  160. return myChart;
  161. }