getPieView.vue 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. <template>
  2. <div class="pieView">
  3. <div style="height: 14%;line-height: 30px;text-align: left;padding-left: 10px;color: white;">{{info.config.title||""}}</div>
  4. <div style="width:100%;height:86%;display: inline-block; overflow: hidden;">
  5. <div :id="info.config.idSelector"
  6. style="width:100%;height:95%;overflow: hidden;"> </div>
  7. </div>
  8. </div>
  9. </template>
  10. <script>
  11. import * as echarts from "echarts";
  12. export default {
  13. data() {
  14. return {
  15. }
  16. },
  17. props: {
  18. info: {
  19. type: Object,
  20. default: {}
  21. }
  22. },
  23. mounted() {
  24. let this_ = this;
  25. this.$nextTick(() => {
  26. this_.getMiddleLeft();
  27. })
  28. },
  29. methods: {
  30. getMiddleLeft() {
  31. let chartDom = document.getElementById(this.info.config.idSelector);
  32. var myChart = echarts.init(chartDom);
  33. var option;
  34. option = {
  35. title: {
  36. show: true,
  37. left: 'center',
  38. textStyle: {
  39. color: '#fff',
  40. fontSize: 20,
  41. fontWeight: '600'
  42. },
  43. },
  44. color: this.info.color,
  45. tooltip: {
  46. trigger: 'item',
  47. formatter: '{d}%'
  48. },
  49. label: {
  50. formatter: '{b}\n({d}%)',
  51. edgeDistance: "20%"
  52. },
  53. legend: {
  54. show: true,
  55. z: 3,
  56. left: 'right',
  57. textStyle: {
  58. color: '#fff'
  59. }
  60. },
  61. series: [{
  62. type: 'pie',
  63. radius: '70%',
  64. center: ['50%', '50%'],
  65. data: this.info.data,
  66. emphasis: {
  67. itemStyle: {
  68. shadowBlur: 10,
  69. shadowOffsetX: 0,
  70. shadowColor: 'rgba(0, 0, 0, 0.5)'
  71. }
  72. },
  73. labelLine: {
  74. distanceToLabelLine: 0,
  75. },
  76. }]
  77. };
  78. myChart.setOption(option);
  79. },
  80. },
  81. watch: {
  82. info: {
  83. handler(newVal, oldVal) {
  84. this.getMiddleLeft()
  85. },
  86. deep: true
  87. }
  88. }
  89. };
  90. </script>
  91. <style lang="scss" scoped>
  92. .pieView {
  93. width: 100%;
  94. height: 100%;
  95. overflow: hidden;
  96. background-color: rgba(6, 30, 93, 0.5);
  97. }
  98. </style>