农经大屏
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

165 lines
3.9 KiB

  1. import * as echarts from 'echarts';
  2. import elementResizeDetectorMaker from 'element-resize-detector';
  3. export default {
  4. props: {
  5. id: {
  6. type: String,
  7. default: 'pie'
  8. },
  9. data: {
  10. type: Array,
  11. default: function () {
  12. return [
  13. {
  14. value: 2154,
  15. unit: '万元',
  16. name: "项目一",
  17. },
  18. {
  19. value: 3854,
  20. unit: '万元',
  21. name: "项目二",
  22. },
  23. {
  24. value: 3854,
  25. unit: '万吨',
  26. name: "项目三",
  27. },
  28. {
  29. value: 3854,
  30. unit: '万吨',
  31. name: "项目四",
  32. }
  33. ];
  34. }
  35. }
  36. },
  37. data () {
  38. return {
  39. chart: null
  40. };
  41. },
  42. mounted () {
  43. this.initChart();
  44. },
  45. computed: {
  46. },
  47. methods: {
  48. // 设置监听器 页面尺寸变化重新绘制图表
  49. initResizeCallBack () {
  50. const erd = elementResizeDetectorMaker();
  51. erd.listenTo(document.getElementById(this.id), () => {
  52. this.$nextTick(() => {
  53. this.chart.resize();
  54. });
  55. });
  56. },
  57. initChart () {
  58. this.chart = echarts.init(document.getElementById(this.id));
  59. this.chartSetOption();
  60. },
  61. chartSetOption () {
  62. var scale = 1;
  63. var echartData = [
  64. ...this.data
  65. ];
  66. var rich = {
  67. yellow: {
  68. color: "rgba(185, 211, 235, 1)",
  69. fontSize: 18 * scale,
  70. padding: [5, 4],
  71. align: "center",
  72. },
  73. total: {
  74. color: "#ffc72b",
  75. fontSize: 40 * scale,
  76. align: "center",
  77. },
  78. white: {
  79. color: "rgba(185, 211, 235, 1)",
  80. align: "center",
  81. fontSize: 18 * scale,
  82. padding: [0, 0],
  83. },
  84. blue: {
  85. color: "rgba(185, 211, 235, 1)",
  86. fontSize: 16 * scale,
  87. align: "center",
  88. },
  89. hr: {
  90. // borderColor: "#0b5263",
  91. width: "100%",
  92. borderWidth: 1,
  93. height: 0,
  94. },
  95. };
  96. const option = {
  97. title: [
  98. {
  99. text: "总债务",
  100. left: "center",
  101. top: "40%",
  102. padding: [0, 0],
  103. textStyle: {
  104. color: "#fff",
  105. fontSize: 18 * scale,
  106. align: "center",
  107. },
  108. },
  109. {
  110. text: "1000 万元",
  111. left: "center",
  112. top: "50%",
  113. padding: [0, 0],
  114. textStyle: {
  115. color: "#fff",
  116. fontSize: 18 * scale,
  117. align: "center",
  118. },
  119. }
  120. ],
  121. series: [
  122. {
  123. name: "",
  124. type: "pie",
  125. radius: ["48%", "70%"],
  126. color: ["rgba(15, 252, 252, 1)", "rgba(134, 91, 252, 1)", "rgba(49, 129, 246, 1)", "rgba(29, 197, 104, 1)"],
  127. label: {
  128. normal: {
  129. formatter: function (params, ticket, callback) {
  130. var total = 0; //考生总数量
  131. var percent = 0; //考生占比
  132. echartData.forEach(function (value, index, array) {
  133. total += value.value;
  134. });
  135. percent = ((params.value / total) * 100).toFixed(1);
  136. return (
  137. "{white|" +
  138. percent + "%" +
  139. "}\n{blue|" +
  140. params.name +
  141. "}\n{hr|}\n{yellow|" +
  142. params.value + params.data.unit + '}'
  143. );
  144. },
  145. rich: rich,
  146. },
  147. },
  148. labelLine: {
  149. normal: {
  150. length: 10 * scale,
  151. length2: 20 * scale,
  152. },
  153. },
  154. data: echartData,
  155. },
  156. ],
  157. };
  158. this.chart.setOption(option);
  159. this.initResizeCallBack();
  160. }
  161. }
  162. };