reportDoughnut.vue 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. <template>
  2. <div style="width:100%;height:100%;textAlign:center;" :id="id">
  3. </div>
  4. </template>
  5. <script>
  6. import echarts from "echarts"
  7. export default {
  8. name: "doughnut",
  9. props: {
  10. id: {
  11. type: String,
  12. default: function createRandomId() {
  13. return (Math.random() * 10000000).toString(16).substr(0, 4) + '-' + (new Date()).getTime() + '-' + Math.random().toString().substr(2, 5);
  14. }
  15. },
  16. renderData: {
  17. type: Array,
  18. default: function () {
  19. return []
  20. }
  21. },
  22. text: {
  23. type: String,
  24. default: function () {
  25. return []
  26. }
  27. },
  28. type: {},
  29. name: "",
  30. sum: ""
  31. },
  32. created(){
  33. },
  34. data() {
  35. return {
  36. myCharts: null
  37. }
  38. },
  39. created() { },
  40. mounted() {
  41. this.drawDoughnut()
  42. },
  43. methods: {
  44. drawDoughnut() {
  45. let options = {
  46. tooltip: {
  47. trigger: 'item',
  48. formatter: "{b}"
  49. },
  50. legend: {
  51. show: false,
  52. orient: 'vertical',
  53. right: 10,
  54. top: 30,
  55. bottom: 20,
  56. data: this.renderData.map(item => {
  57. return item.name
  58. })
  59. },
  60. series: [{
  61. name: '',
  62. type: 'pie',
  63. radius: ['40%', '60%'],
  64. itemStyle: {
  65. normal: {
  66. label: {
  67. show: this.type != 'left' ? false : true,
  68. textStyle: {
  69. color: '#3c4858',
  70. fontSize: "12"
  71. },
  72. formatter: function (val) { //让series 中的文字进行换行
  73. return val.name.split("-")[0];
  74. }
  75. },
  76. title: {
  77. text: 'aaaa'
  78. },
  79. labelLine: {
  80. show: this.type != 'left' ? false : true,
  81. lineStyle: {
  82. }
  83. }
  84. },
  85. emphasis: {
  86. shadowBlur: 5,
  87. shadowOffsetX: 0,
  88. shadowColor: 'rgba(0, 0, 0, 0.5)',
  89. textColor: '#000'
  90. }
  91. },
  92. data: this.renderData
  93. }],
  94. color: ['#67C23A', 'rgb(225, 243, 216)', 'rgb(244, 244, 245)']
  95. }
  96. options.graphic = {
  97. type: 'text',
  98. left: 'center',
  99. top: 'center',
  100. style: {
  101. text: `${this.text|| ''}`,
  102. textAlign: 'center',
  103. fill: '#000',
  104. width: 30,
  105. height: 30
  106. }
  107. }
  108. this.myCharts = echarts.init(document.getElementById(this.id))
  109. this.myCharts.setOption(options)
  110. }
  111. },
  112. watch: {
  113. renderData: {
  114. deep: true,
  115. handler: function () {
  116. this.drawDoughnut()
  117. }
  118. }
  119. }
  120. }
  121. </script>
  122. <style>
  123. </style>