bottomRightChart.vue 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321
  1. <template>
  2. <div>
  3. <div id="bottomRightChart" style="width:100%;height:3.5rem;top: -20px"></div>
  4. </div>
  5. </template>
  6. <script>
  7. import echartMixins from "@/utils/resizeMixins";
  8. export default {
  9. props:['weekData'],
  10. data() {
  11. return {
  12. chart: null
  13. };
  14. },
  15. mounted() {
  16. this.draw();
  17. this.charTimg();
  18. },
  19. mixins: [echartMixins],
  20. methods: {
  21. charTimg() {
  22. setInterval(() => {
  23. this.draw();
  24. }, 6000);
  25. },
  26. draw() {
  27. // 基于准备好的dom,初始化echarts实例
  28. this.chart = this.echarts.init(document.getElementById("bottomRightChart"));
  29. // ----------------------------------------------------------------
  30. // 数据
  31. let dateBase = new Date();
  32. let year = dateBase.getFullYear();
  33. let dottedBase = +dateBase + 1000 * 3600 * 24;
  34. let weekCategory = [];
  35. let maxData = 12000;
  36. let weekMaxData = [];
  37. let weekLineData = [];
  38. // 周数据
  39. for (let i = 0; i < 7; i++) {
  40. // 日期
  41. var date = new Date((dottedBase -= 1000 * 3600 * 24));
  42. weekCategory.unshift([date.getMonth() + 1, date.getDate()].join("/"));
  43. // 折线图数据
  44. weekMaxData.push(maxData);
  45. var distance = Math.round(Math.random() * 11000 + 500);
  46. weekLineData.push(distance);
  47. };
  48. const dateNum = [];
  49. for (let i = 0; i < this.weekData.length; i++) {
  50. dateNum[i] = this.weekData[i].evconsume;
  51. }
  52. // // 颜色设置
  53. // let color = {
  54. // linearYtoG: {
  55. // type: "linear",
  56. // x: 0,
  57. // y: 0,
  58. // x2: 1,
  59. // y2: 1,
  60. // colorStops: [
  61. // {
  62. // offset: 0,
  63. // color: "#f5b44d"
  64. // },
  65. // {
  66. // offset: 1,
  67. // color: "#28f8de"
  68. // }
  69. // ]
  70. // },
  71. // linearGtoB: {
  72. // type: "linear",
  73. // x: 0,
  74. // y: 0,
  75. // x2: 1,
  76. // y2: 0,
  77. // colorStops: [
  78. // {
  79. // offset: 0,
  80. // color: "#43dfa2"
  81. // },
  82. // {
  83. // offset: 1,
  84. // color: "#28f8de"
  85. // }
  86. // ]
  87. // },
  88. // linearBtoG: {
  89. // type: "linear",
  90. // x: 0,
  91. // y: 0,
  92. // x2: 1,
  93. // y2: 0,
  94. // colorStops: [
  95. // {
  96. // offset: 0,
  97. // color: "#1c98e8"
  98. // },
  99. // {
  100. // offset: 1,
  101. // color: "#28f8de"
  102. // }
  103. // ]
  104. // },
  105. // areaBtoG: {
  106. // type: "linear",
  107. // x: 0,
  108. // y: 0,
  109. // x2: 0,
  110. // y2: 1,
  111. // colorStops: [
  112. // {
  113. // offset: 0,
  114. // color: "rgba(35,184,210,.2)"
  115. // },
  116. // {
  117. // offset: 1,
  118. // color: "rgba(35,184,210,0)"
  119. // }
  120. // ]
  121. // }
  122. // };
  123. // let option = {
  124. // tooltip: {
  125. // trigger: "item"
  126. // },
  127. // grid: {
  128. // left: 90,
  129. // right: 80,
  130. // bottom: 40,
  131. // top: "30%"
  132. // },
  133. // xAxis: {
  134. // type: "category",
  135. // position: "bottom",
  136. // axisLine: true,
  137. // axisLabel: {
  138. // color: "rgba(255,255,255,.8)",
  139. // fontSize: 12
  140. // },
  141. // data: weekCategory
  142. // },
  143. // // 下方Y轴
  144. // yAxis: {
  145. // name: "消耗",
  146. // nameLocation: "end",
  147. // nameGap: 24,
  148. // nameTextStyle: {
  149. // color: "rgba(255,255,255,.5)",
  150. // fontSize: 14
  151. // },
  152. // max: maxData,
  153. // splitNumber: 4,
  154. //
  155. // axisLine: {
  156. // lineStyle: {
  157. // opacity: 0
  158. // }
  159. // },
  160. // splitLine: {
  161. // show: true,
  162. // lineStyle: {
  163. // color: "#fff",
  164. // opacity: 0.1
  165. // }
  166. // },
  167. // axisLabel: {
  168. // color: "rgba(255,255,255,.8)",
  169. // fontSize: 12
  170. // }
  171. // },
  172. // series: [
  173. // {
  174. // name: "",
  175. // type: "line",
  176. // smooth: true,
  177. // symbol: "emptyCircle",
  178. // symbolSize: 8,
  179. // itemStyle: {
  180. // normal: {
  181. // color: "#fff"
  182. // }
  183. // },
  184. // lineStyle: {
  185. // normal: {
  186. // color: "rgba(248,211,81,.7)",
  187. // width: 3
  188. // }
  189. // },
  190. // areaStyle: {
  191. // normal: {
  192. // color: color.areaBtoG
  193. // }
  194. // },
  195. // data: weekLineData,
  196. // lineSmooth: true,
  197. // markLine: {
  198. // silent: true,
  199. // data: [
  200. // {
  201. // type: "average",
  202. // name: "平均值"
  203. // }
  204. // ],
  205. // precision: 0,
  206. // label: {
  207. // normal: {
  208. // formatter: "平均值: \n {c}"
  209. // }
  210. // },
  211. // lineStyle: {
  212. // normal: {
  213. // color: "rgba(248,211,81,.7)"
  214. // }
  215. // }
  216. // },
  217. // tooltip: {
  218. // position: "top",
  219. // formatter: "{c} m",
  220. // backgroundColor: "rgba(28,152,232,.2)",
  221. // padding: 6
  222. // }
  223. // },
  224. // {
  225. // name: "占位背景",
  226. // type: "bar",
  227. // itemStyle: {
  228. // normal: {
  229. // show: true,
  230. // color: "#000",
  231. // opacity: 0
  232. // }
  233. // },
  234. // silent: true,
  235. // barWidth: "50%",
  236. // data: weekMaxData,
  237. // animation: false
  238. // }
  239. // ]
  240. // };
  241. let option = {
  242. tooltip: {
  243. trigger: "item"
  244. },
  245. grid: {
  246. left: 90,
  247. right: 80,
  248. bottom: 40,
  249. top: "30%"
  250. },
  251. xAxis: {
  252. type: "category",
  253. position: "bottom",
  254. axisLine: true,
  255. axisLabel: {
  256. color: "rgba(255,255,255,.8)",
  257. fontSize: 12
  258. },
  259. data: ['08:00' ,'11:00' ,'14:00' ,'17:00' ,'20:00' ,'23:00' ,'02:00' ,'05:00' ]
  260. // data: weekCategory
  261. },
  262. yAxis: {
  263. type: 'value'
  264. },
  265. series: [
  266. {
  267. data: [99, 180, 200, 310, 459, 601, 800 ,933],
  268. // data:dateNum,
  269. type: 'line',
  270. smooth: true,
  271. symbolSize: 15,
  272. color:"#28f8de",
  273. lineStyle: {
  274. width: 6
  275. },
  276. markLine: {
  277. silent: true,
  278. data: [
  279. {
  280. type: "average",
  281. name: "额定值",
  282. yAxis: 900
  283. }
  284. ],
  285. precision: 0,
  286. label: {
  287. normal: {
  288. formatter: "额定值: \n {c}"
  289. }
  290. },
  291. lineStyle: {
  292. normal: {
  293. width: 3,
  294. color: "rgba(248,211,81,.7)"
  295. }
  296. }
  297. },
  298. }
  299. ]
  300. };
  301. this.chart.setOption(option);
  302. }
  303. },
  304. destroyed() {
  305. window.onresize = null;
  306. }
  307. };
  308. </script>
  309. <style lang="scss" scoped>
  310. </style>