performanceEcharts.vue 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261
  1. <template>
  2. <div class="chart" :id="id"></div>
  3. </template>
  4. <script>
  5. import util from "@/helper/util.js";
  6. import partten from "@/helper/partten.js";
  7. import * as echarts from "echarts";
  8. import ecStat from "echarts-stat";
  9. export default {
  10. components: {
  11. ecStat,
  12. },
  13. props: {
  14. width: {
  15. type: String,
  16. default: "100%",
  17. },
  18. height: {
  19. type: String,
  20. default: "350px",
  21. },
  22. showTime: {
  23. type: Boolean,
  24. default: false,
  25. },
  26. // 传入数据
  27. data: {
  28. type: Array,
  29. default: () => [
  30. [96.24, 11.35],
  31. [33.09, 85.11],
  32. [57.6, 36.61],
  33. [36.77, 27.26],
  34. [20.1, 6.72],
  35. [45.53, 36.37],
  36. [110.07, 80.13],
  37. [72.05, 20.88],
  38. [39.82, 37.15],
  39. [48.05, 70.5],
  40. [0.85, 2.57],
  41. [51.66, 63.7],
  42. [61.07, 127.13],
  43. [64.54, 33.59],
  44. [35.5, 25.01],
  45. [226.55, 664.02],
  46. [188.6, 175.31],
  47. [81.31, 108.68],
  48. ],
  49. },
  50. dotName: {
  51. type: String,
  52. default: "",
  53. },
  54. },
  55. data() {
  56. return {
  57. id: "",
  58. chart: null,
  59. color: ["#05bb4c", "#f8de5b", "#4b55ae", "#fa8c16"],
  60. xdata: [],
  61. };
  62. },
  63. methods: {
  64. resize() {},
  65. initChart() {
  66. const chart = echarts.init(this.$el);
  67. echarts.registerTransform(ecStat.transform.regression);
  68. let option = {
  69. legend: {
  70. show: true,
  71. data: ["实发功率", "理论功率", "实时风速"],
  72. right: 120,
  73. icon: "ract",
  74. itemWidth: 8,
  75. itemHeight: 8,
  76. textStyle: {
  77. fontSize: "14px",
  78. color: "#fff",
  79. },
  80. },
  81. dataset: [
  82. {
  83. source: this.data,
  84. },
  85. {
  86. transform: {
  87. type: "ecStat:regression",
  88. config: {
  89. method: "polynomial",
  90. order: 3,
  91. },
  92. },
  93. },
  94. ],
  95. tooltip: {
  96. trigger: "axis",
  97. },
  98. xAxis: [
  99. {
  100. type: "category",
  101. boundaryGap: false,
  102. axisLabel: {
  103. interval:
  104. Number((this.xdata.length / 6).toFixed(0)) > 2
  105. ? Number((this.xdata.length / 6).toFixed(0))
  106. : 0,
  107. showMinLabel: true,
  108. showMaxLabel: true,
  109. formatter: "{value}",
  110. fontSize: 12,
  111. textStyle: {
  112. color: "#606769",
  113. },
  114. },
  115. axisLine: {
  116. show: false,
  117. },
  118. data: this.xdata,
  119. },
  120. ],
  121. // {
  122. // name: "时间",
  123. // splitLine: {
  124. // lineStyle: {
  125. // color: partten.getColor("gray") + 55,
  126. // type: "dashed",
  127. // },
  128. // },
  129. // splitNumber: 20,
  130. // data: this.xAxisData,
  131. // },
  132. yAxis: [
  133. {
  134. name: "功率(kWh)",
  135. type: "value",
  136. axisTick: {
  137. show: false,
  138. length: 1,
  139. },
  140. splitLine: {
  141. lineStyle: {
  142. color: partten.getColor("gray") + 55,
  143. type: "dashed",
  144. },
  145. },
  146. },
  147. {
  148. name: "风速(m/s)",
  149. type: "value",
  150. axisTick: {
  151. show: false,
  152. length: 1,
  153. },
  154. splitLine: {
  155. lineStyle: {
  156. color: partten.getColor("gray") + 55,
  157. type: "dashed",
  158. },
  159. },
  160. },
  161. ],
  162. series: [],
  163. };
  164. if (this.data?.power?.length > 0) {
  165. let arr = [];
  166. this.data.power.forEach((item) => {
  167. arr.push(item.doubleValue);
  168. });
  169. let obj = {
  170. name: "实发功率",
  171. type: "line",
  172. data: arr,
  173. smooth: true, //平滑展示
  174. yAxisIndex: 0,
  175. };
  176. option.series.push(obj);
  177. }
  178. if (this.data?.llglpower?.length > 0) {
  179. let arr = [];
  180. this.data.llglpower.forEach((item) => {
  181. arr.push(item.doubleValue);
  182. });
  183. let obj = {
  184. name: "理论功率",
  185. type: "line",
  186. data: arr,
  187. smooth: true, //平滑展示
  188. yAxisIndex: 0,
  189. };
  190. option.series.push(obj);
  191. }
  192. if (this.data?.speed?.length > 0) {
  193. let arr = [];
  194. this.data.speed.forEach((item) => {
  195. arr.push(item.doubleValue);
  196. });
  197. let obj = {
  198. name: "实时风速",
  199. type: "line",
  200. data: arr,
  201. smooth: true, //平滑展示
  202. yAxisIndex: 1,
  203. };
  204. option.series.push(obj);
  205. }
  206. chart.clear();
  207. chart.setOption(option);
  208. this.resize = function () {
  209. chart.resize();
  210. };
  211. window.addEventListener("resize", this.resize);
  212. },
  213. },
  214. created() {
  215. this.id = "pie-chart-" + util.newGUID();
  216. },
  217. mounted() {
  218. this.$nextTick(() => {
  219. this.$el.style.width = this.width;
  220. this.$el.style.height = this.height;
  221. this.initChart();
  222. });
  223. },
  224. updated() {
  225. let data = [];
  226. if (this.data?.power.length > 0 || this.data?.speed.length > 0) {
  227. if (this.showTime) {
  228. this.data?.power.forEach((value, index) => {
  229. data.push(new Date(value.ts).formatDate("MM-dd hh:mm"));
  230. });
  231. } else {
  232. this.data?.power.forEach((value, index) => {
  233. data.push(new Date(value.ts).formatDate("yyyy-MM-dd hh:mm"));
  234. });
  235. }
  236. this.xdata = data;
  237. }
  238. this.$nextTick(() => {
  239. this.initChart();
  240. });
  241. },
  242. unmounted() {
  243. window.removeEventListener("resize", this.resize);
  244. },
  245. };
  246. </script>
  247. <style lang="less">
  248. .chart {
  249. width: 100%;
  250. height: 100%;
  251. display: inline-block;
  252. }
  253. </style>