pieChart.vue 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286
  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. export default {
  9. name: "double-line-chart",
  10. componentName: "double-line-chart",
  11. props: {
  12. width: {
  13. type: String,
  14. default: "100%",
  15. },
  16. height: {
  17. type: String,
  18. default: "13.889vh",
  19. },
  20. // 传入数据
  21. lossPower: {
  22. type: Object,
  23. default: () => {},
  24. },
  25. // 单位
  26. unit: {
  27. type: String,
  28. default: "",
  29. },
  30. //倍率
  31. ratio: {
  32. type: Number,
  33. default: 1,
  34. },
  35. showLegend: {
  36. type: Boolean,
  37. default: false,
  38. },
  39. // 颜色
  40. color: {
  41. type: Array,
  42. default: () => [
  43. "#005bd9",
  44. "#019f2e",
  45. "#db6200",
  46. "#a10f0f",
  47. "#850894",
  48. "#9fa0a2",
  49. ],
  50. },
  51. },
  52. data() {
  53. return {
  54. id: "",
  55. chart: null,
  56. newlist: null,
  57. };
  58. },
  59. watch: {
  60. list: {
  61. handler(newValue, oldValue) {
  62. this.newlist = newValue;
  63. this.$nextTick(() => {
  64. this.newlist = this.list;
  65. this.initChart();
  66. });
  67. },
  68. deep: true,
  69. },
  70. "$store.state.themeName"() {
  71. this.initChart();
  72. },
  73. },
  74. methods: {
  75. resize() {},
  76. initChart() {
  77. const chart = echarts.init(this.$el);
  78. let that = this;
  79. let option = {
  80. color: this.color,
  81. legend: {
  82. type: "scroll",
  83. top: 20,
  84. itemWidth: 8,
  85. itemHeight: 8,
  86. textStyle: {
  87. color: "#fff",
  88. fontSize: 12,
  89. },
  90. // formatter(params) {
  91. // switch (params) {
  92. // case "实发电量":
  93. // return (
  94. // params +
  95. // " " +
  96. // (that.lossPower?.SFDL
  97. // ? that.lossPower?.SFDL?.toFixed(2)
  98. // : "0")
  99. // );
  100. // case "故障损失":
  101. // return (
  102. // params +
  103. // " " +
  104. // (that.lossPower?.GZSS
  105. // ? that.lossPower?.GZSS?.toFixed(2)
  106. // : "0")
  107. // );
  108. // case "检修损失":
  109. // return (
  110. // params +
  111. // " " +
  112. // (that.lossPower?.WHSS
  113. // ? that.lossPower?.WHSS?.toFixed(2)
  114. // : "0")
  115. // );
  116. // case "受累损失":
  117. // return (
  118. // params +
  119. // " " +
  120. // (that.lossPower?.SLSS
  121. // ? that.lossPower?.SLSS?.toFixed(2)
  122. // : "0")
  123. // );
  124. // case "限电损失":
  125. // return (
  126. // params +
  127. // " " +
  128. // (that.lossPower?.XDSS
  129. // ? that.lossPower?.XDSS?.toFixed(2)
  130. // : "0")
  131. // );
  132. // case "性能损失":
  133. // return (
  134. // params +
  135. // " " +
  136. // (that.lossPower?.XNSS
  137. // ? that.lossPower?.XNSS?.toFixed(2)
  138. // : "0")
  139. // );
  140. // }
  141. // },
  142. },
  143. tooltip: {
  144. trigger: "item",
  145. formatter(params) {
  146. return `${params?.marker} ${
  147. params?.name
  148. } ${params?.data?.realVal?.toFixed(2)}`;
  149. },
  150. },
  151. radar: [
  152. {
  153. indicator: [{ text: "" }],
  154. center: ["50%", "60%"],
  155. radius: [0, 79],
  156. startAngle: 60,
  157. splitNumber: 5,
  158. shape: "circle",
  159. name: {
  160. formatter: "",
  161. textStyle: {
  162. color: "#0000FF",
  163. },
  164. },
  165. splitArea: {
  166. areaStyle: {
  167. color: "rgba(0, 0, 0, 0)",
  168. },
  169. },
  170. axisLine: {
  171. lineStyle: {
  172. color: "rgba(0, 0, 0, 0)",
  173. },
  174. },
  175. splitLine: {
  176. lineStyle: {
  177. color: "#0a389c",
  178. shadowColor: "#0a389c",
  179. shadowBlur: 10,
  180. },
  181. },
  182. },
  183. ],
  184. series: [
  185. {
  186. name: "",
  187. type: "pie",
  188. radius: [0, 80],
  189. center: ["50%", "60%"],
  190. roseType: "area",
  191. label: {
  192. normal: {
  193. color: "#fff",
  194. formatter: "{d}%",
  195. },
  196. },
  197. data: [
  198. {
  199. value: this.lossPower.SFDL
  200. ? this.lossPower?.SFDL / this.lossPower?.SUM
  201. : 0,
  202. name: "实发电量",
  203. realVal: this.lossPower?.SFDL,
  204. },
  205. {
  206. value: this.lossPower.XNSS
  207. ? this.lossPower?.XNSS / this.lossPower?.SUM
  208. : 0,
  209. name: "性能损失",
  210. realVal: this.lossPower?.XNSS,
  211. },
  212. {
  213. value: this.lossPower.WHSS
  214. ? this.lossPower?.WHSS / this.lossPower?.SUM
  215. : 0,
  216. name: "检修损失",
  217. realVal: this.lossPower?.WHSS,
  218. },
  219. {
  220. value: this.lossPower.GZSS
  221. ? this.lossPower?.GZSS / this.lossPower?.SUM
  222. : 0,
  223. name: "故障损失",
  224. realVal: this.lossPower?.GZSS,
  225. },
  226. {
  227. value: this.lossPower.XDSS
  228. ? this.lossPower?.XDSS / this.lossPower?.SUM
  229. : 0,
  230. name: "限电损失",
  231. realVal: this.lossPower?.XDSS,
  232. },
  233. {
  234. value: this.lossPower.SLSS
  235. ? this.lossPower?.SLSS / this.lossPower?.SUM
  236. : 0,
  237. name: "受累损失",
  238. realVal: this.lossPower?.SLSS,
  239. },
  240. ],
  241. },
  242. ],
  243. };
  244. chart.clear();
  245. chart.setOption(option);
  246. this.resize = function () {
  247. chart.resize();
  248. };
  249. window.addEventListener("resize", this.resize);
  250. },
  251. },
  252. created() {
  253. this.$nextTick(() => {
  254. this.id = "pie-chart-" + util.newGUID();
  255. });
  256. this.newlist = this.list;
  257. },
  258. mounted() {
  259. this.$nextTick(() => {
  260. this.$el.style.width = this.width;
  261. this.$el.style.height = this.height;
  262. this.initChart();
  263. });
  264. },
  265. updated() {
  266. this.$nextTick(() => {
  267. this.initChart();
  268. });
  269. },
  270. unmounted() {
  271. window.removeEventListener("resize", this.resize);
  272. },
  273. };
  274. </script>
  275. <style lang="less">
  276. .chart {
  277. width: 100%;
  278. height: 100%;
  279. display: inline-block;
  280. }
  281. </style>