CostPie.vue 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. <template>
  2. <div id="costPie" style="width: 100%; height: 100%;"></div>
  3. </template>
  4. <script>
  5. export default {
  6. props: {
  7. pieData: {
  8. type: Array,
  9. default: () => []
  10. }
  11. },
  12. data() {
  13. return {
  14. myChart: null
  15. }
  16. },
  17. methods: {
  18. init() {
  19. let options = {
  20. grid: {
  21. x: 100
  22. },
  23. // legend: {
  24. // top: '25%',
  25. // left: '75%',
  26. // orient: 'vertical',
  27. // icon: "circle",
  28. // selectedMode: false, // 取消右侧项选中
  29. // itemGap: 20, // 各项间隔
  30. // textStyle: {
  31. // fontSize: 15,
  32. // color: '#666'
  33. // },
  34. // },
  35. series: [
  36. {
  37. // name: 'Access From',
  38. type: 'pie',
  39. radius: '70%', // 半径
  40. center: ['50%', '55%'],
  41. avoidLabelOverlap: false,
  42. labelLine: {
  43. show: true
  44. },
  45. itemStyle: {
  46. normal: {
  47. color: function (colors) { // 颜色设置
  48. 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)']
  49. return colorList[colors.dataIndex]
  50. },
  51. label: {
  52. formatter: '{b}: {c}%'
  53. }
  54. },
  55. label: {
  56. show: false
  57. },
  58. emphasis: {
  59. label: {
  60. show: true,
  61. formatter: '{b}: {c}%',
  62. textStyle: {
  63. fontSize: '15',
  64. }
  65. },
  66. itemStyle: {
  67. shadowBlur: 10,
  68. shadowOffsetX: 0,
  69. shadowColor: 'rgba(0, 0, 0, 0.5)'
  70. }
  71. },
  72. },
  73. data: this.pieData
  74. }
  75. ]
  76. };
  77. this.myChart.setOption(options)
  78. }
  79. },
  80. mounted() {
  81. this.myChart = this.$echarts.init(document.getElementById('costPie'));
  82. this.init()
  83. },
  84. watch: {
  85. data(value) {
  86. console.log('成本分析环形图数据', value)
  87. this.init()
  88. }
  89. }
  90. }
  91. </script>
  92. <style scoped>
  93. #costPie {
  94. width: 100%;
  95. height: 100%;
  96. }
  97. </style>>