TestCaseCountChart.vue 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. <template>
  2. <div>
  3. <div class="chart-title">用例-缺陷数量直方图</div>
  4. <div id="testCaseCountChart" :class="className" :style="{height:height,width:width}" />
  5. </div>
  6. </template>
  7. <script>
  8. import echarts from 'echarts'
  9. require('echarts/theme/macarons') // echarts theme
  10. import resize from './mixins/resize'
  11. const animationDuration = 6000
  12. export default {
  13. mixins: [resize],
  14. props: {
  15. className: {
  16. type: String,
  17. default: 'chart'
  18. },
  19. width: {
  20. type: String,
  21. default: '100%'
  22. },
  23. height: {
  24. type: String,
  25. default: '380px'
  26. },
  27. counts: {
  28. type: Object,
  29. default: function () {
  30. return {}
  31. }
  32. }
  33. },
  34. watch: {
  35. counts: {
  36. handler (nv, ov) {
  37. if (nv) {
  38. this.YValue[0] = nv['testCaseCount']
  39. this.YValue[1] = nv['validTestCaseCount']
  40. this.YValue[2] = nv['invalidTestCaseCount']
  41. this.YValue[3] = nv['noExamedTestCaseCount']
  42. this.YValue[4] = nv['defectCount']
  43. }
  44. this.initChart()
  45. },
  46. deep: true
  47. }
  48. },
  49. data () {
  50. return {
  51. chart: null,
  52. XData: ['用例总数', '有效用例数', '无效用例数', '待审用例数', '缺陷总数'],
  53. YValue: [0, 0, 0, 0, 0]
  54. }
  55. },
  56. mounted () {
  57. this.$nextTick(() => {
  58. this.initChart()
  59. })
  60. },
  61. beforeDestroy () {
  62. if (!this.chart) {
  63. return
  64. }
  65. this.chart.dispose()
  66. this.chart = null
  67. },
  68. methods:{
  69. initChart() {
  70. this.chart = echarts.init(document.getElementById('testCaseCountChart'), 'macarons')
  71. this.chart.setOption({
  72. // title:{
  73. // text:'众测成绩分布直方图',
  74. // padding:20
  75. // },
  76. tooltip: {
  77. trigger: 'axis',
  78. axisPointer: { // 坐标轴指示器,坐标轴触发有效
  79. type: 'shadow' // 默认为直线,可选为:'line' | 'shadow'
  80. }
  81. },
  82. grid: {
  83. top: 10,
  84. left: '2%',
  85. right: '2%',
  86. bottom: '3%',
  87. containLabel: true
  88. },
  89. xAxis: [{
  90. name: '严重程度',
  91. type: 'category',
  92. data: Array.from(this.XData),
  93. axisTick: {
  94. alignWithLabel: true
  95. },
  96. axisLabel: {interval: 0}
  97. }],
  98. yAxis: [{
  99. name: '数量',
  100. type: 'value',
  101. axisTick: {
  102. show: false
  103. }
  104. }],
  105. series: [{
  106. type: 'bar',
  107. stack: 'vistors',
  108. barWidth: '60%',
  109. data: Array.from(this.YValue),
  110. animationDuration
  111. }]
  112. })
  113. }
  114. }
  115. }
  116. </script>