tendency.vue 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. <template>
  2. <div class="line1">
  3. <div id="line1" class="" style="width: 90%;height:450px;"></div>
  4. </div>
  5. </template>
  6. <script>
  7. import echarts from 'echarts/lib/echarts';
  8. // 引入柱状图
  9. import 'echarts/lib/chart/bar';
  10. import 'echarts/lib/chart/line';
  11. import 'echarts/lib/component/title';
  12. import 'echarts/lib/component/legend';
  13. import 'echarts/lib/component/toolbox';
  14. import 'echarts/lib/component/markPoint';
  15. import 'echarts/lib/component/tooltip';
  16. export default {
  17. mounted() {
  18. this.myChart = echarts.init(document.getElementById('line1'));
  19. this.initData();
  20. },
  21. props: ['sevenDate', 'sevenDay'],
  22. methods: {
  23. initData() {
  24. const colors = ['#5793f3', '#675bba', '#d14a61'];
  25. const option = {
  26. color: colors,
  27. title: {
  28. text: '走势图',
  29. subtext: ''
  30. },
  31. tooltip: {
  32. trigger: 'axis'
  33. },
  34. legend: {
  35. data: ['新注册用户', '新增信息', '新增管理员']
  36. },
  37. toolbox: {
  38. show: true,
  39. feature: {
  40. dataZoom: {
  41. yAxisIndex: 'none'
  42. },
  43. dataView: { readOnly: false },
  44. magicType: { type: ['bar', 'line'] },
  45. restore: {}
  46. }
  47. },
  48. xAxis: {
  49. type: 'category',
  50. boundaryGap: false,
  51. data: this.sevenDay
  52. },
  53. yAxis: [
  54. {
  55. type: 'value',
  56. name: '用户',
  57. min: 0,
  58. max: 200,
  59. position: 'left',
  60. axisLine: {
  61. lineStyle: {
  62. color: '#999'
  63. }
  64. },
  65. axisLabel: {
  66. formatter: '{value}'
  67. }
  68. },
  69. {
  70. type: 'value',
  71. name: '信息',
  72. min: 0,
  73. max: 200,
  74. position: 'right',
  75. axisLine: {
  76. lineStyle: {
  77. color: '#999'
  78. }
  79. },
  80. axisLabel: {
  81. formatter: '{value}'
  82. }
  83. }
  84. ],
  85. series: [
  86. {
  87. name: '新注册用户',
  88. type: 'line',
  89. data: this.sevenDate[0],
  90. yAxisIndex: 1,
  91. markPoint: {
  92. data: [{ type: 'max', name: '最大值' }, { type: 'min', name: '最小值' }]
  93. }
  94. },
  95. {
  96. name: '新增信息',
  97. type: 'line',
  98. data: this.sevenDate[1],
  99. yAxisIndex: 1,
  100. markPoint: {
  101. data: [{ type: 'max', name: '最大值' }, { type: 'min', name: '最小值' }]
  102. }
  103. },
  104. {
  105. name: '新增管理员',
  106. type: 'line',
  107. data: this.sevenDate[2],
  108. yAxisIndex: 1,
  109. markPoint: {
  110. data: [{ type: 'max', name: '最大值' }, { type: 'min', name: '最小值' }]
  111. }
  112. }
  113. ]
  114. };
  115. this.myChart.setOption(option);
  116. }
  117. },
  118. watch: {
  119. sevenDate() {
  120. this.initData();
  121. },
  122. sevenDay() {
  123. this.initData();
  124. }
  125. }
  126. };
  127. </script>
  128. <style lang="less">
  129. @import '~@/style/mixin';
  130. .line1 {
  131. display: flex;
  132. justify-content: center;
  133. }
  134. </style>