performanceEcharts.vue 5.6 KB

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