statusChart.vue 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  1. <template>
  2. <section>
  3. <div class="control">
  4. <div class="pile-line" :class="[pileOrLine==='pile'?'active':'']" @click="changePileOrLine('pile')">堆叠面积图</div>
  5. <div class="pile-line" :class="[pileOrLine==='line'?'active':'']" @click="changePileOrLine('line')">折线图</div>
  6. </div>
  7. <div class="chart-contain">
  8. <normal-echart v-if="echartsOption" :chart-id="id" :option="echartsOption" />
  9. </div>
  10. </section>
  11. </template>
  12. <script>
  13. import normalEchart from '@/components/chart/normalEchart'
  14. export default {
  15. components: { normalEchart },
  16. props: {
  17. id: {
  18. type: String,
  19. default: 'status-chart',
  20. required: false
  21. },
  22. chartData: {
  23. type: Object,
  24. default: () => null,
  25. required: false
  26. }
  27. },
  28. data() {
  29. return {
  30. echartsOption: null,
  31. pileOrLine: 'pile' // 图的类型,pile:堆叠面积图,line:折线图
  32. }
  33. },
  34. watch: {
  35. chartData: {
  36. handler(newV) {
  37. this.changePileOrLine(this.pileOrLine)
  38. },
  39. deep: true,
  40. immediate: true
  41. }
  42. },
  43. mounted() {
  44. this.changePileOrLine(this.pileOrLine)
  45. },
  46. methods: {
  47. changePileOrLine(type) { // 图类型切换
  48. this.pileOrLine = type
  49. if (type === 'pile') {
  50. this.setPile()
  51. } else {
  52. this.setLine()
  53. }
  54. },
  55. setPile() {
  56. this.echartsOption = {
  57. tooltip: {
  58. trigger: 'axis',
  59. axisPointer: {
  60. type: 'cross',
  61. label: {
  62. backgroundColor: '#6a7985'
  63. }
  64. }
  65. },
  66. legend: {
  67. data: ['邮件营销', '联盟广告', '视频广告', '直接访问', '搜索引擎'],
  68. left: '0%'
  69. },
  70. grid: { left: '0%', right: '0%', bottom: '0%', top: '10%', containLabel: true },
  71. xAxis: [
  72. {
  73. type: 'category',
  74. boundaryGap: false,
  75. data: ['周一', '周二', '周三', '周四', '周五', '周六', '周日']
  76. }
  77. ],
  78. yAxis: [{ type: 'value' }],
  79. series: [
  80. {
  81. name: '邮件营销',
  82. type: 'line',
  83. smooth: 0.5,
  84. stack: '总量',
  85. areaStyle: {},
  86. data: [120, 132, 101, 134, 90, 230, 210]
  87. },
  88. {
  89. name: '联盟广告',
  90. type: 'line',
  91. smooth: 0.5,
  92. stack: '总量',
  93. areaStyle: {},
  94. data: [220, 182, 191, 234, 290, 330, 310]
  95. },
  96. {
  97. name: '视频广告',
  98. type: 'line',
  99. smooth: 0.5,
  100. stack: '总量',
  101. areaStyle: {},
  102. data: [150, 232, 201, 154, 190, 330, 410]
  103. },
  104. {
  105. name: '直接访问',
  106. type: 'line',
  107. smooth: 0.5,
  108. stack: '总量',
  109. areaStyle: {},
  110. data: [320, 332, 301, 334, 390, 330, 320]
  111. },
  112. {
  113. name: '搜索引擎',
  114. type: 'line',
  115. smooth: 0.5,
  116. stack: '总量',
  117. label: { normal: { show: true, position: 'top' }},
  118. areaStyle: {},
  119. data: [820, 932, 901, 934, 1290, 1330, 1320]
  120. }
  121. ]
  122. }
  123. },
  124. setLine() {
  125. this.echartsOption = {
  126. tooltip: {
  127. trigger: 'axis',
  128. axisPointer: {
  129. type: 'cross',
  130. label: {
  131. backgroundColor: '#6a7985'
  132. }
  133. }
  134. },
  135. legend: {
  136. data: ['邮件营销', '联盟广告', '视频广告', '直接访问', '搜索引擎'],
  137. left: '0%'
  138. },
  139. grid: { left: '0%', right: '0%', bottom: '0%', top: '10%', containLabel: true },
  140. xAxis: [
  141. {
  142. type: 'category',
  143. boundaryGap: false,
  144. data: ['周一', '周二', '周三', '周四', '周五', '周六', '周日']
  145. }
  146. ],
  147. yAxis: [{ type: 'value' }],
  148. series: [
  149. {
  150. name: '邮件营销',
  151. type: 'line',
  152. stack: '总量',
  153. data: [120, 132, 101, 134, 90, 230, 210]
  154. },
  155. {
  156. name: '联盟广告',
  157. type: 'line',
  158. stack: '总量',
  159. data: [220, 182, 191, 234, 290, 330, 310]
  160. },
  161. {
  162. name: '视频广告',
  163. type: 'line',
  164. stack: '总量',
  165. data: [150, 232, 201, 154, 190, 330, 410]
  166. },
  167. {
  168. name: '直接访问',
  169. type: 'line',
  170. stack: '总量',
  171. data: [320, 332, 301, 334, 390, 330, 320]
  172. },
  173. {
  174. name: '搜索引擎',
  175. type: 'line',
  176. stack: '总量',
  177. label: { normal: { show: true, position: 'top' }},
  178. data: [820, 932, 901, 934, 1290, 1330, 1320]
  179. }
  180. ]
  181. }
  182. }
  183. }
  184. }
  185. </script>
  186. <style lang="scss" scoped>
  187. .control {
  188. display: flex;
  189. justify-content: flex-end;
  190. width: 84%;
  191. margin: 20px auto;
  192. .pile-line{
  193. font-size: 14px;
  194. width: 100px;
  195. display: inline-block;
  196. padding: 6px 10px;
  197. margin-left: 20px;
  198. color: #50A6FF;
  199. border: 1px solid #50A6FF;
  200. border-radius: 4px;
  201. text-align: center;
  202. cursor: pointer;
  203. }
  204. .active {
  205. color: #ffffff;
  206. background: #50A6FF;
  207. }
  208. }
  209. .chart-contain {
  210. position: relative;
  211. height: 400px;
  212. width: 84%;
  213. margin: auto;
  214. margin-top: 20px;
  215. }
  216. </style>