pieChartProjectInfo.vue 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  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. itemStyle: {
  65. normal: {
  66. color: this.colors[index],
  67. },
  68. },
  69. };
  70. }
  71. let option = {
  72. tooltip: {
  73. //提示框,可以在全局也可以在
  74. trigger: "item", //提示框的样式
  75. // formatter: "{a} <br/>{b}: {c} ({d}%)",
  76. formatter: "{a} <br/>{b} ({d}%)",
  77. color: "#000", //提示框的背景色
  78. textStyle: {
  79. //提示的字体样式
  80. color: "#ffffff",
  81. },
  82. confine: true,
  83. },
  84. series: [
  85. {
  86. name: this.seriesName,
  87. type: "pie",
  88. // radius: '55%',
  89. avoidLabelOverlap: true,
  90. data,
  91. top: 10,
  92. },
  93. ],
  94. };
  95. this.charts.setOption(option);
  96. },
  97. },
  98. mounted() {
  99. this.charts = this.$echarts.init(document.getElementById(this.id));
  100. this.$nextTick(() => {
  101. window.addEventListener("resize", () => {
  102. this.charts.resize();
  103. });
  104. });
  105. },
  106. destroyed() {
  107. // console.log("destroyed");
  108. this.charts.dispose();
  109. },
  110. };
  111. </script>
  112. <style lang='less' scoped>
  113. .linechart {
  114. margin: 0 auto;
  115. overflow: hidden;
  116. }
  117. </style>