echarts.js 7.5 KB

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