PanelGroupfour.vue 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. <template>
  2. <div :class="className" :style="{ height: height, width: width }" />
  3. </template>
  4. <script>
  5. import 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: '150px'
  18. },
  19. height: {
  20. type: String,
  21. default: '150px'
  22. },
  23. autoResize: {
  24. type: Boolean,
  25. default: true
  26. },
  27. chartData: {
  28. type: Object,
  29. required: true
  30. }
  31. },
  32. data() {
  33. return {
  34. chart: null
  35. };
  36. },
  37. watch: {
  38. chartData: {
  39. deep: true,
  40. handler(val) {
  41. this.setOptions(val)
  42. }
  43. }
  44. },
  45. mounted() {
  46. this.$nextTick(() => {
  47. this.initChart();
  48. });
  49. console.log(this.chartData,58)
  50. },
  51. beforeDestroy() {
  52. if (!this.chart) {
  53. return;
  54. }
  55. this.chart.dispose();
  56. this.chart = null;
  57. },
  58. methods: {
  59. initChart() {
  60. this.chart = echarts.init(this.$el, 'macarons');
  61. this.chart = echarts.init(this.$el, 'macarons')
  62. this.setOptions(this.chartData)
  63. },
  64. setOptions({ columnNewsNum , columnNewsTodayNum,columnNews } = {}) {
  65. this.chart.setOption({
  66. color: [new echarts.graphic.LinearGradient(1, 0, 0, 0, [{
  67. offset: 0,
  68. color: '#F69F24'
  69. },
  70. {
  71. offset: 1,
  72. color: '#F69F24'
  73. }]), new echarts.graphic.LinearGradient(1, 1, 0, 0, [{
  74. offset: 0,
  75. color: '#FFE1B7'
  76. },
  77. {
  78. offset: 0.9,
  79. color: '#FFE1B7'
  80. }]),],
  81. tooltip: {
  82. trigger: 'item'
  83. },
  84. legend: {
  85. top: '10%',
  86. left: 'center',
  87. data:[]
  88. },
  89. // 设置环形中间的数据
  90. graphic: [{
  91. type: 'text',
  92. left: 'center',
  93. top: '46%',
  94. z: 10,
  95. style: {
  96. fill: '#F69F24',
  97. text: columnNews,
  98. font: '16px Microsoft YaHei'
  99. },
  100. textStyle: {
  101. color: "#F69F24",
  102. fontSize: 17,
  103. align: "center"
  104. }
  105. }],
  106. series: [
  107. {
  108. name: '发文次数',
  109. type: 'pie',
  110. radius: ['50%', '70%'],
  111. center: ['center', '50%'],
  112. avoidLabelOverlap: false,
  113. // label: {
  114. // show: false,
  115. // position: 'center'
  116. // },
  117. // emphasis: {
  118. // label: {
  119. // show: true,
  120. // fontSize: '17',
  121. // fontWeight: '400',
  122. // color:'#2497D5'
  123. // }
  124. // },
  125. // labelLine: {
  126. // show: true
  127. // },
  128. itemStyle: {
  129. normal: {
  130. label: {
  131. show: false
  132. },
  133. labelLine: {
  134. show: false
  135. }
  136. },
  137. emphasis: {
  138. label: {
  139. show: false,
  140. position: 'outer',
  141. textStyle: {
  142. fontSize: '15',
  143. fontWeight: 'bold',
  144. color: 'white'
  145. }
  146. }
  147. }
  148. },
  149. data: [
  150. {value: columnNewsNum, name: '总计发布文章'},
  151. {value: columnNewsTodayNum, name: '今日发布文章'}
  152. ]
  153. }
  154. ]
  155. })
  156. }
  157. }
  158. };
  159. </script>