pieChart.vue 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. <template>
  2. <div ref="distion" style="width: 100%; height: 100%"></div>
  3. </template>
  4. <script>
  5. import * as echarts from "echarts";
  6. export default {
  7. props: {
  8. // className: {
  9. // type: String,
  10. // default: "chart",
  11. // },
  12. // width: {
  13. // type: String,
  14. // default: "100%",
  15. // },
  16. // height: {
  17. // type: String,
  18. // default: "400px",
  19. // },
  20. // perData: {
  21. // type: Array,
  22. // default: () => [
  23. // {
  24. // color: "#01ACFF",
  25. // name: "摄像头",
  26. // value: [39],
  27. // // nAmount: 566557.14,
  28. // },
  29. // ],
  30. // },
  31. },
  32. data() {
  33. return {};
  34. },
  35. mounted() {
  36. this.$nextTick(() => {
  37. this.initChart();
  38. });
  39. },
  40. beforeUnmount() {
  41. window.removeEventListener("resize", this.chart);
  42. },
  43. methods: {
  44. //次数分布折线图
  45. initChart() {
  46. var chart = echarts.init(this.$refs.distion);
  47. var option;
  48. var pie = [
  49. {
  50. value: 12,
  51. name: "配电",
  52. },
  53. {
  54. value: 5,
  55. name: "箱变",
  56. },
  57. {
  58. value: 3,
  59. name: "杆变",
  60. },
  61. ];
  62. var totalNum = 0;
  63. pie.forEach(function (value) {
  64. totalNum += value.value;
  65. });
  66. option = {
  67. grid: {
  68. },
  69. title: [
  70. {
  71. text: "{name|" + totalNum + "}\n{val|总数}",
  72. top: "center",
  73. left: "center",
  74. textStyle: {
  75. rich: {
  76. name: {
  77. fontSize: 30,
  78. fontWeight: "normal",
  79. color: "#FFFFFF",
  80. fontFamily:"impact",
  81. padding: [0, 0,3,0]
  82. },
  83. val: {
  84. fontSize: 14,
  85. fontWeight: "normal",
  86. color: "#FFFFFF",
  87. padding: [3,0,0, 0]
  88. },
  89. },
  90. },
  91. },
  92. ],
  93. tooltip: {
  94. // trigger: "item",
  95. trigger: 'item',
  96. confine:true,//将此限制打开后tooltip将不再溢出
  97. formatter: function (params) {
  98. return (
  99. params.name +
  100. ":" +
  101. params.value +
  102. "<br>占比:" +
  103. params.percent.toFixed(2) +
  104. "%"
  105. );
  106. },
  107. },
  108. series: [
  109. {
  110. label: {
  111. position: "inside",//此处将展示的文字在内部展示
  112. normal: {
  113. show: true,
  114. formatter: " {b}:{c} ",
  115. },
  116. emphasis: {
  117. show: true,
  118. },
  119. },
  120. name: "访问来源",
  121. radius: ["43%", "65%"],
  122. type: "pie",
  123. data: pie,
  124. labelLine: {
  125. normal: {
  126. length: 3, //aa折线长度
  127. // length2: 1, //aa折线长度
  128. }
  129. },
  130. // labelLine:{
  131. // normal:{
  132. // length:5
  133. // }
  134. // },
  135. },
  136. ],
  137. color: ["#39BBFE", "#FCCB35", "#FC7735"],
  138. };
  139. chart.setOption(option);
  140. window.addEventListener("resize", () => {
  141. chart.resize();
  142. });
  143. this.chart = chart;
  144. },
  145. },
  146. };
  147. </script>