weatherForecast.vue 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413
  1. <!-- 温度折线图 -->
  2. <template>
  3. <div class="weatherBox" :style="{height:barHeight}">
  4. <boxTop :title="title">
  5. <!-- <div class="select_btn">-->
  6. <!-- <el-select size="small" :popper-append-to-body="false" style="width: 120px" v-model="value" placeholder="请选择">-->
  7. <!-- <el-option-->
  8. <!-- v-for="(item, index) in selectList"-->
  9. <!-- :key="index"-->
  10. <!-- :label="item.value"-->
  11. <!-- :value="item.value">-->
  12. <!-- </el-option>-->
  13. <!-- </el-select>-->
  14. <!-- </div>-->
  15. </boxTop>
  16. <div class="chartsdom" :id="id"></div>
  17. <div class="title"><span class="label">{{title}}</span><span class="value">{{ total }}</span></div>
  18. </div>
  19. </template>
  20. <script>
  21. import {Select, Option} from 'element-ui'
  22. import Vue from 'vue'
  23. Vue.use(Select)
  24. Vue.use(Option)
  25. import boxTop from '@/components/boxTop/index.vue'
  26. export default {
  27. data() {
  28. return {
  29. value: null,
  30. selectList: [
  31. {
  32. value: "2025-01",
  33. }, {
  34. value: "2025-02",
  35. }, {
  36. value: "2025-03",
  37. }, {
  38. value: "2025-04",
  39. },
  40. ],
  41. option: null,
  42. information: {},
  43. }
  44. },
  45. props: {
  46. id: {
  47. type: String,
  48. default: ``,
  49. },
  50. area: {
  51. type: Array,
  52. },
  53. dataArray: {
  54. type: Object,
  55. default: null
  56. },
  57. barHeight: {
  58. type: String,
  59. default: `200px`,
  60. },
  61. showLegnd: {
  62. type: Boolean,
  63. default: true
  64. },
  65. title: {
  66. type: String,
  67. default: ``,
  68. },
  69. },
  70. components: {
  71. boxTop,
  72. },
  73. mounted() {
  74. this.getEchart()
  75. },
  76. watch: {
  77. dataArray() {
  78. this.getEchart()
  79. },
  80. },
  81. methods: {
  82. getEchart() {
  83. let myChart = echarts.init(document.getElementById(this.id))
  84. function addAlpha(rgb, alpha) {
  85. // 匹配rgb颜色格式
  86. const rgbPattern = /^rgb\((\d{1,3}),\s*(\d{1,3}),\s*(\d{1,3})\)$/;
  87. const match = rgb.match(rgbPattern);
  88. if (!match) {
  89. throw new Error('Invalid RGB format');
  90. }
  91. // 提取红、绿、蓝值
  92. const r = match[1];
  93. const g = match[2];
  94. const b = match[3];
  95. // 返回rgba颜色格式
  96. return `rgba(${r},${g},${b},${alpha})`;
  97. }
  98. let colors = [
  99. 'rgb(150,208,135)',
  100. 'rgb(63,162,246)',
  101. 'rgb(244,162,97)',
  102. 'rgb(145,122,176)'
  103. ]
  104. let data = {
  105. data: [
  106. [92, 0, 8, 143, 89, 67, 0, 0, 0, 0, 197, 0],
  107. [12, 0, 8, 14, 23, 44, 0, 0, 0, 0, 19, 0],
  108. ],
  109. unit: "亩",
  110. xAxis: ['1月', '2月', '3月', '4月', '5月', '6月', '7月', '8月', '9月', '10月', '11月', '12月'],
  111. legend: ["今年", "去年"],
  112. };
  113. if (this.dataArray) {
  114. data.data = []
  115. data.legend = []
  116. if (this.dataArray.thisYear) {
  117. data.data.push(this.dataArray.thisYear || [])
  118. data.legend.push("今年")
  119. }
  120. if (this.dataArray.LastYear) {
  121. data.data.push(this.dataArray.LastYear || [])
  122. data.legend.push("去年")
  123. }
  124. }
  125. if (this.area) {
  126. data.xAxis = []
  127. data.xAxis = this.area
  128. }
  129. let series = data.data.map((item, index) => {
  130. return {
  131. name: data.legend[index],
  132. type: 'line',
  133. smooth: false, //是否平滑
  134. showAllSymbol: true,
  135. symbol: 'circle',
  136. symbolSize: 5,
  137. lineStyle: {
  138. color: colors[index],
  139. },
  140. label: {
  141. show: false,
  142. position: 'top',
  143. textStyle: {
  144. color: colors[index],
  145. }
  146. },
  147. itemStyle: {
  148. color: colors[index],
  149. borderColor: "#fff",
  150. borderWidth: 2,
  151. shadowColor: 'rgba(0, 0, 0, .1)',
  152. shadowBlur: 0,
  153. shadowOffsetY: 2,
  154. shadowOffsetX: 2,
  155. },
  156. tooltip: {
  157. show: true
  158. },
  159. areaStyle: {
  160. normal: {
  161. color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
  162. offset: 0,
  163. color: addAlpha(colors[index], 0.2)
  164. },
  165. {
  166. offset: 1,
  167. color: addAlpha(colors[index], 0)
  168. }
  169. ], false),
  170. shadowColor: 'rgba(0,179,244, 0.5)',
  171. shadowBlur: 20
  172. }
  173. },
  174. data: data.data[index]
  175. }
  176. })
  177. this.option = {
  178. tooltip: {
  179. show: true,
  180. trigger: 'axis',
  181. axisPointer: {
  182. label: {
  183. show: true,
  184. },
  185. },
  186. },
  187. grid: {
  188. top: '10%',
  189. left: '5%',
  190. right: '5%',
  191. bottom: '15%',
  192. containLabel: true
  193. },
  194. xAxis: [{
  195. type: 'category',
  196. boundaryGap: true,
  197. axisLine: {
  198. show: true
  199. },
  200. splitArea: {
  201. // show: true,
  202. color: '#f00',
  203. lineStyle: {
  204. color: '#f00'
  205. },
  206. },
  207. axisLabel: {},
  208. splitLine: {
  209. show: false
  210. },
  211. data: data.xAxis
  212. }],
  213. yAxis: [{
  214. type: 'value',
  215. splitLine: {
  216. show: true,
  217. lineStyle: {
  218. type: 'dashed',
  219. color: 'rgba(255,255,255,0.1)'
  220. }
  221. },
  222. axisLine: {
  223. show: true,
  224. },
  225. axisLabel: {
  226. show: true,
  227. margin: 20,
  228. textStyle: {},
  229. },
  230. axisTick: {
  231. show: true,
  232. },
  233. }],
  234. legend: {
  235. show: this.showLegnd,
  236. textStyle: {
  237. color: '#ffffff'//字体颜色
  238. }
  239. },
  240. series: series
  241. };
  242. myChart.setOption(this.option, true)
  243. },
  244. },
  245. beforeDestroy() {
  246. },
  247. }
  248. </script>
  249. <style lang="less" scoped>
  250. .weatherBox {
  251. width: 460px;
  252. height: 216px;
  253. background: linear-gradient(rgba(0, 32, 77, 0.8) 0%, rgba(0, 32, 77, 0.5) 100%);
  254. box-shadow: inset 0px 0px 20px 0px rgba(27, 146, 255, 0.3);
  255. .chartsdom {
  256. width: 100%;
  257. height: 90%;
  258. }
  259. }
  260. </style>
  261. <style lang="less">
  262. .el-select {
  263. width: 115px;
  264. }
  265. .input-with-select .el-input-group__prepend {
  266. background: rgba(10, 30, 55, 0.7);
  267. box-shadow: 0px 4px 4px rgba(49, 49, 49, 0.5);
  268. }
  269. .el-input-group {
  270. line-height: normal;
  271. display: inline-table;
  272. width: 100%;
  273. border-collapse: separate;
  274. border-spacing: 0;
  275. // height: 46px;
  276. .el-input-group__append,
  277. .el-input-group__prepend {
  278. background-color: rgba(10, 30, 55, 0.7);
  279. }
  280. }
  281. .el-input__inner {
  282. background: rgba(10, 30, 55, 0.7);
  283. }
  284. // 修改下拉菜单背景颜色
  285. .el-scrollbar {
  286. background: #1d2f46;
  287. border-radius: 6px;
  288. }
  289. //下拉背景
  290. .el-card.is-hover-shadow:focus,
  291. .el-card.is-hover-shadow:hover,
  292. .el-color-picker__panel,
  293. .el-menu--popup,
  294. .el-message-box,
  295. .el-picker-panel .el-time-panel,
  296. .el-picker__popper.el-popper[role='tooltip'],
  297. .el-popover.el-popper,
  298. .el-select-v2__popper.el-popper[role='tooltip'],
  299. .el-select__popper.el-popper[role='tooltip'],
  300. .el-table-filter {
  301. opacity: 0.8;
  302. border-radius: 6px;
  303. }
  304. .el-popper__arrow {
  305. display: none;
  306. }
  307. .el-select-dropdown__item {
  308. color: #fff;
  309. }
  310. //修改输入框背景颜色
  311. .el-input-group > .el-input__inner {
  312. box-shadow: 0px 4px 4px rgba(49, 49, 49, 0.5);
  313. background: rgba(10, 30, 55, 0.7);
  314. // width: 260px;
  315. // height: 46px;
  316. border-left: 0;
  317. border-right: 0;
  318. font-size: 14px;
  319. }
  320. .el-input-group--prepend .el-input__inner,
  321. .el-input-group__append {
  322. background: rgba(10, 30, 55, 0.7);
  323. border-top-left-radius: 0;
  324. border-bottom-left-radius: 0;
  325. }
  326. .el-input-group__append {
  327. border-left: 0;
  328. }
  329. .el-select-dropdown__wrap,
  330. .el-scrollbar__wrap,
  331. .el-scrollbar__wrap--hidden-default {
  332. background: rgba(10, 30, 55, 0.7);
  333. }
  334. //修改输入框字体
  335. .el-input-group--append .el-input__inner,
  336. .el-input-group__prepend {
  337. font-size: 14px;
  338. color: #ffff;
  339. }
  340. // 修改搜索按钮icon
  341. .el-icon-my-export:before {
  342. content: '替';
  343. font-size: 25px;
  344. visibility: hidden;
  345. }
  346. //修改下拉框的字体
  347. .el-select-dropdown__list {
  348. padding: 5px;
  349. text-align: center;
  350. //修改单个的选项的样式
  351. .el-select-dropdown__item {
  352. padding: 0 0.2rem 0 0.2rem;
  353. color: #ffff;
  354. font-size: 16px;
  355. }
  356. .el-select-dropdown__item.selected {
  357. color: #ffff;
  358. }
  359. //item选项的hover样式
  360. .el-select-dropdown__item.hover,
  361. .el-select-dropdown__item:hover {
  362. background: rgba(10, 30, 55, 0.7);
  363. }
  364. }
  365. // 修改下拉箭头左侧字体大小颜色
  366. .el-input-group__append button.el-button,
  367. .el-input-group__append div.el-select .el-input__inner,
  368. .el-input-group__append div.el-select:hover .el-input__inner,
  369. .el-input-group__prepend button.el-button,
  370. .el-input-group__prepend div.el-select .el-input__inner,
  371. .el-input-group__prepend div.el-select:hover .el-input__inner {
  372. color: #ffff !important;
  373. font-size: 16px;
  374. }
  375. // 修改鼠标选中输入框时输入框的颜色
  376. input.el-input__inner:focus {
  377. border-color: #fff;
  378. }
  379. </style>