ChartLine.vue 3.0 KB

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