CostPie.vue 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. <!--
  2. * @Author: your name
  3. * @Date: 2021-10-12 08:39:43
  4. * @LastEditTime: 2021-10-12 10:10:54
  5. * @LastEditors: Please set LastEditors
  6. * @Description: 成本分析扇形图
  7. * @FilePath: \hyyfClient\src\views\PdcData\analysis\CostPie.vue
  8. -->
  9. <template>
  10. <div class="cost-pie">
  11. <div id="costPie"></div>
  12. </div>
  13. </template>
  14. <script>
  15. export default {
  16. props: {
  17. data: {
  18. type: Array,
  19. default: () => []
  20. }
  21. },
  22. data() {
  23. return {
  24. myChart: null
  25. }
  26. },
  27. methods: {
  28. init() {
  29. let options = {
  30. grid: {
  31. x: 100
  32. },
  33. legend: {
  34. top: '25%',
  35. left: '75%',
  36. orient: 'vertical',
  37. icon: "circle",
  38. selectedMode: false, // 取消右侧项选中
  39. itemGap: 20, // 各项间隔
  40. textStyle: {
  41. fontSize: 15,
  42. color: '#666'
  43. },
  44. },
  45. series: [
  46. {
  47. // name: 'Access From',
  48. type: 'pie',
  49. radius: '70%', // 半径
  50. center: ['35%', '55%'],
  51. avoidLabelOverlap: false,
  52. labelLine: {
  53. show: true
  54. },
  55. itemStyle: {
  56. normal: {
  57. color: function (colors) { // 颜色设置
  58. var colorList = ['rgb(112,182,3)', 'rgb(232,56,92)', 'rgb(123,0,255)', 'rgb(0,215,233)', 'rgb(255,255,160)', 'rgb(0,0,255)']
  59. return colorList[colors.dataIndex]
  60. },
  61. label: {
  62. formatter: '{b}: {c}%'
  63. }
  64. },
  65. label: {
  66. show: false
  67. },
  68. emphasis: {
  69. label: {
  70. show: true,
  71. formatter: '{b}: {c}%',
  72. textStyle: {
  73. fontSize: '15',
  74. }
  75. },
  76. itemStyle: {
  77. shadowBlur: 10,
  78. shadowOffsetX: 0,
  79. shadowColor: 'rgba(0, 0, 0, 0.5)'
  80. }
  81. },
  82. },
  83. data: this.data
  84. }
  85. ]
  86. };
  87. this.myChart.setOption(options)
  88. }
  89. },
  90. mounted() {
  91. this.myChart = this.$echarts.init(document.getElementById('costPie'));
  92. // this.init()
  93. },
  94. watch: {
  95. data(value) {
  96. console.log('成本分析环形图数据', value)
  97. this.init()
  98. }
  99. }
  100. }
  101. </script>
  102. <style scoped>
  103. .cost-pie {
  104. display: inline-block;
  105. width: 100%;
  106. height: 300px;
  107. }
  108. #costPie {
  109. width: 100%;
  110. height: 100%;
  111. }
  112. </style>>