water.vue 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. <template>
  2. <div class="realtime-container">
  3. <div class="title">当日时间水位趋势图</div>
  4. <div ref="chart" class="chart" :style="{height: '140px', width: '100%'}" />
  5. </div>
  6. </template>
  7. <script>
  8. import * as echarts from "echarts";
  9. require('echarts/theme/macarons') // echarts theme
  10. import resize from '@/utils/resize'
  11. export default {
  12. mixins: [resize],
  13. mounted() {
  14. this.$nextTick(() => {
  15. this.chart = echarts.init(this.$refs.chart, 'macarons');
  16. })
  17. },
  18. beforeDestroy() {
  19. if (this.chart) {
  20. this.chart.dispose()
  21. this.chart = null
  22. }
  23. },
  24. methods: {
  25. setOptions(chartData) {
  26. if (!this.chart) {
  27. return;
  28. }
  29. chartData.reverse()
  30. const xAxisData = chartData.map(({ time }) => time);
  31. const seriesData = chartData.map(({ avgWaterlevel }) => avgWaterlevel);
  32. const options = {
  33. xAxis: {
  34. name: '时间',
  35. data: xAxisData,
  36. type: 'category',
  37. axisLabel: {
  38. color: '#54606C'
  39. },
  40. axisLine: {
  41. lineStyle: {
  42. color: '#E4E4E4'
  43. }
  44. }
  45. },
  46. yAxis: [
  47. {
  48. name: '水位(m)',
  49. axisLine: {
  50. show: false
  51. },
  52. axisLabel: {
  53. color: '#54606C'
  54. },
  55. nameTextStyle: {
  56. color: '#8D99A4'
  57. },
  58. min: 'dataMin',
  59. max: 'dataMax',
  60. },
  61. ],
  62. grid: {
  63. left: 20,
  64. right: 0,
  65. bottom: 0,
  66. top: 30,
  67. containLabel: true
  68. },
  69. tooltip: {
  70. trigger: 'axis',
  71. axisPointer: {
  72. type: 'line'
  73. },
  74. formatter: function(prams) {
  75. return `时间:${prams[0].name}<br/>水位:${prams[0].data}m`;
  76. },
  77. padding: [5, 10]
  78. },
  79. series: [{
  80. name: '水位',
  81. type: 'line',
  82. smooth: false,
  83. data: seriesData,
  84. areaStyle: {
  85. normal: {
  86. color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
  87. {
  88. offset: 0,
  89. color: "rgba(127, 200, 229, 0.4)"
  90. },
  91. {
  92. offset: 1,
  93. color: "rgba(119, 211, 247, 0.1)"
  94. }
  95. ], false),
  96. shadowColor: "rgba(119, 211, 247, 0.1)",
  97. shadowBlur: 20
  98. }
  99. },
  100. }]
  101. };
  102. this.chart.setOption(options);
  103. }
  104. }
  105. }
  106. </script>
  107. <style scoped>
  108. .realtime-container {
  109. background: #fff;
  110. height: 190px;
  111. border-radius: 4px;
  112. padding: 10px 20px;
  113. }
  114. .title {
  115. font-size: 18px;
  116. line-height: 26px;
  117. font-weight: 600;
  118. color: #1D2738;
  119. }
  120. </style>