PieChart.vue 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. <template>
  2. <div :class="className" :style="{height:height,width:width}"/>
  3. </template>
  4. <script>
  5. import * as echarts from 'echarts';
  6. import resize from '@/views/dashboard/mixins/resize'
  7. import {listPlan} from "@/api/ps/patrol/plan";
  8. require('echarts/theme/macarons') // echarts theme
  9. export default {
  10. mixins: [resize],
  11. props: {
  12. className: {
  13. type: String,
  14. default: 'chart'
  15. },
  16. width: {
  17. type: String,
  18. default: '100%'
  19. },
  20. height: {
  21. type: String,
  22. default: '570px'
  23. }
  24. },
  25. data() {
  26. return {
  27. chart: null,
  28. planList: [],
  29. // 查询参数
  30. queryParams: {
  31. planMonth: new Date().getMonth() + 1, planYear: new Date().getFullYear()
  32. },
  33. }
  34. },
  35. mounted() {
  36. this.$nextTick(() => {
  37. this.getList()
  38. })
  39. },
  40. beforeDestroy() {
  41. if (!this.chart) {
  42. return
  43. }
  44. this.chart.dispose()
  45. this.chart = null
  46. },
  47. methods: {
  48. getList() {
  49. listPlan(this.queryParams).then(response => {
  50. response.rows.forEach(item => {
  51. this.planList.push({name: item.planName, value: item.uncheckedNum})
  52. })
  53. this.initChart();
  54. })
  55. },
  56. initChart() {
  57. this.chart = echarts.init(this.$el, 'macarons')
  58. this.chart.setOption({
  59. tooltip: {
  60. trigger: 'item',
  61. formatter: '{a} <br/>{b} : {c} ({d}%)'
  62. },
  63. legend: {
  64. type: 'scroll',
  65. orient: 'horizontalAndVertical',
  66. top: '70%',
  67. data: this.planList,
  68. },
  69. series: [
  70. {
  71. name: '计划中未检测的设备数量',
  72. type: 'pie',
  73. radius: ['30%', '50%'],
  74. center: ['50%', '30%'],
  75. itemStyle:{
  76. borderRadius: 15,
  77. },
  78. emphasis: {
  79. itemStyle: {
  80. shadowBlur: 10,
  81. shadowOffsetX: 0,
  82. shadowColor: 'rgba(0, 0, 0, 0.5)'
  83. }
  84. },
  85. data: this.planList,
  86. animationEasing: 'cubicInOut',
  87. animationDuration: 2600
  88. }
  89. ]
  90. })
  91. }
  92. }
  93. }
  94. </script>