common.js 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328
  1. var indexName = {'index_128': '预约总量', 'index_129': '居民预约量', 'index_130': '代预约量'};
  2. function getStartDate(chooseYear){
  3. // 按年度来计算的时候,开始时间是该年度7月1号还是到下一个年的6月30号结束
  4. if(chooseYear == 2016){
  5. return chooseYear + "-08-01";
  6. }else{
  7. return chooseYear+'-07-01';
  8. }
  9. }
  10. //获取结束时间
  11. function getEndDate(chooseYear){
  12. chooseYear = parseInt(chooseYear);
  13. var endDate = new Date((chooseYear+1) + '-06-30'),
  14. now = new Date();
  15. if(now <= endDate){
  16. return now.format("yyyy-MM-dd");
  17. }else{
  18. return (chooseYear+1) + '-06-30';
  19. }
  20. }
  21. //获取结束时间29
  22. function getEndDate29(chooseYear){
  23. chooseYear = parseInt(chooseYear);
  24. var endDate = new Date((chooseYear+1) + '-06-29'),
  25. now = new Date();
  26. if(now <= endDate){
  27. return now.format("yyyy-MM-dd");
  28. }else{
  29. return (chooseYear+1) + '-06-29';
  30. }
  31. }
  32. /**
  33. * 获取多少天前的日期
  34. */
  35. function getDateBefore(days) {
  36. var now = new Date();
  37. var date = new Date(now.getTime() - days * 24 * 3600 * 1000);
  38. var year = date.getFullYear();
  39. var month = date.getMonth() + 1;
  40. var day = date.getDate();
  41. var hour = date.getHours();
  42. var minute = date.getMinutes();
  43. var second = date.getSeconds();
  44. return year + '-' + (month < 10 ? '0' + month : month) + '-' + (day < 10 ? '0' + day : day);
  45. }
  46. /*
  47. * 获取用来排序的字段值,返回数组
  48. * 参数: list - 列表, key - 字段的名称
  49. */
  50. function getKeyValueArr(list, key){
  51. var arr = [];
  52. for(var k in list){
  53. arr.push(list[k][key]);
  54. }
  55. return arr;
  56. }
  57. /*
  58. * 排名
  59. */
  60. function soreRank(arr){
  61. var temp = [];
  62. var lis = [];
  63. for(var i=0;i<arr.length;i++){
  64. lis.push(arr[i]);
  65. }
  66. lis = _.uniq(lis);
  67. for(var i=0;i<arr.length;i++){
  68. temp[i] = lis.indexOf(arr[i])+1;
  69. }
  70. return temp;
  71. }
  72. /*
  73. * 绘制饼图数据处理 // elId, arry, title, hasNum,colors,radius,noLedend,param
  74. */
  75. function handlePieData(arg){
  76. var legend = {
  77. orient: 'vertical',
  78. right: '15%',
  79. y:'center',
  80. };
  81. var colorList=[]
  82. legendNames = [];
  83. var arr1 = _.map(arg.arry, function(o,i){
  84. var obj = {
  85. name: o.name,
  86. count: parseInt(o.amount||o[arg.param])
  87. };
  88. legendNames.push(obj);
  89. if(o.code){
  90. colorList.push(arg.colors[o.code])
  91. }else{
  92. colorList.push(arg.colors[i])
  93. }
  94. return {
  95. value: parseInt(o.amount||o[arg.param]),
  96. name: o.name
  97. }
  98. });
  99. legend.formatter = function(name){
  100. if(arg.hasNum){
  101. var target;
  102. for (var i = 0, l = legendNames.length; i < l; i++) {
  103. if (legendNames[i].name == name) {
  104. target = parseInt(legendNames[i].count);
  105. }
  106. }
  107. return name+": "+target
  108. }else{
  109. return name
  110. }
  111. }
  112. if(arg.noLedend){ //true时无注释
  113. drawPie(arg.elId, arr1, colorList, null, arg.position||['50%', '51%'], arg.radius||['70%', '90%'], arg.title)
  114. }else{
  115. drawPie(arg.elId, arr1, colorList, legend, arg.position||['30%', '51%'], arg.radius||['70%', '90%'], arg.title)
  116. }
  117. }
  118. /*
  119. * 绘制饼图
  120. */
  121. function drawPie(elId, arry, color, legend, center, radius, title){
  122. var pieChart = echarts.init(document.getElementById(elId));
  123. var options = {
  124. tooltip: {
  125. trigger: 'item',
  126. formatter: "{b} : {c} ({d}%)",
  127. // position: ['50%', '50%']
  128. },
  129. color: color,
  130. series: [
  131. {
  132. type:'pie',
  133. radius: ['80%', '99%'],
  134. startAngle: 270,
  135. legendHoverLink: false,
  136. hoverAnimation: false,
  137. avoidLabelOverlap: false,
  138. label: {
  139. normal: {
  140. show: false,
  141. textStyle: {
  142. color: "#000",
  143. }
  144. }
  145. },
  146. labelLine: {
  147. normal: {
  148. show: false
  149. }
  150. },
  151. data:arry,
  152. }]
  153. };
  154. if(legend){
  155. options.legend = legend;
  156. }
  157. if(center){
  158. options.series[0].center = center;
  159. }
  160. if(radius){
  161. options.series[0].radius = radius;
  162. }
  163. if(title){
  164. options.title = title
  165. }
  166. pieChart.clear();
  167. pieChart.setOption(options);
  168. }
  169. /*
  170. * 绘制饼图
  171. * arry [{name: '', value: ''}]
  172. * color ['#ffc800', '#17b3ec']
  173. * silent 图形是否不响应和触发鼠标事件,默认为 false,即响应和触发鼠标事件
  174. */
  175. function drawPieChart(elId, arry, color, silent){
  176. var myChart = echarts.init(document.getElementById(elId));
  177. var option = {
  178. tooltip: {
  179. trigger: 'item',
  180. formatter: "{b} : {c} ({d}%)",
  181. position: ['50%', '50%']
  182. },
  183. color: color,
  184. series: [
  185. {
  186. type:'pie',
  187. radius: ['80%', '99%'],
  188. startAngle: 270,
  189. legendHoverLink: false,
  190. hoverAnimation: false,
  191. avoidLabelOverlap: false,
  192. silent: silent,
  193. label: {
  194. normal: {
  195. show: false,
  196. textStyle: {
  197. color: "#000"
  198. }
  199. }
  200. },
  201. labelLine: {
  202. normal: {
  203. show: false
  204. }
  205. },
  206. data:arry
  207. }]
  208. };
  209. $("#"+elId).removeAttr("_echarts_instance_");
  210. myChart.setOption(option);
  211. return myChart;
  212. }
  213. /**
  214. * 绘制柱状图
  215. */
  216. function drawBarChart(el, xData, yData, color, name){
  217. var myChart = echarts.init(document.getElementById(el));
  218. // 指定图表的配置项和数据
  219. var option = {
  220. tooltip: {
  221. trigger: 'item'
  222. },
  223. toolbox: {
  224. dataZoom: true,
  225. show: true,
  226. orient: 'vertical',
  227. x: 'right',
  228. y: 'center'
  229. },
  230. grid: {
  231. left: '20px',
  232. right: '20px',
  233. bottom: '20px',
  234. top: '20px',
  235. containLabel: true
  236. },
  237. xAxis: [{
  238. type: 'category',
  239. data: xData,
  240. axisLabel: {
  241. interval:0,//横轴信息全部显示
  242. },
  243. splitLine: {
  244. show: false
  245. }
  246. }],
  247. yAxis: [{
  248. type: 'value',
  249. splitLine: {show:false}
  250. }],
  251. series: [{
  252. clickable: true,
  253. name: name,
  254. itemStyle : {
  255. normal: {
  256. label : {
  257. show: true, position: 'top'
  258. },
  259. color: color
  260. }
  261. },
  262. barWidth: 20,
  263. type: 'bar',
  264. data: yData
  265. }]
  266. };
  267. // 使用刚指定的配置项和数据显示图表。
  268. myChart.setOption(option);
  269. return myChart;
  270. }
  271. /**
  272. * 绘制折线图数据处理
  273. * @param {Object} elId div的id值
  274. * @param {Object} data 数据值
  275. * @param {Object} selectedDateType true的时候x轴值年-月-日 1-日,2-周, 3-月
  276. */
  277. function getChartData(elId, data, selectedDateType,hasLegend,title,unit){
  278. var dataZoom_end,
  279. xDatas = [],
  280. yDatas = [],
  281. names = [],
  282. colors = ['#12b7f5', '#cd67fd','#FF9526'];
  283. for(var p in data){
  284. if(hasLegend){
  285. names.push(indexName[p]);
  286. }
  287. var xData = _.map(data[p], function(o){
  288. return o.range;
  289. });
  290. var yData = _.map(data[p], function(o){
  291. return o.amount;
  292. });
  293. xDatas.push(xData);
  294. yDatas.push(yData);
  295. var lastIndex = yData.length % 10;
  296. if(yData.length >10 ){
  297. dataZoom_end = 100-(9/yData.length)*100;
  298. }else{
  299. dataZoom_end = 0;
  300. }
  301. }
  302. setTimeout(function(){
  303. EventBus.$emit("draw-line-chart", {
  304. panelName : title,
  305. quotaNames : names,
  306. xData : xDatas[0],
  307. yDatas : yDatas,
  308. colors : colors,
  309. selectedDateType: selectedDateType,
  310. nowlineid : elId,
  311. unit:unit
  312. });
  313. },10)
  314. }