ProductionDonut.vue 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. <!--
  2. * @Author: your name
  3. * @Date: 2021-10-11 14:54:18
  4. * @LastEditTime: 2021-12-21 08:46:56
  5. * @LastEditors: Please set LastEditors
  6. * @Description: 生产情况的环形图
  7. * @FilePath: \hyyfClient\src\components\erp\ProductionDonut.vue
  8. -->
  9. <template>
  10. <div class="production-donut">
  11. <div :id="id" class="chartPie"></div>
  12. </div>
  13. </template>
  14. <script>
  15. export default {
  16. props: {
  17. id: {
  18. type: Number,
  19. required: true,
  20. },
  21. stockName: {
  22. type: String,
  23. required: true,
  24. },
  25. stockQuantity: {
  26. type: String,
  27. default: () => 0,
  28. },
  29. color: {
  30. type: String,
  31. required: true,
  32. },
  33. },
  34. data() {
  35. return {
  36. myChart: null,
  37. rest: 0,
  38. };
  39. },
  40. methods: {
  41. init() {
  42. this.rest = 1 - parseFloat(this.stockQuantity);
  43. const useColor = this.color;
  44. let options = {
  45. title: {
  46. text: this.stockName,
  47. x: 35,
  48. y: 175,
  49. },
  50. grid: {
  51. x: 100,
  52. y: 200,
  53. },
  54. graphic: [
  55. {
  56. type: "text",
  57. left: "35",
  58. top: "38%",
  59. style: {
  60. text: (parseFloat(this.stockQuantity) * 100).toFixed(2) + "%",
  61. fontSize: 28,
  62. fill: useColor,
  63. },
  64. },
  65. ],
  66. series: [
  67. {
  68. name: "Access From",
  69. type: "pie",
  70. radius: ["65%", "80%"], // 半径
  71. center: ["30%", "45%"],
  72. avoidLabelOverlap: false,
  73. label: {
  74. show: false,
  75. },
  76. hoverAnimation: false,
  77. emphasis: {
  78. label: {
  79. show: false,
  80. fontSize: "40",
  81. fontWeight: "bold",
  82. },
  83. },
  84. labelLine: {
  85. show: false,
  86. },
  87. itemStyle: {
  88. normal: {
  89. color: function(colors) {
  90. // 颜色设置
  91. var colorList = [useColor, "#000000"];
  92. return colorList[colors.dataIndex];
  93. },
  94. // borderWidth: 5, // 设置各项空隙
  95. // borderColor: '#fff'
  96. },
  97. },
  98. data: [
  99. { value: parseFloat(this.stockQuantity) },
  100. { value: this.rest },
  101. // { value: 2032, name: '哺乳仔猪存栏' },
  102. // { value: 1644, name: '保育猪存栏' },
  103. // { value: 1546, name: '育肥猪存栏' }
  104. ],
  105. },
  106. ],
  107. };
  108. this.myChart.setOption(options);
  109. },
  110. },
  111. mounted() {
  112. this.myChart = this.$echarts.init(document.getElementById(this.id));
  113. this.init();
  114. },
  115. watch: {
  116. stockName: {
  117. handler(newValue) {
  118. console.log(newValue);
  119. this.init();
  120. },
  121. },
  122. },
  123. };
  124. </script>
  125. <style scoped>
  126. .production-donut {
  127. display: inline-block;
  128. margin-top: 20px;
  129. width: 20%;
  130. height: 200px;
  131. }
  132. .chartPie {
  133. width: 100%;
  134. height: 100%;
  135. }
  136. </style>