windChartCom.vue 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  1. <template>
  2. <div class="home_card">
  3. <!-- <div class="header"> <img src="@/../public/img/home/arrows.png"> {{CurveTitle}}曲线</div> -->
  4. <div class="windChart">
  5. <div :id="chartId" :style="{ width: width, height: height }"></div>
  6. </div>
  7. </div>
  8. </template>
  9. <script>
  10. import * as echarts from "echarts";
  11. import dayjs from "dayjs";
  12. export default {
  13. name: "windChartCom",
  14. props: {
  15. width: {
  16. type: String,
  17. default: "100%",
  18. },
  19. height: {
  20. type: String,
  21. default: "70vh",
  22. },
  23. CurveTitle: {
  24. type: String,
  25. required: true,
  26. },
  27. chartShow: {
  28. type: Boolean,
  29. required: true,
  30. default: false,
  31. },
  32. windCurveValues: {
  33. type: Array,
  34. required: true,
  35. },
  36. chartId: {
  37. type: String,
  38. required: true,
  39. },
  40. ratio: {
  41. type: Number,
  42. default: 1,
  43. },
  44. unit: {
  45. type: String,
  46. default: "",
  47. },
  48. },
  49. async created() {},
  50. mounted() {
  51. this.$nextTick(() => {
  52. this.getChart();
  53. });
  54. },
  55. data() {
  56. return {
  57. emptyData: [],
  58. };
  59. },
  60. methods: {
  61. getChart() {
  62. var chartDom = document.getElementById(this.chartId);
  63. var myChart = echarts.init(chartDom); // 绘制图表
  64. var options = {
  65. tooltip: {
  66. trigger: "axis",
  67. backgroundColor: "rgba(0, 0, 0, 0.3)",
  68. textStyle: {
  69. fontSize: 16,
  70. fontFamily: "楷体",
  71. color: "white", //设置文字颜色
  72. fontWeight: "400",
  73. },
  74. },
  75. legend: {
  76. top: "6%",
  77. right: "2%",
  78. textStyle: {
  79. fontSize: "12",
  80. color: "#A4A4A5",
  81. },
  82. orient: "vertical",
  83. icon: "roundRect",
  84. itemWidth: 5,
  85. itemHeight: 5,
  86. itemGap: 7,
  87. },
  88. xAxis: {
  89. type: "category",
  90. boundaryGap: false,
  91. axisTick: {
  92. alignWithLabel: true,
  93. },
  94. axisLabel: {
  95. show: true,
  96. textStyle: {
  97. color: "#606769",
  98. },
  99. },
  100. axisLine: {
  101. lineStyle: {
  102. color: "#606769", //x轴的颜色
  103. width: 1, //轴线的宽度
  104. },
  105. },
  106. // splitLine: { show: false },
  107. // data: this.windCurveValues.map((item) => item.dateTime),
  108. },
  109. yAxis: {
  110. name: this.unit,
  111. nameTextStyle: {
  112. fontSize: 16,
  113. align: "right",
  114. },
  115. type: "value",
  116. splitNumber: this.unit == "%" ? 2 : 3,
  117. max: this.unit == "%" ? "100" : null,
  118. splitLine: {
  119. show: false,
  120. textStyle: {
  121. color: "#606769",
  122. },
  123. },
  124. axisLine: {
  125. lineStyle: {
  126. color: "#606769", // y轴的颜色
  127. width: 1, //y轴线的宽度
  128. },
  129. },
  130. },
  131. grid: [
  132. {
  133. left: 80,
  134. right: 40,
  135. top: 30,
  136. bottom: 30,
  137. containLabel: true,
  138. },
  139. ],
  140. series: [
  141. {
  142. name: this.CurveTitle,
  143. type: "line",
  144. smooth: true,
  145. symbol: "none",
  146. areaStyle: {
  147. opacity: 0.7,
  148. color: new echarts.graphic.LinearGradient(2, 2, 0, 2, [
  149. {
  150. offset: 0,
  151. color: "rgba(53, 150, 235, 1)",
  152. },
  153. {
  154. offset: 1,
  155. color: "rgba(18, 32, 50, 0.2)",
  156. },
  157. ]),
  158. },
  159. lineStyle: {
  160. width: 1,
  161. },
  162. color: "#3596EB",
  163. data: this.windCurveValues.map((item) => {
  164. return [item.dateTime, item.value];
  165. }),
  166. },
  167. ],
  168. };
  169. myChart.setOption(options);
  170. },
  171. //处理数据
  172. getData(datas) {
  173. let data = [];
  174. //查询的测点没有数据情况
  175. if (datas && datas.length > 0) {
  176. datas.forEach((item) => {
  177. let result;
  178. if (item.value) {
  179. result = (Number(item.value) / this.ratio).toFixed(2);
  180. } else {
  181. result = item.value;
  182. }
  183. data.push(result);
  184. });
  185. return data;
  186. } else {
  187. return this.emptyData;
  188. }
  189. },
  190. },
  191. computed: {
  192. getTimeStanp() {
  193. // 当日0点时间
  194. var timeStamp = [];
  195. let stamp = new Date(new Date().setHours(0, 0, 0, 0)).getTime();
  196. for (let i = 0; i < 96; i++) {
  197. timeStamp.push(dayjs(stamp).format("HH:mm"));
  198. this.emptyData.push("0");
  199. stamp = parseInt(stamp) + 15 * 60 * 1000;
  200. }
  201. timeStamp.push("24:00");
  202. return timeStamp;
  203. },
  204. },
  205. watch: {
  206. windCurveValues: {
  207. handler() {
  208. this.getChart();
  209. },
  210. },
  211. },
  212. };
  213. </script>
  214. <style lang="less" scoped></style>