windChartCom.vue 5.9 KB

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