pieChartProjectInfo.vue 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. <template>
  2. <div class="linechart" :id="id" style="width: 100%; height: 100%"></div>
  3. </template>
  4. <script>
  5. //import from '';
  6. export default {
  7. name: "pieChartProjectInfo", // 手动运行项目详情-饼图
  8. components: {},
  9. data() {
  10. return {
  11. charts: "",
  12. colors: [
  13. "#5B8FF9",
  14. "#61DDAA",
  15. "#65789B",
  16. "#F6BD16",
  17. "#FF5C5C",
  18. "#4671C6",
  19. "#7CCE7A",
  20. "#FFC655",
  21. "#4BC2DF",
  22. "#00A476",
  23. "#FF7D46",
  24. "#A45DB2",
  25. ],
  26. };
  27. },
  28. props: {
  29. id: {
  30. default: "pieChartProjectInfo",
  31. type: String,
  32. },
  33. seriesName: {
  34. default: "统计",
  35. type: String,
  36. },
  37. stateName: {
  38. default: "name",
  39. type: String,
  40. },
  41. stateList: {
  42. default: function () {
  43. return [];
  44. },
  45. type: Array,
  46. },
  47. },
  48. watch: {
  49. stateList(val) {
  50. if (val.length > 0) {
  51. this.initStateList();
  52. }
  53. },
  54. },
  55. methods: {
  56. initStateList() {
  57. let stateList = this.stateList;
  58. let data = [];
  59. for (let index = 0; index < stateList.length; index++) {
  60. const element = stateList[index];
  61. data[index] = {
  62. value: element.num,
  63. // name: element[this.stateName] + "\n" + element.num,
  64. name: element[this.stateName],
  65. itemStyle: {
  66. normal: {
  67. color: this.colors[index],
  68. },
  69. },
  70. };
  71. }
  72. let option = {
  73. title: {
  74. text: "暂无数据",
  75. show: stateList.length === 0,
  76. left: "center",
  77. top: "center",
  78. },
  79. tooltip: {
  80. //提示框,可以在全局也可以在
  81. trigger: "item", //提示框的样式
  82. formatter: "{a} <br/>{b}: {c} ({d}%)",
  83. // formatter: "{a} <br/>{b} {c} ({d}%)",
  84. color: "#000", //提示框的背景色
  85. textStyle: {
  86. //提示的字体样式
  87. color: "#ffffff",
  88. },
  89. confine: true,
  90. },
  91. legend: {
  92. orient: "vertical",
  93. left: "left",
  94. },
  95. series: [
  96. {
  97. name: this.seriesName,
  98. type: "pie",
  99. radius: ["40%", "70%"],
  100. avoidLabelOverlap: true,
  101. data,
  102. top: 10,
  103. label: {
  104. show: false,
  105. position: "outside",
  106. },
  107. emphasis: {
  108. label: {
  109. show: true,
  110. // fontSize: "20",
  111. // fontWeight: "bold",
  112. },
  113. },
  114. },
  115. ],
  116. };
  117. this.charts.setOption(option);
  118. },
  119. },
  120. mounted() {
  121. this.charts = this.$echarts.init(document.getElementById(this.id));
  122. this.initStateList();
  123. this.$nextTick(() => {
  124. window.addEventListener("resize", () => {
  125. this.charts.resize();
  126. });
  127. });
  128. },
  129. destroyed() {
  130. // console.log("destroyed");
  131. this.charts.dispose();
  132. },
  133. };
  134. </script>
  135. <style lang='less' scoped>
  136. .linechart {
  137. margin: 0 auto;
  138. overflow: hidden;
  139. }
  140. </style>