Echarts.vue 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. <template>
  2. <div class="echarts-body">
  3. <div :id='ids[0]' :style="{width: '130px', height: '130px'}"></div>
  4. <div :id="ids[1]" :style="{width: '130px', height: '130px'}"></div>
  5. <div :id="ids[2]" :style="{width: '130px', height: '130px'}"></div>
  6. <div class="icon">
  7. <img src="../assets/cruise-ship-blue.png" alt="" v-if="ids[0]=='myCharts'">
  8. <img src="../assets/original-blue.png" alt="" v-else>
  9. </div>
  10. </div>
  11. </template>
  12. <script>
  13. export default {
  14. props: {
  15. icon: {
  16. type: String,
  17. default: '../assets/cruise-ship-blue.png'
  18. },
  19. ids: {
  20. type: Array,
  21. default: () => {
  22. return ['myCharts', 'myCharts2', 'myCharts3']
  23. }
  24. },
  25. nums: {
  26. type: Object,
  27. default: () => {
  28. return {
  29. allcount: 11,
  30. idlecount: 0,
  31. repaircount: 0,
  32. runcount: 11
  33. }
  34. }
  35. }
  36. },
  37. created() {
  38. setTimeout(() => {
  39. this.drawLine('#52E686', this.ids[0], '90%', '100%', this.nums.runcount, this.nums
  40. .allcount) // 运行中
  41. this.drawLine('#6CACFC', this.ids[1], '70%', '80%', this.nums.repaircount, this.nums
  42. .allcount) // 维修中
  43. this.drawLine('#FA9DF2', this.ids[2], '50%', '60%', this.nums.idlecount, this.nums
  44. .allcount) // 空闲中
  45. }, 500)
  46. // this.drawLine()
  47. },
  48. methods: {
  49. drawLine(lineColor, id, x, y, num, totaNum) {
  50. // 基于准备好的dom,初始化echarts实例
  51. let myChart = this.$echarts.init(document.getElementById(id))
  52. // 绘制图表
  53. myChart.setOption({
  54. legend: {
  55. orient: 'vertical',
  56. left: 10,
  57. data: ['直接访问', '邮件营销']
  58. },
  59. series: [{
  60. name: '邮轮',
  61. type: 'pie',
  62. radius: [x, y],
  63. hoverAnimation: false,
  64. avoidLabelOverlap: false,
  65. label: {
  66. show: false,
  67. position: 'center'
  68. },
  69. emphasis: {
  70. label: {
  71. show: true,
  72. fontSize: '30',
  73. fontWeight: 'bold'
  74. }
  75. },
  76. labelLine: {
  77. show: false
  78. },
  79. data: [{
  80. value: num,
  81. },
  82. {
  83. value: totaNum - num,
  84. },
  85. ]
  86. }]
  87. });
  88. }
  89. }
  90. }
  91. </script>
  92. <style lang="scss" scoped>
  93. .echarts-body {
  94. position: relative;
  95. height: 100%;
  96. div {
  97. position: absolute;
  98. }
  99. .icon {
  100. width: 35px;
  101. height: 35px;
  102. // background: cadetblue;
  103. top: 47px;
  104. left: 49px;
  105. img {
  106. width: 35px;
  107. height: 35px;
  108. }
  109. }
  110. }
  111. </style>