weatherForecast.vue 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  1. <!-- 温度折线图 -->
  2. <template>
  3. <div class="weatherBox" :style="{height:barHeight}">
  4. <boxTop :title="title">
  5. <el-select size="small" :popper-append-to-body="false" style="width: 80px" v-model="value" placeholder="请选择">
  6. <el-option
  7. key="2025"
  8. label="2025"
  9. value="2025">
  10. </el-option>
  11. </el-select>
  12. </boxTop>
  13. <div class="chartsdom" :id="id"></div>
  14. </div>
  15. </template>
  16. <script>
  17. import {Select, Option} from 'element-ui'
  18. import Vue from 'vue'
  19. Vue.use(Select)
  20. Vue.use(Option)
  21. import boxTop from '@/components/boxTop/index.vue'
  22. export default {
  23. data() {
  24. return {
  25. value: '2025',
  26. option: null,
  27. information: {},
  28. }
  29. },
  30. props: {
  31. id: {
  32. type: String,
  33. default: ``,
  34. },
  35. area: {
  36. type: Array,
  37. },
  38. dataArray: {
  39. type: Object,
  40. },
  41. barHeight: {
  42. type: String,
  43. default: `200px`,
  44. },
  45. title: {
  46. type: String,
  47. default: ``,
  48. },
  49. unit: {
  50. type: String,
  51. },
  52. },
  53. components: {
  54. boxTop,
  55. },
  56. mounted() {
  57. this.getEchart()
  58. },
  59. watch: {
  60. dataArray() {
  61. this.getEchart()
  62. },
  63. },
  64. methods: {
  65. getEchart() {
  66. let myChart = echarts.init(document.getElementById(this.id))
  67. function addAlpha(rgb, alpha) {
  68. // 匹配rgb颜色格式
  69. const rgbPattern = /^rgb\((\d{1,3}),\s*(\d{1,3}),\s*(\d{1,3})\)$/;
  70. const match = rgb.match(rgbPattern);
  71. if (!match) {
  72. throw new Error('Invalid RGB format');
  73. }
  74. // 提取红、绿、蓝值
  75. const r = match[1];
  76. const g = match[2];
  77. const b = match[3];
  78. // 返回rgba颜色格式
  79. return `rgba(${r},${g},${b},${alpha})`;
  80. }
  81. let colors = [
  82. 'rgb(150,208,135)',
  83. 'rgb(63,162,246)',
  84. 'rgb(244,162,97)',
  85. 'rgb(145,122,176)'
  86. ]
  87. let data = {
  88. data: [
  89. [92, 0, 8, 143, 89, 67, 0, 0, 0, 0, 197, 0],
  90. [12, 0, 8, 14, 23, 44, 0, 0, 0, 0, 19, 0],
  91. ],
  92. unit: "亩",
  93. xAxis: ['1月', '2月', '3月', '4月', '5月', '6月', '7月', '8月', '9月', '10月', '11月', '12月'],
  94. legend: ["今年当月", "去年当月"],
  95. };
  96. let series = data.data.map((item, index) => {
  97. return {
  98. name: data.legend[index],
  99. type: 'line',
  100. smooth: false, //是否平滑
  101. showAllSymbol: true,
  102. symbol: 'circle',
  103. symbolSize: 5,
  104. lineStyle: {
  105. color: colors[index],
  106. },
  107. label: {
  108. show: false,
  109. position: 'top',
  110. textStyle: {
  111. color: colors[index],
  112. }
  113. },
  114. itemStyle: {
  115. color: colors[index],
  116. borderColor: "#fff",
  117. borderWidth: 2,
  118. shadowColor: 'rgba(0, 0, 0, .1)',
  119. shadowBlur: 0,
  120. shadowOffsetY: 2,
  121. shadowOffsetX: 2,
  122. },
  123. tooltip: {
  124. show: true
  125. },
  126. areaStyle: {
  127. normal: {
  128. color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
  129. offset: 0,
  130. color: addAlpha(colors[index], 0.2)
  131. },
  132. {
  133. offset: 1,
  134. color: addAlpha(colors[index], 0)
  135. }
  136. ], false),
  137. shadowColor: 'rgba(0,179,244, 0.5)',
  138. shadowBlur: 20
  139. }
  140. },
  141. data: data.data[index]
  142. }
  143. })
  144. this.option = {
  145. tooltip: {
  146. show: true,
  147. trigger: 'axis',
  148. axisPointer: {
  149. label: {
  150. show: true,
  151. },
  152. },
  153. },
  154. grid: {
  155. top: '15%',
  156. left: '5%',
  157. right: '5%',
  158. bottom: '15%',
  159. containLabel: true
  160. },
  161. xAxis: [{
  162. type: 'category',
  163. boundaryGap: true,
  164. axisLine: {
  165. show: true
  166. },
  167. splitArea: {
  168. // show: true,
  169. color: '#f00',
  170. lineStyle: {
  171. color: '#f00'
  172. },
  173. },
  174. axisLabel: {},
  175. splitLine: {
  176. show: false
  177. },
  178. data: data.xAxis
  179. }],
  180. yAxis: [{
  181. type: 'value',
  182. splitLine: {
  183. show: true,
  184. lineStyle: {
  185. type: 'dashed',
  186. color: 'rgba(255,255,255,0.1)'
  187. }
  188. },
  189. axisLine: {
  190. show: true,
  191. },
  192. axisLabel: {
  193. show: true,
  194. margin: 20,
  195. textStyle: {},
  196. },
  197. axisTick: {
  198. show: true,
  199. },
  200. }],
  201. legend: {
  202. show: true,
  203. textStyle: {
  204. color: '#ffffff'//字体颜色
  205. }
  206. },
  207. series: series
  208. };
  209. myChart.setOption(this.option, true)
  210. },
  211. },
  212. beforeDestroy() {
  213. },
  214. }
  215. </script>
  216. <style lang="less" scoped>
  217. .weatherBox {
  218. width: 460px;
  219. height: 216px;
  220. background: linear-gradient(rgba(0, 32, 77, 0.8) 0%, rgba(0, 32, 77, 0.5) 100%);
  221. box-shadow: inset 0px 0px 20px 0px rgba(27, 146, 255, 0.3);
  222. .chartsdom {
  223. width: 100%;
  224. height: 90%;
  225. }
  226. }
  227. </style>