PieChartone.vue 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  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: '100%'
  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,566)
  61. var colors = ["#00B278","#91CC75","#FAC858", "#EE6666","#73C0DE","#5470C6"];
  62. this.chart.setOption({
  63. series: [{
  64. name: '',
  65. type: 'pie',
  66. radius: ['40%', '80%'],
  67. center: ['50%', '59%'],
  68. labelLine:{
  69. normal:{
  70. length:8, // 指示线长度
  71. lineStyle: {
  72. // color: "#595959" // 指示线颜色
  73. }
  74. },
  75. },
  76. label: {
  77. normal: {
  78. show: true,
  79. position: 'center',
  80. color:'#4c4a4a',
  81. formatter: '{active|总告警数}' + '\n\r' + ' {total|' + row.zs + '}' + '{activen|/次}' ,
  82. rich: {
  83. total:{
  84. fontSize: 20,
  85. fontWight:700,
  86. fontFamily : "微软雅黑",
  87. color:'#454c5c'
  88. },
  89. active: {
  90. fontFamily : "微软雅黑",
  91. fontSize: 16,
  92. color:'#6c7a89',
  93. lineHeight:30,
  94. },
  95. activen: {
  96. fontFamily : "微软雅黑",
  97. fontSize: 16,
  98. color:'#666666',
  99. lineHeight:30,
  100. },
  101. }
  102. },
  103. emphasis: {//中间文字显示
  104. show: true,
  105. }
  106. },
  107. data:[
  108. {value:row.wlfw,
  109. name:'网络服务',
  110. hoverAnimation: false,
  111. itemStyle: {
  112. normal: {
  113. borderWidth: 5, // 为两个颜色之间那个宽度
  114. borderColor: '#fff', // 边框颜色白色
  115. color: colors[0]
  116. }
  117. }
  118. },
  119. {
  120. value:row.sbfw,
  121. name:'设备服务',
  122. hoverAnimation: false,
  123. itemStyle: {
  124. normal: {
  125. borderWidth: 5,
  126. borderColor: '#fff',
  127. color: colors[1]
  128. }
  129. }
  130. },
  131. {
  132. value:row.rjfw,
  133. name:'软件服务',
  134. hoverAnimation: false,
  135. itemStyle: {
  136. normal: {
  137. borderWidth: 5,
  138. borderColor: '#fff',
  139. color: colors[2]
  140. }
  141. }
  142. },
  143. {
  144. value:row.kffw,
  145. name:'开发服务',
  146. hoverAnimation: false,
  147. itemStyle: {
  148. normal: {
  149. borderWidth: 5,
  150. borderColor: '#fff',
  151. color: colors[3]
  152. }
  153. }
  154. },
  155. {
  156. value:row.sjfw,
  157. name:'设计服务',
  158. hoverAnimation: false,
  159. itemStyle: {
  160. normal: {
  161. borderWidth: 5,
  162. borderColor: '#fff',
  163. color: colors[4]
  164. }
  165. }
  166. },
  167. {
  168. value:row.qtfw,
  169. name:'其他服务',
  170. hoverAnimation: false,
  171. itemStyle: {
  172. normal: {
  173. borderWidth: 5,
  174. borderColor: '#fff',
  175. color: colors[5],
  176. }
  177. }
  178. },
  179. ]
  180. }
  181. ]
  182. });
  183. }
  184. }
  185. };
  186. </script>