trend.vue 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  1. <template>
  2. <e-charts :options="options"></e-charts>
  3. </template>
  4. <script>
  5. import ECharts from 'vue-echarts';
  6. import 'echarts/lib/chart/line';
  7. export default {
  8. name: 'echart',
  9. components: {
  10. ECharts
  11. },
  12. props: {
  13. chartData: {
  14. type: Object
  15. }
  16. },
  17. data() {
  18. return {
  19. chart: null,
  20. options: {
  21. // tooltip: {
  22. // trigger: 'axis'
  23. // },
  24. // grid: {
  25. // left: '3%',
  26. // right: '3%',
  27. // top: '30',
  28. // bottom: '0',
  29. // containLabel: true
  30. // },
  31. // xAxis: [
  32. // {
  33. // type: 'category',
  34. // data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'],
  35. // axisLine: {
  36. // lineStyle: {
  37. // color: '#999'
  38. // }
  39. // }
  40. // }
  41. // ],
  42. // yAxis: [
  43. // {
  44. // type: 'value',
  45. // splitNumber: 4,
  46. // splitLine: {
  47. // lineStyle: {
  48. // type: 'dashed',
  49. // color: '#DDD'
  50. // }
  51. // },
  52. // axisLine: {
  53. // show: false,
  54. // lineStyle: {
  55. // color: '#333'
  56. // }
  57. // },
  58. // nameTextStyle: {
  59. // color: '#999'
  60. // },
  61. // splitArea: {
  62. // show: false
  63. // }
  64. // }
  65. // ],
  66. // series: [
  67. // {
  68. // name: '统计',
  69. // type: 'line',
  70. // data: [820, 932, 901, 934, 1290, 1330, 1320],
  71. // lineStyle: {
  72. // normal: {
  73. // width: 8,
  74. // color: {
  75. // type: 'linear',
  76. // colorStops: [
  77. // {
  78. // offset: 0,
  79. // color: '#A9F387'
  80. // },
  81. // {
  82. // offset: 1,
  83. // color: '#48D8BF'
  84. // }
  85. // ],
  86. // globalCoord: false
  87. // },
  88. // shadowColor: 'rgba(72,216,191, 0.3)',
  89. // shadowBlur: 10,
  90. // shadowOffsetY: 20
  91. // }
  92. // },
  93. // itemStyle: {
  94. // normal: {
  95. // color: '#fff',
  96. // borderWidth: 10,
  97. // borderColor: '#A9F387'
  98. // }
  99. // },
  100. // smooth: true
  101. // }
  102. // ]
  103. }
  104. };
  105. },
  106. watch: {
  107. chartData: {
  108. deep: true,
  109. handler: function(val) {
  110. if (!this.chart) {
  111. return false;
  112. }
  113. // let chartData = JSON.parse(JSON.stringify(val));
  114. this.initChart();
  115. // this.setOptions(chartData);
  116. }
  117. }
  118. },
  119. methods: {
  120. initChart() {
  121. // this.chart = echarts.init(this.$el, 'macarons')
  122. this.chart = true;
  123. if (this.$util.isEmpty(this.chartData)) return false;
  124. let chartData = JSON.parse(JSON.stringify(this.chartData));
  125. let nameData = [];
  126. let numData = [];
  127. for (let i in chartData) {
  128. nameData.push(i);
  129. numData.push(chartData[i]);
  130. }
  131. this.setOptions({ nameData: nameData, numData: numData });
  132. },
  133. setOptions(data) {
  134. this.options = {
  135. tooltip: {
  136. trigger: 'axis'
  137. },
  138. grid: {
  139. left: '3%',
  140. right: '3%',
  141. top: '30',
  142. bottom: '0',
  143. containLabel: true
  144. },
  145. xAxis: [
  146. {
  147. type: 'category',
  148. data: data.nameData,
  149. axisLine: {
  150. lineStyle: {
  151. color: '#999'
  152. }
  153. }
  154. }
  155. ],
  156. yAxis: [
  157. {
  158. type: 'value',
  159. splitNumber: 4,
  160. splitLine: {
  161. lineStyle: {
  162. type: 'dashed',
  163. color: '#DDD'
  164. }
  165. },
  166. axisLine: {
  167. show: false,
  168. lineStyle: {
  169. color: '#333'
  170. }
  171. },
  172. nameTextStyle: {
  173. color: '#999'
  174. },
  175. splitArea: {
  176. show: false
  177. }
  178. }
  179. ],
  180. series: [
  181. {
  182. name: '统计',
  183. type: 'line',
  184. data: data.numData,
  185. lineStyle: {
  186. normal: {
  187. width: 8,
  188. color: {
  189. type: 'linear',
  190. colorStops: [
  191. {
  192. offset: 0,
  193. color: '#A9F387'
  194. },
  195. {
  196. offset: 1,
  197. color: '#48D8BF'
  198. }
  199. ],
  200. globalCoord: false
  201. },
  202. shadowColor: 'rgba(72,216,191, 0.3)',
  203. shadowBlur: 10,
  204. shadowOffsetY: 20
  205. }
  206. },
  207. itemStyle: {
  208. normal: {
  209. color: '#fff',
  210. borderWidth: 10,
  211. borderColor: '#A9F387'
  212. }
  213. },
  214. smooth: true
  215. }
  216. ]
  217. };
  218. }
  219. }
  220. };
  221. </script>
  222. <style lang="stylus" scoped>
  223. .echarts {
  224. width: 100%;
  225. }
  226. </style>