windChartCom.vue 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  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. },
  45. async created() {},
  46. mounted() {
  47. this.$nextTick(() => {
  48. this.getChart();
  49. });
  50. },
  51. data() {
  52. return {
  53. emptyData: [],
  54. };
  55. },
  56. methods: {
  57. getChart() {
  58. var chartDom = document.getElementById(this.chartId);
  59. var myChart = echarts.init(chartDom); // 绘制图表
  60. var options = {
  61. title: {},
  62. tooltip: {
  63. trigger: "axis",
  64. backgroundColor: "rgba(0, 0, 0, 0.3)",
  65. textStyle: {
  66. color: "white", //设置文字颜色
  67. },
  68. },
  69. legend: {
  70. top: "6%",
  71. right: "2%",
  72. textStyle: {
  73. fontSize: "12",
  74. color: "#A4A4A5",
  75. },
  76. orient: "vertical",
  77. icon: "roundRect",
  78. itemWidth: 5,
  79. itemHeight: 5,
  80. itemGap: 7,
  81. },
  82. xAxis: {
  83. type: "category",
  84. axisTick: {
  85. alignWithLabel: true,
  86. },
  87. axisLabel: {
  88. show: true,
  89. textStyle: {
  90. color: "#606769",
  91. },
  92. },
  93. axisLine: {
  94. lineStyle: {
  95. color: "#606769", //x轴的颜色
  96. width: 1, //轴线的宽度
  97. },
  98. },
  99. // splitLine: { show: false },
  100. // data: this.windCurveValues.map((item) => item.dateTime),
  101. },
  102. yAxis: {
  103. type: "value",
  104. splitNumber: 3,
  105. splitLine: {
  106. show: false,
  107. textStyle: {
  108. color: "#606769",
  109. },
  110. },
  111. axisLine: {
  112. lineStyle: {
  113. color: "#606769", // y轴的颜色
  114. width: 1, //y轴线的宽度
  115. },
  116. },
  117. },
  118. grid: [
  119. {
  120. left: 80,
  121. right: 40,
  122. top: 20,
  123. bottom: 30,
  124. },
  125. ],
  126. series: [
  127. {
  128. name: this.CurveTitle,
  129. type: "line",
  130. smooth: true,
  131. symbol: "none",
  132. areaStyle: {
  133. opacity: 0.7,
  134. color: new echarts.graphic.LinearGradient(2, 2, 0, 2, [
  135. {
  136. offset: 0,
  137. color: "rgba(53, 150, 235, 1)",
  138. },
  139. {
  140. offset: 1,
  141. color: "rgba(18, 32, 50, 0.2)",
  142. },
  143. ]),
  144. },
  145. lineStyle: {
  146. width: 1,
  147. },
  148. color: "#3596EB",
  149. data: this.windCurveValues.map((item) => {
  150. return [item.dateTime, item.value];
  151. }),
  152. },
  153. ],
  154. };
  155. console.log(options);
  156. myChart.setOption(options);
  157. },
  158. //处理数据
  159. getData(datas) {
  160. let data = [];
  161. //查询的测点没有数据情况
  162. if (datas && datas.length > 0) {
  163. datas.forEach((item) => {
  164. let result;
  165. if (item.value) {
  166. result = (Number(item.value) / this.ratio).toFixed(2);
  167. } else {
  168. result = item.value;
  169. }
  170. data.push(result);
  171. });
  172. return data;
  173. } else {
  174. return this.emptyData;
  175. }
  176. },
  177. },
  178. computed: {
  179. getTimeStanp() {
  180. // 当日0点时间
  181. var timeStamp = [];
  182. let stamp = new Date(new Date().setHours(0, 0, 0, 0)).getTime();
  183. for (let i = 0; i < 96; i++) {
  184. timeStamp.push(dayjs(stamp).format("HH:mm"));
  185. this.emptyData.push("0");
  186. stamp = parseInt(stamp) + 15 * 60 * 1000;
  187. }
  188. timeStamp.push("24:00");
  189. return timeStamp;
  190. },
  191. },
  192. watch: {
  193. windCurveValues: {
  194. handler() {
  195. this.getChart();
  196. },
  197. },
  198. },
  199. };
  200. </script>
  201. <style lang="less" scoped></style>