report.js 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. var reportUtil = {};
  2. reportUtil.splineOptions = {
  3. chart: {
  4. type: 'spline'
  5. },
  6. title: {
  7. text: null //无标题
  8. },
  9. credits: {
  10. enabled: false //不显版权
  11. },
  12. xAxis: {
  13. categories: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun','Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
  14. },
  15. yAxis: {
  16. title: {
  17. text: '' //y轴文字
  18. },
  19. plotLines: [{
  20. value: 0,
  21. width: 1,
  22. color: '#808080'
  23. }]
  24. },
  25. tooltip: {
  26. crosshairs: true
  27. //shared: true
  28. //headerFormat: '<span style="color: rgb(90, 90, 90);">{point.key} ({point.percentage:.1f}%)</span><br/>', //百分比(用于饼图)
  29. //headerFormat: '<span style="color: rgb(90, 90, 90);">{series.name}</span><br/>',
  30. //pointFormat: '<span style="color: rgb(90, 90, 90);">{point.x}点: {point.y}</span>'
  31. },
  32. series: [{
  33. name: 'Tokyo', //x轴文字
  34. data: [7.0, 6.9, 9.5, 14.5, 18.2, 21.5, 25.2, 26.5, 23.3, 18.3, 13.9, 9.6]
  35. }]
  36. }
  37. /**
  38. * 获得曲线参数
  39. * @param categories x轴显示数据
  40. * @param series 数据列表
  41. * @param yText y轴文字
  42. * @returns 参数对象
  43. */
  44. reportUtil.getSplineOptions = function(categories, series, yText) {
  45. var options = {};
  46. $.extend(options, reportUtil.splineOptions);
  47. options.xAxis.categories = categories; //x轴显示数据
  48. options.series = series; //数据列表
  49. options.yAxis.title.text = yText; //y轴文字
  50. return options;
  51. }
  52. $(function() {
  53. $(document).ajaxSend(function(evt, request, settings){
  54. showLoading();
  55. });
  56. $(document).ajaxComplete(function(evt, request, settings){
  57. removeLoading();
  58. });
  59. })
  60. /**
  61. * 显示加载效果(需要引入spin.min.js)
  62. */
  63. function showLoading() {
  64. if($("#showLoadingDiv").length == 0) {
  65. $("body").append($("<div id=showLoadingDiv>").css({
  66. position: "fixed",
  67. _position: "absolute",
  68. width: "100%",
  69. height: $(window.document).height(),
  70. top: "0",
  71. left: "0",
  72. opacity: "0.6",
  73. filter: "alpha(opacity = 60)",
  74. background: "white",
  75. display: "none",
  76. "z-index": "9999"
  77. })
  78. .append($("<div>").css({
  79. width: "100px",
  80. height: "100px",
  81. position: "absolute",
  82. top: $(window).height()/2,
  83. left: "50%"
  84. })
  85. .append(new Spinner().spin().el)
  86. ));
  87. }
  88. $(".spinner").css("position", "static");
  89. $("#showLoadingDiv").fadeIn(200);
  90. }
  91. /**
  92. * 移除加载效果
  93. */
  94. function removeLoading() {
  95. $("#showLoadingDiv").fadeOut(200);
  96. }
  97. /**
  98. * 计算天数差的函数
  99. */
  100. function dateDiff(sDate1, sDate2){ //sDate1和sDate2是2006-12-18格式
  101. var aDate, oDate1, oDate2, iDays
  102. aDate = sDate1.split("-")
  103. oDate1 = new Date(aDate[1] + '-' + aDate[2] + '-' + aDate[0]) //转换为12-18-2006格式
  104. aDate = sDate2.split("-")
  105. oDate2 = new Date(aDate[1] + '-' + aDate[2] + '-' + aDate[0])
  106. iDays = parseInt(Math.abs(oDate1 - oDate2) / 1000 / 60 / 60 /24) //把相差的毫秒数转换为天数
  107. return iDays
  108. }
  109. /**
  110. * 获得两日期之间
  111. */
  112. function getBetweenDay(startDate, endDate) {
  113. var dayCount = dateDiff(endDate, startDate);
  114. var spliteStartDate = startDate.split("-");
  115. var startYear = parseInt(spliteStartDate[0]);
  116. var startMonth = parseInt(spliteStartDate[1]);
  117. var startDay = parseInt(spliteStartDate[2]);
  118. var result = new Array();
  119. for(var i = 0; i <= dayCount; i++) {
  120. var d = new Date(startYear, startMonth - 1, startDay + i);
  121. result.push(d.getFullYear() + "-" + (d.getMonth() + 1) + "-" + d.getDate());
  122. }
  123. return result;
  124. }
  125. /**
  126. * 控制台打印信息(对IE做了兼容)
  127. */
  128. function log(msg) {
  129. try {
  130. if(console) {
  131. console.log(msg);
  132. }
  133. } catch (e) {
  134. // TODO: handle exception
  135. }
  136. }