BrithChart.vue 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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. import { trainNewstaffCount} from "@/api/training/newstaff/tnNew";
  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: '210px'
  23. }
  24. },
  25. data() {
  26. return {
  27. chart: null,
  28. dataOut: []
  29. }
  30. },
  31. mounted() {
  32. this.$nextTick(() => {
  33. trainNewstaffCount().then(res=>{
  34. this.dataOut = [
  35. {value: res.data.count1, name: res.data.count1Name},
  36. {value: res.data.count0, name: res.data.count0Name},
  37. ]
  38. this.initChart()
  39. })
  40. })
  41. },
  42. beforeDestroy() {
  43. if (!this.chart) {
  44. return
  45. }
  46. this.chart.dispose()
  47. this.chart = null
  48. },
  49. methods: {
  50. initChart() {
  51. this.chart = echarts.init(this.$el, 'macarons')
  52. this.chart.setOption({
  53. tooltip: {
  54. trigger: 'item',
  55. formatter: "{b}: {c} " + " | " + "{d}%"
  56. },
  57. color: [
  58. '#87CA8B',
  59. '#FBD44A'
  60. ],
  61. title:
  62. {
  63. text: '',
  64. }
  65. ,
  66. legend: {
  67. orient: 'vertical',
  68. left: 'left',
  69. itemWidth: 10,
  70. itemHeight: 10,
  71. textStyle: {
  72. fontSize: 12,
  73. padding:[0,0]
  74. },
  75. selectedMode: true,
  76. data:['已完成','未完成']
  77. },
  78. series: [
  79. {
  80. name: '',
  81. type: 'pie',
  82. selectedMode: 'single',
  83. label: {
  84. position: 'outside',
  85. fontSize: 10,
  86. },
  87. animationEasing: 'cubicInOut',
  88. animationDuration: 1300,
  89. labelLine: {
  90. show: true
  91. },
  92. data: this.dataOut
  93. }
  94. ],
  95. })
  96. }
  97. }
  98. }
  99. </script>