annualdata.js 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  1. /**
  2. * Draw status pie chart.
  3. *
  4. * @param string $id
  5. * @param string $title
  6. * @param array $data
  7. * @param function $callback
  8. * @access public
  9. * @return object
  10. */
  11. function drawStatusPieChart(id, title, data, callback)
  12. {
  13. var titleTextStyle = {
  14. color:'#fff',
  15. fontSize: 14
  16. };
  17. var tooltip = {
  18. trigger: 'item',
  19. backgroundColor: '#010419',
  20. textStyle: {color:'#fff'},
  21. formatter: '{a} <br/>{b}: {c} ({d}%)'
  22. };
  23. var legendLeft = '0';
  24. var legendTop = '25';
  25. var legendItemWidth = 8;
  26. var legendItemHeight = 8;
  27. var legendTextStyle = {
  28. color:'#fff',
  29. fontSize: 12
  30. };
  31. var seriesTop = '50';
  32. var seriesRadius = ['40%', '70%'];
  33. var seriesLabel = {
  34. color:'#fff',
  35. formatter: '{b} {d}%'
  36. };
  37. var chart = echarts.init(document.getElementById(id));
  38. var option = {
  39. title: {
  40. text: title,
  41. textStyle: titleTextStyle,
  42. },
  43. tooltip: tooltip,
  44. legend: {
  45. left: legendLeft,
  46. top: legendTop,
  47. icon: 'circle',
  48. itemWidth: legendItemWidth,
  49. itemHeight: legendItemHeight,
  50. textStyle: legendTextStyle,
  51. },
  52. series: [
  53. {
  54. name: title,
  55. type: 'pie',
  56. top: seriesTop,
  57. radius: seriesRadius,
  58. avoidLabelOverlap: false,
  59. label: seriesLabel,
  60. data: data
  61. }
  62. ]
  63. }
  64. chart.setOption(option);
  65. if(typeof(callback) == 'function') chart.on('finished', callback);
  66. return chart;
  67. }
  68. /**
  69. * Draw months bar chart.
  70. *
  71. * @param string $id
  72. * @param string $title
  73. * @param array $legends
  74. * @param array $xAxis
  75. * @param array $data
  76. * @access public
  77. * @return object
  78. */
  79. function drawMonthsBarChart(id, title, legends, xAxis, data)
  80. {
  81. var titleTextStyle = {
  82. color:'#fff',
  83. fontSize: 14
  84. };
  85. var tooltip = {
  86. trigger: 'axis',
  87. axisPointer: {
  88. type: 'shadow'
  89. }
  90. };
  91. var legendRight = '20';
  92. var legendTop = '0';
  93. var legendItemWidth = 10;
  94. var legendItemHeight = 10;
  95. var legendTextStyle = {
  96. color:'#fff',
  97. fontSize: 12
  98. };
  99. var labelStyle = {color:'#fff'}
  100. var chart = echarts.init(document.getElementById(id));
  101. var option = {
  102. title: {
  103. text: title,
  104. textStyle: titleTextStyle,
  105. },
  106. tooltip: tooltip,
  107. legend: {
  108. right: legendRight,
  109. top: legendTop,
  110. itemWidth: legendItemWidth,
  111. itemHeight: legendItemHeight,
  112. textStyle: legendTextStyle,
  113. data: legends
  114. },
  115. grid: {
  116. left: '0%',
  117. right: '0%',
  118. bottom: '2%',
  119. containLabel: true
  120. },
  121. yAxis: {
  122. type: 'value',
  123. axisLine: {show: true },
  124. splitLine: {show: false},
  125. axisLabel: labelStyle
  126. },
  127. xAxis: {
  128. type: 'category',
  129. axisLabel: labelStyle,
  130. axisTick: {alignWithLabel: true},
  131. data: xAxis
  132. },
  133. series: data
  134. }
  135. chart.setOption(option);
  136. return chart;
  137. }
  138. /**
  139. * Export annual data to image file
  140. * @param {function} sucessCallback
  141. * @param {function} errorCallback
  142. * @return {void}
  143. */
  144. function exportAnnualImage(sucessCallback, errorCallback)
  145. {
  146. var $main = $('#main');
  147. if($main.hasClass('exporting')) return;
  148. var $loading = $('#loadIndicator');
  149. $loading.addClass('loading');
  150. var $container = $('#container');
  151. $main.addClass('exporting').css('background-color', $container.css('background-color'));
  152. var afterFinish = function(canvas)
  153. {
  154. $main.removeClass('exporting');
  155. $loading.removeClass('loading');
  156. };
  157. html2canvas($main[0], {logging: false}).then(function(canvas)
  158. {
  159. canvas.onerror = function()
  160. {
  161. afterFinish(canvas);
  162. if(errorCallback) errorCallback('Cannot convert image to blob.');
  163. };
  164. /* Watermark. */
  165. const ctx = canvas.getContext('2d');
  166. ctx.font = '12px serif';
  167. ctx.fillStyle = 'rgba(200,200,200, 0.8)';
  168. ctx.fillText(exportByZentao, 1220, 90);
  169. ctx.fillText(exportByZentao, 45, canvas.height - 10);
  170. canvas.toBlob(function(blob)
  171. {
  172. var imageUrl = URL.createObjectURL(blob);
  173. $('#imageDownloadBtn').attr({href: imageUrl})[0].click();
  174. if(sucessCallback) sucessCallback(imageUrl);
  175. afterFinish(canvas);
  176. });
  177. });
  178. }
  179. $(function()
  180. {
  181. $('#exportBtn').on('click', function()
  182. {
  183. exportAnnualImage();
  184. });
  185. $('select#year, select#dept, select#account').change(function()
  186. {
  187. var year = $('select#year').val();
  188. var dept = $('select#dept').val();
  189. var account = $('select#account').val();
  190. if($(this).attr('id') == 'dept') account = '';
  191. location.href = createLink('screen', 'view', 'screenID=3&year=' + year + '&month=0&dept=' + dept + '&account=' + account);
  192. });
  193. $('#actionData > div > ul > li').mouseenter(function(e)
  194. {
  195. var width = $(this).width();
  196. var maxOffset = width - 100;
  197. var offset = e.pageX - $(this).offset().left + 10;
  198. if(offset > maxOffset) offset = maxOffset;
  199. $('#actionData > div > ul > li .dropdown-menu').css('left', offset);
  200. });
  201. $('section').mouseover(function(){$(this).addClass('active')});
  202. $('section').mouseout(function(){$(this).removeClass('active')});
  203. $('[data-toggle="popover"]').popover();
  204. });