BrithChart.vue 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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. title:
  58. {
  59. text: '',
  60. }
  61. ,
  62. legend: {
  63. orient: 'vertical',
  64. left: 'left',
  65. itemWidth: 10,
  66. itemHeight: 10,
  67. textStyle: {
  68. fontSize: 12,
  69. padding:[0,0]
  70. },
  71. selectedMode: true,
  72. data: [],
  73. },
  74. series: [
  75. {
  76. name: '',
  77. type: 'pie',
  78. selectedMode: 'single',
  79. label: {
  80. position: 'outside',
  81. fontSize: 10,
  82. },
  83. animationEasing: 'cubicInOut',
  84. animationDuration: 1300,
  85. labelLine: {
  86. show: true
  87. },
  88. data: this.dataOut
  89. }
  90. ],
  91. })
  92. }
  93. }
  94. }
  95. </script>