powerEcharts.vue 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342
  1. <template>
  2. <!-- 72小时功率曲线-->
  3. <div
  4. class="powerTitle"
  5. :style="{ 'margin-bottom': orient ? '10px' : '' }"
  6. v-if="showTitle"
  7. >
  8. 24小时功率曲线
  9. </div>
  10. <div :id="'main' + id" :style="{ width: width, height: height }"></div>
  11. </template>
  12. <script>
  13. import * as echarts from "echarts";
  14. import dayjs from "dayjs";
  15. export default {
  16. name: "powerEcharts",
  17. props: {
  18. id: {
  19. type: String,
  20. default: "",
  21. },
  22. showTitle: {
  23. type: Boolean,
  24. default: true,
  25. },
  26. predictFlag: {
  27. type: Boolean,
  28. default: false,
  29. },
  30. width: {
  31. type: String,
  32. default: "100%",
  33. },
  34. height: {
  35. type: String,
  36. default: "100%",
  37. },
  38. CurveValues: {
  39. type: Array,
  40. required: true,
  41. },
  42. // 单位
  43. unit: {
  44. type: String,
  45. default: "",
  46. },
  47. //倍率
  48. ratio: {
  49. type: Number,
  50. default: 1,
  51. },
  52. orient: String,
  53. },
  54. data() {
  55. return {
  56. emptyData: [],
  57. current: 0,
  58. };
  59. },
  60. mounted() {
  61. this.$nextTick(() => {
  62. this.getChart();
  63. window.addEventListener("resize", this.resize);
  64. });
  65. },
  66. methods: {
  67. resize() {
  68. var chartDom = document.getElementById(`main${this.id}`);
  69. var myChart = echarts.init(chartDom); // 绘制图表
  70. myChart.resize();
  71. },
  72. getChart() {
  73. var chartDom = document.getElementById(`main${this.id}`);
  74. var myChart = echarts.init(chartDom); // 绘制图表
  75. var options = {
  76. title: {},
  77. axisLine: {
  78. lineStyle: {
  79. color: "#272729", //x轴的颜色
  80. width: 2, //轴线的宽度
  81. },
  82. },
  83. tooltip: {
  84. // formatter: '{a} <br/>{b} : {c}',
  85. trigger: "axis",
  86. backgroundColor: "rgba(5, 187, 76,0.35)",
  87. borderColor: "#05bb4c",
  88. formatter: function (params) {
  89. var htmlStr = `<div style='font-size:16px;color:#fff;margin-bottom:5px'>${params[0].axisValue}</div>`;
  90. for (var i = 0; i < params.length; i++) {
  91. htmlStr += `<div style='font-size:16px;color:#fff;margin-bottom:2px'>`;
  92. var param = params[i];
  93. var seriesName = param.seriesName; //图例名称
  94. var value = param.value; //y轴值
  95. var data = param.data; //单位判断code
  96. var mark = param.marker; //点
  97. var unit = `<span style='font-size:14px'>`;
  98. htmlStr += mark; //一个点
  99. htmlStr += `${seriesName} : ${
  100. value != null ? value + unit + " MW</span>" : "--"
  101. }`; //圆点后面显示的文本
  102. htmlStr += "</div>";
  103. }
  104. return htmlStr;
  105. },
  106. },
  107. legend: {
  108. top: this.orient ? "0" : "6%",
  109. right: this.orient ? "16%" : "2%",
  110. textStyle: {
  111. fontSize: "12",
  112. color: "#A4A4A5",
  113. },
  114. orient: this.orient ? this.orient : "vertical",
  115. icon: "roundRect",
  116. itemWidth: 5,
  117. itemHeight: 5,
  118. itemGap: 7,
  119. },
  120. xAxis: {
  121. boundaryGap: false, //x轴从0开始
  122. axisLabel: {
  123. textStyle: {
  124. color: "#606769",
  125. },
  126. },
  127. axisLine: {
  128. lineStyle: {
  129. color: "#606769", //x轴的颜色
  130. width: 1, //轴线的宽度
  131. },
  132. },
  133. axisTick: {
  134. alignWithLabel: true,
  135. },
  136. splitLine: { show: false },
  137. data: this.getTimeStanp,
  138. },
  139. yAxis: {
  140. type: "value",
  141. name: this.unit,
  142. nameTextStyle: {
  143. color: "#828484",
  144. fontSize: 14,
  145. align: "right",
  146. },
  147. splitNumber: 3,
  148. splitLine: {
  149. show: false,
  150. },
  151. axisLabel: {
  152. show: true,
  153. textStyle: {
  154. color: "#606769",
  155. },
  156. },
  157. axisLine: {
  158. lineStyle: {
  159. color: "#606769", // y轴的颜色
  160. width: 1, //y轴线的宽度
  161. },
  162. },
  163. },
  164. grid: [
  165. {
  166. left: 25,
  167. right: this.orient ? 100 : 28,
  168. top: 30,
  169. bottom: 30,
  170. containLabel: true,
  171. },
  172. ],
  173. series: this.series,
  174. };
  175. myChart.setOption(options);
  176. },
  177. //处理数据
  178. getData(datas) {
  179. let data = [];
  180. //查询的测点没有数据情况
  181. if (datas && datas.length > 0) {
  182. datas.forEach((item) => {
  183. let result;
  184. if (item.value) {
  185. result = {
  186. dateTime: item.dateTime,
  187. value: item.value,
  188. };
  189. } else {
  190. result = item;
  191. }
  192. data.push(result);
  193. });
  194. return data;
  195. } else {
  196. return this.emptyData;
  197. }
  198. },
  199. },
  200. computed: {
  201. getTimeStanp() {
  202. // 当日0点时间
  203. var timeStamp = [];
  204. let stamp = new Date(new Date().setHours(0, 0, 0, 0)).getTime();
  205. if (this.predictFlag) {
  206. for (let i = 0; i < 48; i++) {
  207. timeStamp.push(dayjs(stamp).format("HH:mm"));
  208. this.emptyData.push("0");
  209. stamp = parseInt(stamp) + 30 * 60 * 1000;
  210. }
  211. timeStamp.push("24:00");
  212. } else {
  213. for (let i = 0; i < 24; i++) {
  214. timeStamp.push(dayjs(stamp).format("HH:mm"));
  215. this.emptyData.push("0");
  216. stamp = parseInt(stamp) + 60 * 60 * 1000;
  217. }
  218. }
  219. this.emptyData.push("0");
  220. return timeStamp;
  221. },
  222. series() {
  223. let series = [
  224. {
  225. name: "预测功率",
  226. type: "line",
  227. smooth: true,
  228. symbol: "none",
  229. lineStyle: {
  230. width: 1,
  231. },
  232. color: "#C530C8",
  233. data: this.getData(this.CurveValues[0]?.value),
  234. },
  235. {
  236. name: "理论功率",
  237. type: "line",
  238. smooth: true,
  239. symbol: "none",
  240. lineStyle: {
  241. width: 1,
  242. },
  243. color: "#FF8700FF",
  244. data: this.getData(this.CurveValues[1]?.value),
  245. },
  246. {
  247. name: "实际功率",
  248. type: "line",
  249. smooth: true,
  250. symbol: "none",
  251. lineStyle: {
  252. width: 1,
  253. },
  254. color: "#1C99FFFF",
  255. textStyle: {
  256. color: "red",
  257. },
  258. data: this.getData(this.CurveValues[2]?.value),
  259. },
  260. ];
  261. return series;
  262. },
  263. },
  264. watch: {
  265. "$store.state.isFixed"() {
  266. this.$nextTick(() => {
  267. this.resize();
  268. });
  269. },
  270. CurveValues: {
  271. handler() {
  272. this.$nextTick(() => {
  273. this.getChart();
  274. window.addEventListener("resize", this.resize);
  275. });
  276. },
  277. },
  278. },
  279. };
  280. </script>
  281. <style lang="less" scoped>
  282. .powerTitle {
  283. font-size: 16px;
  284. font-family: "思源黑体";
  285. font-weight: 400;
  286. color: #ffffff;
  287. padding-top: 16px;
  288. padding-left: 27px;
  289. display: flex;
  290. flex-direction: row;
  291. align-items: center;
  292. justify-content: space-between;
  293. .tabs {
  294. display: flex;
  295. flex-direction: row;
  296. align-items: center;
  297. margin-right: 25px;
  298. margin-top: -10px;
  299. }
  300. .left {
  301. display: flex;
  302. align-items: center;
  303. justify-content: center;
  304. width: 70px;
  305. height: 25px;
  306. background: rgba(67, 81, 107, 0.6);
  307. border: 1px solid #3b4c6c;
  308. border-radius: 13px 0px 0px 13px;
  309. font-size: 14px;
  310. font-family: Microsoft YaHei;
  311. font-weight: 400;
  312. color: #b3b3b3;
  313. &.active {
  314. background: rgba(0, 70, 199, 0.5);
  315. color: #ffffff;
  316. }
  317. }
  318. .right {
  319. display: flex;
  320. align-items: center;
  321. justify-content: center;
  322. width: 70px;
  323. height: 25px;
  324. background: rgba(67, 81, 107, 0.6);
  325. border: 1px solid #3b4c6c;
  326. border-radius: 0px 13px 13px 0px;
  327. font-size: 14px;
  328. font-family: Microsoft YaHei;
  329. font-weight: 400;
  330. color: #b3b3b3;
  331. &.active {
  332. background: rgba(0, 70, 199, 0.5);
  333. color: #ffffff;
  334. }
  335. }
  336. }
  337. </style>