BingChart.vue 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. <template>
  2. <div class="pie-chart-content">
  3. <div ref="myPieChart" :id="chartId" style="width: 100%; height: 400px"></div>
  4. </div>
  5. </template>
  6. <script>
  7. import * as echarts from "echarts";
  8. export default {
  9. name: "pieChart",
  10. components: {},
  11. props: {
  12. options: {
  13. type: Array,
  14. default: function () {
  15. return [];
  16. },
  17. },
  18. chartId: {
  19. type: String,
  20. default: "",
  21. },
  22. chartName: {
  23. type: String,
  24. default: "",
  25. },
  26. },
  27. data() {
  28. return {
  29. color: ["#FCEF9A", "#D54039", "#56743E", "#FF917C"],
  30. pieData: [],
  31. };
  32. },
  33. // mounted() {
  34. // this.myPieEcharts(this.options);
  35. // },
  36. computed: {},
  37. watch: {
  38. options() {
  39. this.myPieEcharts(this.options);
  40. },
  41. },
  42. mounted() {
  43. window.addEventListener("resize", this.echartsAllSize);
  44. },
  45. destroyed() {
  46. console.log("报告页面销毁了");
  47. window.removeEventListener("resize", this.echartsAllSize);
  48. },
  49. methods: {
  50. echartsAllSize() {
  51. let flag = false;
  52. setTimeout(() => {
  53. flag = true;
  54. if ( flag) {
  55. //设置变化的大小
  56. console.log("大小变化了---------------------");
  57. let myChart = this.$echarts.init(document.getElementById(this.chartId));
  58. myChart.resize();
  59. }
  60. }, 1000);
  61. //大小自适应
  62. //查看当前页面是否显示
  63. },
  64. myPieEcharts(pieData) {
  65. let myChart = this.$echarts.init(document.getElementById(this.chartId));
  66. let option = {
  67. title: {
  68. text: ``,
  69. left: "center",
  70. top: "0px",
  71. textStyle: {
  72. fontSize: "20",
  73. color: "#000000",
  74. foontWeight: "600",
  75. },
  76. },
  77. // tooltip: {
  78. // trigger: "item",
  79. // },
  80. series: [
  81. {
  82. name: ``,
  83. type: "pie",
  84. radius: "60%",
  85. label: {
  86. show: true,
  87. position: "outside", //将文字显示在行内 outside inside
  88. textStyle: {
  89. fontSize: 16, //设置图内显示文字的大小
  90. color: "#000000", //设置饼状图文字的颜色
  91. },
  92. },
  93. // label: {
  94. // show: true,
  95. // position: "inner", //将文字显示在行内
  96. // textStyle: {
  97. // fontSize: 20, //设置图内显示文字的大小
  98. // color: "#ffffff", //设置饼状图文字的颜色
  99. // },
  100. // },
  101. data: [
  102. {
  103. value: pieData[0].value,
  104. name:
  105. pieData[0].value + pieData[1].value == 0
  106. ? "0%"
  107. : parseInt(
  108. (pieData[0].value / (pieData[0].value + pieData[1].value)) * 100
  109. ) +
  110. "%" +
  111. pieData[0].name,
  112. itemStyle: { color: "#5470C6", fontSize: "20" },
  113. },
  114. {
  115. value: pieData[1].value,
  116. name:
  117. pieData[0].value + pieData[1].value == 0
  118. ? "0%"
  119. : 100 -
  120. parseInt(
  121. (pieData[0].value / (pieData[0].value + pieData[1].value)) * 100
  122. ) +
  123. "%" +
  124. pieData[1].name,
  125. itemStyle: { color: "#FFAE00", fontSize: "20" },
  126. },
  127. ],
  128. },
  129. ],
  130. };
  131. pieData && option && myChart.setOption(option);
  132. window.onresize = function () {
  133. console.log("111111111111饼状图大小变化了吗");
  134. myChart.resize();
  135. };
  136. },
  137. pieDataHandle(param) {
  138. this.pieData = [];
  139. // param.groupData.map((item,index) => {
  140. //
  141. // this.lineData.push({
  142. // type: 'line',
  143. // name: item.name,
  144. // data: item.value,
  145. // });
  146. //
  147. // });
  148. //
  149. // this.myLineEcharts(param.category,this.lineData);
  150. },
  151. },
  152. };
  153. </script>
  154. <style scoped>
  155. .pie-chart-content {
  156. width: 100%;
  157. /* height: 100%; */
  158. }
  159. </style>