pieChart.vue 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. <template>
  2. <div ref="pieChart" style="width: 100%; height: 100%;padding-top:.375rem"></div>
  3. </template>
  4. <script>
  5. import * as echarts from "echarts";
  6. export default {
  7. props: ["fdeviceTypeCount"],
  8. data() {
  9. return {
  10. deviceTypeCount: this.fdeviceTypeCount,
  11. };
  12. },
  13. mounted() {
  14. this.$nextTick(() => {
  15. // console.log("子组件中");
  16. // console.log(this.deviceTypeCount);
  17. // console.log(this.deviceTypeCount.normalCount);
  18. this.initChart();
  19. });
  20. },
  21. beforeUnmount() {
  22. window.removeEventListener("resize", this.chart);
  23. },
  24. methods: {
  25. //次数分布折线图
  26. initChart() {
  27. // console.log(this.fdeviceTypeCount)
  28. var chart = echarts.init(this.$refs.pieChart);
  29. var option;
  30. var pie = [
  31. {
  32. value: this.deviceTypeCount.normalCount,
  33. name: "正常",
  34. },
  35. {
  36. value:this.deviceTypeCount.faultCount,
  37. name: "故障",
  38. },
  39. {
  40. value:this.deviceTypeCount.offLineCount,
  41. name: "离线",
  42. },
  43. {
  44. value: this.deviceTypeCount.deviceCount,
  45. name: "预警",
  46. },
  47. ];
  48. var totalNum = 0;
  49. pie.forEach(function (value) {
  50. totalNum += value.value;
  51. });
  52. option = {
  53. grid: {
  54. },
  55. title: [
  56. {
  57. text: "{name|" + totalNum + "}\n{val|设备总数}",
  58. top: "center",
  59. left: "center",
  60. textStyle: {
  61. rich: {
  62. name: {
  63. fontSize: 30,
  64. fontWeight: "normal",
  65. color: "#FFFFFF",
  66. fontFamily: "impact",
  67. padding: [0, 0, 3, 0],
  68. },
  69. val: {
  70. fontSize: 14,
  71. fontWeight: "normal",
  72. color: "#FFFFFF",
  73. padding: [3, 0, 0, 0],
  74. },
  75. },
  76. },
  77. },
  78. ],
  79. tooltip: {
  80. trigger: "item",
  81. formatter: function (params) {
  82. return (
  83. params.name +
  84. ":" +
  85. params.value +
  86. "<br>占比:" +
  87. params.percent.toFixed(2) +
  88. "%"
  89. );
  90. },
  91. },
  92. // itemStyle:{
  93. // normal: {
  94. // label: {
  95. // show: true,
  96. // position: 'outside',
  97. // color: 'green',
  98. // }
  99. // }
  100. // },
  101. series: [
  102. {
  103. label: {
  104. normal: {
  105. show: true,
  106. textStyle: {
  107. color: "#fff",
  108. },
  109. formatter: " {b}:{c} ",
  110. },
  111. emphasis: {
  112. show: true,
  113. },
  114. },
  115. name: "访问来源",
  116. radius: ["45%", "67%"],
  117. type: "pie",
  118. data: pie,
  119. },
  120. ],
  121. color: ["#0DFE95", "#F7B61C", "#2BCCFF", "#FE5C0D", "#4388F9"],
  122. };
  123. chart.setOption(option,true);
  124. window.addEventListener("resize", () => {
  125. chart.resize();
  126. });
  127. this.chart = chart;
  128. },
  129. },
  130. };
  131. </script>