pieCharts.vue 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. <template>
  2. <div class="precisionEcharts" :style="style" :id="id"></div>
  3. </template>
  4. <script>
  5. import * as echarts from "echarts";
  6. export default {
  7. props: {
  8. warningTimeList: {
  9. type: Array,
  10. },
  11. id: Object,
  12. width: {
  13. type: String,
  14. default: "600px",
  15. },
  16. height: {
  17. type: String,
  18. default: "250px",
  19. },
  20. },
  21. data() {
  22. return {
  23. xindex: [],
  24. };
  25. },
  26. computed: {
  27. style() {
  28. return `width: ${this.width}; height: ${this.height};`;
  29. },
  30. },
  31. mounted() {
  32. this.deal();
  33. this.$nextTick(() => {
  34. this.initChart();
  35. });
  36. },
  37. updated() {
  38. this.$nextTick(() => {
  39. this.initChart();
  40. });
  41. },
  42. methods: {
  43. deal() {
  44. for (let index = 0; index < 35; index++) {
  45. this.xindex.push(index);
  46. }
  47. },
  48. initChart() {
  49. let seriesData = [];
  50. this.warningTimeList.forEach((item) => {
  51. let obj = {
  52. value: item.num,
  53. name: item.name,
  54. };
  55. seriesData.push(obj);
  56. });
  57. let chartDom = document.getElementById(this.id);
  58. let myChart = echarts.init(chartDom);
  59. let option = {
  60. title: {
  61. text: "",
  62. },
  63. tooltip: {
  64. trigger: "item",
  65. },
  66. legend: {
  67. top: "5%",
  68. left: "center",
  69. textStyle: {
  70. color: "#ffffff",
  71. fontSize: 14,
  72. },
  73. },
  74. series: [
  75. {
  76. name: "报警次数",
  77. type: "pie",
  78. radius: ["30%", "60%"],
  79. avoidLabelOverlap: false,
  80. itemStyle: {
  81. borderRadius: 10,
  82. borderColor: "#000",
  83. borderWidth: 2,
  84. },
  85. label: {
  86. show: true,
  87. normal: {
  88. show: true,
  89. textStyle: {
  90. fontSize: "20",
  91. color: "#ffffff",
  92. },
  93. },
  94. emphasis: {
  95. show: true,
  96. textStyle: {
  97. fontSize: "25",
  98. color: "#ffffff",
  99. },
  100. },
  101. },
  102. emphasis: {
  103. label: {
  104. show: true,
  105. fontSize: "40",
  106. fontWeight: "bold",
  107. },
  108. },
  109. labelLine: {
  110. show: true,
  111. },
  112. data: seriesData,
  113. },
  114. ],
  115. };
  116. option && myChart.setOption(option);
  117. },
  118. Compare(property) {
  119. return function (a, b) {
  120. var value1 = a[property];
  121. var value2 = b[property];
  122. return value1 - value2;
  123. };
  124. },
  125. },
  126. watch: {
  127. warningTimeList: {
  128. handler(newValue, oldValue) {
  129. this.initChart();
  130. },
  131. deep: true,
  132. },
  133. },
  134. };
  135. </script>
  136. <style lang="less" scoped>
  137. // .precisionEcharts {
  138. // width: 600px;
  139. // height: 250px;
  140. // }
  141. </style>