PanelGroup.vue 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. <template>
  2. <div :class="className" :style="{ height: height, width: width }" />
  3. </template>
  4. <script>
  5. import * as echarts from 'echarts';
  6. require('echarts/theme/macarons'); // echarts theme
  7. import resize from './mixins/resize';
  8. export default {
  9. mixins: [resize],
  10. props: {
  11. className: {
  12. type: String,
  13. default: 'chart'
  14. },
  15. width: {
  16. type: String,
  17. default: '80%'
  18. },
  19. height: {
  20. type: String,
  21. default: '200px'
  22. },
  23. chartData: {
  24. type: Object,
  25. required: true
  26. }
  27. },
  28. watch: {
  29. chartData: {
  30. deep: true,
  31. handler(val) {
  32. this.setOptions(val)
  33. }
  34. }
  35. },
  36. data() {
  37. return {
  38. chart: null
  39. }
  40. },
  41. mounted() {
  42. this.$nextTick(() => {
  43. this.initChart()
  44. })
  45. },
  46. beforeDestroy() {
  47. if (!this.chart) {
  48. return
  49. }
  50. this.chart.dispose()
  51. this.chart = null
  52. },
  53. methods: {
  54. initChart() {
  55. this.chart = echarts.init(this.$el, 'macarons');
  56. this.chart = echarts.init(this.$el, 'macarons')
  57. this.setOptions(this.chartData)
  58. },
  59. setOptions(row) {
  60. console.log(row,56)
  61. this.chart.setOption({
  62. tooltip: {
  63. trigger: 'item'
  64. },
  65. legend: {
  66. top: '5%',
  67. left: 'center',
  68. data: [],
  69. },
  70. // 设置环形中间的数据
  71. graphic: [
  72. {
  73. type: 'text',
  74. left: '50%',
  75. top: '10%',
  76. z: 10,
  77. style: {
  78. fill: '#AAAAAA',
  79. text: "",
  80. font: '16px Microsoft YaHei'
  81. },
  82. textStyle: {
  83. color: '#AAAAAA',
  84. fontSize: 17,
  85. align: 'center'
  86. }
  87. }
  88. ],
  89. series: [
  90. {
  91. name: '车辆进入/辆',
  92. type: 'pie',
  93. radius: ['55%', '70%'],
  94. center: ['50%', '39%'],
  95. avoidLabelOverlap: false,
  96. padAngle: 3, // 调整数值,控制间隔大小
  97. color:['#6096FB', '#4EBCB5',],
  98. label: {
  99. show: true,
  100. position: 'center'
  101. },
  102. // emphasis: {
  103. // label: {
  104. // show: true,
  105. // fontSize: '17',
  106. // fontWeight: '400',
  107. // color:'#2497D5'
  108. // }
  109. // },
  110. labelLine: {
  111. show: true
  112. },
  113. itemStyle: {
  114. normal: {
  115. label: {
  116. show: true
  117. },
  118. labelLine: {
  119. show: true
  120. }
  121. },
  122. emphasis: {
  123. label: {
  124. show: false,
  125. position: 'outer',
  126. textStyle: {
  127. fontSize: '15',
  128. fontWeight: 'bold',
  129. color: '#AAAAAA'
  130. }
  131. }
  132. }
  133. },
  134. data: [ { value: row.nb, name: '内部车辆' },{ value: row.wl, name: '外来车辆' },
  135. ]
  136. }
  137. ]
  138. });
  139. }
  140. }
  141. };
  142. </script>