multiple-line-chart.vue 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260
  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 { right } from "@antv/x6/lib/registry/port-layout/main";
  9. export default {
  10. name: "multiple-line-chart",
  11. componentName: "multiple-line-chart",
  12. props: {
  13. width: {
  14. type: String,
  15. default: "100%",
  16. },
  17. height: {
  18. type: String,
  19. default: "100%",
  20. },
  21. chartData: {
  22. type: Array,
  23. default: () => {},
  24. },
  25. isDouble: { type: Boolean, default: false },
  26. type: { type: String, default: "" },
  27. },
  28. data() {
  29. return {
  30. id: "",
  31. chart: null,
  32. chartName: [
  33. { name: "实际功率", code: "sjgl", color: "#4B55AE" },
  34. { name: "理论功率", code: "llgl", color: "#1C99FF" },
  35. { name: "预测功率", code: "ycgl", color: "#F8DE5B" },
  36. { name: "实际风速", name1: "实际光照", code: "pjfs", color: "#05BB4C" },
  37. { name: "预测风速", name1: "预测光照", code: "ycfs", color: "#FF8300" },
  38. ],
  39. };
  40. },
  41. computed: {
  42. series() {
  43. let series = [];
  44. if (this.chartData && this.chartData.xAxis.length) {
  45. for (let key in this.chartData) {
  46. this.chartName.forEach((ele) => {
  47. if (ele.code == key) {
  48. if (ele.code.includes("fs")) {
  49. series.push({
  50. name: this.type == -1 ? ele.name : ele.name1,
  51. type: "line",
  52. symbol: "circle",
  53. showAllSymbol: true,
  54. yAxisIndex: 1,
  55. symbolSize: 0,
  56. smooth: true,
  57. lineStyle: {
  58. normal: {
  59. width: 1,
  60. color: ele.color,
  61. },
  62. // borderColor: "rgba(0,0,0,.4)",
  63. },
  64. itemStyle: {
  65. color: ele.color,
  66. },
  67. tooltip: {
  68. show: true,
  69. },
  70. data: this.chartData[key],
  71. });
  72. } else {
  73. series.push({
  74. name: this.type == -1 ? ele.name : ele.name1,
  75. type: "line",
  76. symbol: "circle",
  77. showAllSymbol: true,
  78. yAxisIndex: 0,
  79. symbolSize: 0,
  80. smooth: true,
  81. lineStyle: {
  82. normal: {
  83. width: 1,
  84. color: ele.color,
  85. },
  86. // borderColor: "rgba(0,0,0,.4)",
  87. },
  88. itemStyle: {
  89. color: ele.color,
  90. },
  91. tooltip: {
  92. show: true,
  93. },
  94. data: this.chartData[key],
  95. });
  96. }
  97. }
  98. });
  99. }
  100. }
  101. return series;
  102. },
  103. // lengend() {
  104. // let arr=[]
  105. // this.chartData.lengend.forEach((i) => {
  106. // if (this.chartName.some((item) => item.code == i)) {
  107. // i = item.name;
  108. // }
  109. // });
  110. // },
  111. },
  112. methods: {
  113. initChart() {
  114. let chart = echarts.init(this.$el);
  115. //图表配置
  116. var option = {
  117. color: this.color,
  118. tooltip: {
  119. trigger: "axis",
  120. },
  121. legend: {
  122. data: this.chartName.map((item) => {
  123. return {
  124. name: item.name,
  125. itemStyle: {
  126. color: item.color,
  127. },
  128. };
  129. }),
  130. itemHeight: 10,
  131. textStyle: {
  132. fontSize: 12,
  133. color: "#93989A",
  134. },
  135. top: "5%",
  136. right: "15%",
  137. },
  138. grid: {
  139. top: "22%",
  140. left: "4%",
  141. right: "4%",
  142. bottom: "12%",
  143. containLabel: true,
  144. },
  145. xAxis: {
  146. type: "category",
  147. boundaryGap: true,
  148. data: this.chartData?.xAxis || [],
  149. axisLabel: {
  150. textStyle: {
  151. color: "#93989A",
  152. },
  153. // formatter: function (params) {
  154. // return params.split(" ")[0] + "\n" + params.split(" ")[1];
  155. // },
  156. },
  157. splitLine: {
  158. show: false,
  159. },
  160. axisLine: {
  161. lineStyle: {
  162. color: "#93989A",
  163. },
  164. },
  165. },
  166. yAxis: [
  167. {
  168. name: "MW",
  169. type: "value",
  170. nameTextStyle: {
  171. color: "#93989A",
  172. },
  173. axisLabel: {
  174. formatter: "{value}",
  175. textStyle: {
  176. color: "#93989A",
  177. },
  178. },
  179. splitLine: {
  180. show: true,
  181. lineStyle: {
  182. color: "rgba(96,103,105,0.3)",
  183. type: "dashed",
  184. },
  185. },
  186. },
  187. {
  188. name: this.type == -1 ? "m/s" : "W/m²",
  189. nameTextStyle: {
  190. color: "#93989A",
  191. },
  192. type: "value",
  193. axisLabel: {
  194. show: true,
  195. formatter: "{value}",
  196. textStyle: {
  197. color: "#93989A",
  198. },
  199. },
  200. splitLine: {
  201. show: false,
  202. },
  203. },
  204. ],
  205. series: this.series || [],
  206. };
  207. if (this.isDouble) {
  208. option.title = {
  209. text: this.chartData?.name,
  210. top: "5%",
  211. left: "35%",
  212. textStyle: {
  213. fontSize: 25,
  214. color: "rgba(255,255,255,0.8)",
  215. fontFamily: 'Arial, "SourceHanSans", "Microsoft YaHei", sans-serif',
  216. },
  217. };
  218. }
  219. chart.setOption(option);
  220. },
  221. },
  222. emits: {
  223. areaClick: null,
  224. },
  225. created() {
  226. this.id = "line-chart-" + util.newGUID();
  227. },
  228. mounted() {
  229. this.$nextTick(() => {
  230. this.$el.style.width = this.width;
  231. this.$el.style.height = this.height;
  232. this.initChart();
  233. });
  234. },
  235. updated() {
  236. this.$nextTick(() => {
  237. this.initChart();
  238. });
  239. },
  240. watch: {
  241. "$store.state.themeName"() {
  242. this.initChart();
  243. },
  244. },
  245. };
  246. </script>
  247. <style lang="less">
  248. .chart {
  249. width: 100%;
  250. height: 100%;
  251. // display: inline-block;
  252. }
  253. </style>