dashboard.js 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. define(['jquery', 'bootstrap', 'backend', 'table', 'form', 'template', 'echarts', 'echarts-theme'], function ($, undefined, Backend, Table, Form, Template, Echarts) {
  2. var Controller = {
  3. index: function () {
  4. //console.log(Echarts.version);
  5. //这句话在多选项卡统计表时必须存在,否则会导致影响的图表宽度不正确
  6. $(document).on("click", ".charts-custom a[data-toggle=\"tab\"]", function () {
  7. var that = this;
  8. setTimeout(function () {
  9. var id = $(that).attr("href");
  10. var chart = Echarts.getInstanceByDom($(id)[0]);
  11. chart.resize();
  12. }, 0);
  13. });
  14. // 基于准备好的dom,初始化echarts实例
  15. var lineChart = Echarts.init(document.getElementById('line-chart'), 'walden');
  16. // 指定图表的配置项和数据
  17. var option = {
  18. xAxis: {
  19. type: 'category',
  20. data: ['周一', '周二', '周三', '周四', '周五', '周六', '周日']
  21. },
  22. yAxis: {
  23. type: 'value'
  24. },
  25. series: [{
  26. data: [49, 92, 61, 134, 90, 130, 120],
  27. type: 'line'
  28. }]
  29. };
  30. // 使用刚指定的配置项和数据显示图表。
  31. lineChart.setOption(option);
  32. // 基于准备好的dom,初始化echarts实例
  33. var areaChart = Echarts.init(document.getElementById('area-chart'), 'walden');
  34. // 指定图表的配置项和数据
  35. var option = {
  36. xAxis: {
  37. type: 'category',
  38. boundaryGap: false,
  39. data: ['周一', '周二', '周三', '周四', '周五', '周六', '周日']
  40. },
  41. yAxis: {
  42. type: 'value'
  43. },
  44. series: [{
  45. data: [820, 932, 901, 934, 1290, 1330, 1320],
  46. type: 'line',
  47. areaStyle: {}
  48. }]
  49. };
  50. // 使用刚指定的配置项和数据显示图表。
  51. areaChart.setOption(option);
  52. var pieChart = Echarts.init(document.getElementById('pie-chart'), 'walden');
  53. var option = {
  54. tooltip: {
  55. trigger: 'item',
  56. formatter: '{a} <br/>{b}: {c} ({d}%)'
  57. },
  58. legend: {
  59. orient: 'vertical',
  60. left: 10,
  61. data: ['直接访问', '邮件营销', '联盟广告', '视频广告', '搜索引擎']
  62. },
  63. series: [
  64. {
  65. name: '访问来源',
  66. type: 'pie',
  67. radius: ['50%', '70%'],
  68. avoidLabelOverlap: false,
  69. label: {
  70. normal: {
  71. show: false,
  72. position: 'center'
  73. },
  74. emphasis: {
  75. show: true,
  76. textStyle: {
  77. fontSize: '30',
  78. fontWeight: 'bold'
  79. }
  80. }
  81. },
  82. labelLine: {
  83. normal: {
  84. show: false
  85. }
  86. },
  87. data: [
  88. {value: 335, name: '直接访问'},
  89. {value: 310, name: '邮件营销'},
  90. {value: 234, name: '联盟广告'},
  91. {value: 135, name: '视频广告'},
  92. {value: 1548, name: '搜索引擎'}
  93. ]
  94. }
  95. ]
  96. };
  97. // 使用刚指定的配置项和数据显示图表。
  98. pieChart.setOption(option);
  99. var barChart = Echarts.init(document.getElementById('bar-chart'), 'walden');
  100. option = {
  101. legend: {},
  102. tooltip: {},
  103. dataset: {
  104. source: [
  105. ['产品销售', '2015', '2016', '2017'],
  106. ['风扇', 43.3, 85.8, 93.7],
  107. ['电视机', 83.1, 73.4, 55.1],
  108. ['空调', 86.4, 65.2, 82.5],
  109. ['冰箱', 72.4, 53.9, 39.1]
  110. ]
  111. },
  112. xAxis: {type: 'category'},
  113. yAxis: {},
  114. // Declare several bar series, each will be mapped
  115. // to a column of dataset.source by default.
  116. series: [
  117. {type: 'bar'},
  118. {type: 'bar'},
  119. {type: 'bar'}
  120. ]
  121. };
  122. // 使用刚指定的配置项和数据显示图表。
  123. barChart.setOption(option);
  124. var barChart = Echarts.init(document.getElementById('simplebar-chart'));
  125. option = {
  126. xAxis: {
  127. type: 'category',
  128. axisLine: {
  129. lineStyle: {
  130. color: "#fff"
  131. }
  132. },
  133. data: ['周一', '周二', '周三', '周四', '周五', '周六', '周日']
  134. },
  135. yAxis: {
  136. type: 'value',
  137. axisLine: {
  138. lineStyle: {
  139. color: "#fff"
  140. }
  141. }
  142. },
  143. series: [{
  144. data: [120, 200, 150, 80, 70, 110, 130],
  145. type: 'bar',
  146. itemStyle: {
  147. color: "#fff",
  148. opacity: 0.6
  149. }
  150. }]
  151. };
  152. // 使用刚指定的配置项和数据显示图表。
  153. barChart.setOption(option);
  154. var barChart = Echarts.init(document.getElementById('smoothline-chart'));
  155. option = {
  156. textStyle: {
  157. color: "#fff"
  158. },
  159. color: ['#fff'],
  160. xAxis: {
  161. type: 'category',
  162. boundaryGap: false,
  163. data: ['周一', '周二', '周三', '周四', '周五', '周六', '周日'],
  164. axisLine: {
  165. lineStyle: {
  166. color: "#fff"
  167. }
  168. }
  169. },
  170. yAxis: {
  171. type: 'value',
  172. splitLine: {
  173. show: false
  174. },
  175. axisLine: {
  176. lineStyle: {
  177. color: "#fff"
  178. }
  179. }
  180. },
  181. series: [{
  182. data: [820, 932, 901, 934, 1290, 1330, 1320],
  183. type: 'line',
  184. smooth: true,
  185. areaStyle: {
  186. opacity: 0.4
  187. }
  188. }]
  189. };
  190. // 使用刚指定的配置项和数据显示图表。
  191. barChart.setOption(option);
  192. }
  193. };
  194. return Controller;
  195. });