supermarketTrendChart.vue 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. <script>
  2. import apiDashboard from "@/api/dashboard/apiDashboard";
  3. export default {
  4. data() {
  5. let colors = {
  6. consumptionAmount: ['#399EE6'],
  7. consumptionOrder: ['#3CC2AC', '#7EE6D4']
  8. }
  9. return {
  10. xData: [],
  11. xBgColor: [],
  12. moneyData: [],
  13. orderData: [],
  14. option: {
  15. legend: {
  16. data: [
  17. '商超消费金额',
  18. '商超消费订单',
  19. ]
  20. },
  21. grid: {
  22. left: '0%', //默认10%
  23. right: '0%', //默认10%
  24. bottom: '15%', //默认60
  25. top: '15%',
  26. containLabel: true
  27. //grid区域是否包含坐标轴的刻度标签
  28. },
  29. xAxis: {
  30. data: [],
  31. splitArea: {
  32. show: true,
  33. areaStyle: {
  34. color: ['white']
  35. }
  36. }
  37. },
  38. yAxis: [
  39. {
  40. name: '金额(元)',
  41. type: 'value',
  42. nameTextStyle: {
  43. padding: [10, 0, 10, -12]
  44. },
  45. },
  46. {
  47. name: '订单(单)',
  48. type: 'value',
  49. nameTextStyle: {
  50. padding: [10, 0, 10, 10]
  51. },
  52. },
  53. ],
  54. dataZoom: [
  55. {
  56. type: 'slider',
  57. start: 0,
  58. end: 100,
  59. height: 12,
  60. },
  61. {
  62. type: 'inside',
  63. start: 0,
  64. end: 100,
  65. }
  66. ],
  67. tooltip: {
  68. trigger: 'axis',
  69. axisPointer: {
  70. type: 'shadow'
  71. },
  72. textStyle: {
  73. color: '#fff',
  74. align: 'left',
  75. fontSize: 14
  76. },
  77. axisLine: {//x坐标轴轴线
  78. show: true,
  79. lineStyle: {//x坐标轴轴线样式
  80. color: '#000',//'#ccc' | 'rgb(128, 128, 128)' | 'rgba(128, 128, 128, 0.5)',设置标签颜色
  81. }
  82. },
  83. backgroundColor: 'rgba(0,0,0,0.8)',
  84. },
  85. series: [
  86. {
  87. name: '商超消费金额',
  88. data: [],
  89. type: 'bar',
  90. yAxisIndex:0,
  91. barWidth: 20,
  92. backgroundStyle: {
  93. color: 'rgb(253, 232, 229, 0.5)'
  94. },
  95. itemStyle: {
  96. color: colors.consumptionAmount[0]
  97. }
  98. },
  99. {
  100. name: '商超消费订单',
  101. data: [],
  102. type: 'line',
  103. yAxisIndex:1,
  104. smooth: true,
  105. showSymbol:false,
  106. areaStyle: {
  107. color: new this.$echarts.graphic.LinearGradient(0, 0, 0, 1, [{
  108. offset: 0,
  109. color: colors.consumptionOrder[1], // 0% 处的颜色
  110. },{
  111. offset: 0.8,
  112. color: 'rgb(255,255,255,0.1)'
  113. }], false),
  114. },
  115. lineStyle: {
  116. color: colors.consumptionOrder[0],
  117. width: 1,
  118. },
  119. itemStyle: {
  120. color: colors.consumptionOrder[0],
  121. },
  122. emphasis: {
  123. scale:1.5
  124. },
  125. },
  126. ]
  127. },
  128. }
  129. },
  130. props: {
  131. height: Number,
  132. data: Array,
  133. },
  134. mounted() {
  135. this.$nextTick(()=>{
  136. this.initData()
  137. this.initChart()
  138. })
  139. },
  140. methods: {
  141. initData() {
  142. if (!this.data) {
  143. return;
  144. }
  145. for (let i = 0; i < this.data.length; i++) {
  146. let obj = this.data[i];
  147. this.xData.push(obj.label);
  148. this.moneyData.push(obj.money);
  149. this.orderData.push(obj.order);
  150. if (obj.money>=200) {
  151. this.xBgColor.push('rgb(253, 232, 229, 0.5)')
  152. } else {
  153. this.xBgColor.push('transparent')
  154. }
  155. }
  156. },
  157. initChart() {
  158. let chart = this.$echarts.init(this.$refs.myChart)
  159. this.chart = chart;
  160. chart.setOption(this.option);
  161. this.getData()
  162. },
  163. getData() {
  164. return apiDashboard.getSuperMarketTrendData(this.queryData).then(res=>{
  165. let data = this.$util.dataUtil.covertDataToEcharts(res, ['consumptionAmount','consumptionOrder'])
  166. this.$util.dataUtil.refreshEchartsData(this.chart, this.option, data)
  167. })
  168. }
  169. }
  170. }
  171. </script>
  172. <template>
  173. <div style="width: 100%" :style="{height: height+'px'}" ref="myChart"></div>
  174. </template>
  175. <style lang="less" scoped>
  176. </style>