ChartLine.vue 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. <!--
  2. * @Author: your name
  3. * @Date: 2021-10-25 16:13:34
  4. * @LastEditTime: 2021-10-25 16:55:38
  5. * @LastEditors: Please set LastEditors
  6. * @Description: 折线图
  7. * @FilePath: \hyyfScreen\src\views\Zoology\charts\ChartLine.vue
  8. -->
  9. <template>
  10. <div :id="'chartLine' + id" class="chart-line">
  11. </div>
  12. </template>
  13. <script>
  14. export default {
  15. props: {
  16. id: {
  17. type: Number
  18. },
  19. data: {
  20. type: Object,
  21. required: true
  22. }
  23. },
  24. data() {
  25. return {
  26. myChart: null
  27. }
  28. },
  29. methods: {
  30. init() {
  31. let options = {
  32. // title: {
  33. // text: '存栏变动',
  34. // x: 10,
  35. // y: 0
  36. // },
  37. tooltip: {
  38. trigger: 'axis',
  39. },
  40. // legend: {
  41. // data: ['头']
  42. // },
  43. // color: ['#3aa0ff', '#4dcb73', '#fad337', '#f2637b', '#975fe4'],
  44. grid: {
  45. top: '10%',
  46. left: '10%',
  47. bottom: '20%',
  48. right: '10%'
  49. },
  50. xAxis: [
  51. {
  52. type: 'category',
  53. // name: this.data.xAxisName,
  54. data: this.data.xAxisData,
  55. axisPointer: {
  56. type: 'shadow'
  57. },
  58. axisLabel: {
  59. textStyle: {
  60. color: '#fff'
  61. }
  62. },
  63. axisLine: {
  64. show: true,
  65. lineStyle: {
  66. color: 'rgb(0, 255, 255)',
  67. }
  68. },
  69. axisTick:{
  70. show: false
  71. },
  72. }
  73. ],
  74. yAxis: //[
  75. {
  76. type: 'value',
  77. name: this.data.yAxisName,
  78. nameTextStyle: {
  79. color: 'red'
  80. },
  81. axisLabel: {
  82. textStyle: {
  83. color: '#fff'
  84. },
  85. formatter: '{value}' + this.data.yAxisName
  86. },
  87. axisLine: {
  88. show: true,
  89. lineStyle: {
  90. color: 'rgb(0, 255, 255)',
  91. }
  92. },
  93. axisTick:{
  94. show:false
  95. },
  96. splitLine:{
  97. show:false
  98. }
  99. },
  100. //],
  101. series: [
  102. {
  103. name: this.data.xAxisName,
  104. type: 'line',
  105. smooth: false,
  106. data: this.data.yAxisData,
  107. itemStyle: {
  108. normal: {
  109. color: '#3aa0ff',
  110. lineStyle: {
  111. color: '#3aa0ff'
  112. }
  113. }
  114. }
  115. }
  116. ]
  117. }
  118. this.myChart.setOption(options);
  119. }
  120. },
  121. mounted() {
  122. this.myChart = this.$echarts.init(document.getElementById('chartLine' + this.id));
  123. this.init();
  124. },
  125. watch: {
  126. data: {
  127. handler(newVal) {
  128. if(newVal) {
  129. this.myChart.clear();
  130. this.init();
  131. }
  132. },
  133. deep: true,
  134. }
  135. }
  136. }
  137. </script>
  138. <style scoped>
  139. .chart-line {
  140. width: 100%;
  141. height: 160px;
  142. }
  143. </style>