restaurantTrendChart.vue 3.8 KB

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