BarTdsjyt.vue 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. <template>
  2. <div ref="dom" style="width:100% ;height:300px;">
  3. </div>
  4. </template>
  5. <script>
  6. import * as echarts from "echarts";
  7. export default {
  8. name: "BarData",
  9. data() {
  10. return {
  11. a: [],
  12. b: [],
  13. }
  14. },
  15. props: {
  16. resultXData: {
  17. },
  18. seriesName:{
  19. type:String,
  20. },
  21. titleText: {
  22. type: String,
  23. },
  24. dw: {
  25. type: String,
  26. },
  27. },
  28. mounted() {
  29. /*setTimeout(() => {
  30. this.getPie();
  31. }, 1000)*/
  32. },
  33. watch: {
  34. resultXData: {
  35. handler(newVal) {
  36. this.$nextTick(function() {
  37. this.resultYData = newVal
  38. this.getPie()
  39. })
  40. },
  41. deep: true,
  42. immediate: true
  43. },
  44. },
  45. methods: {
  46. getPie() {
  47. var _this= this;
  48. // 绘制图表
  49. /* this.$nextTick(() => {*/
  50. var option = {
  51. title: {
  52. text: this.titleText,
  53. x: 'left', //标题位置
  54. // textStyle: { //标题内容的样式
  55. // color: '#000',
  56. // fontStyle: 'normal',
  57. // fontWeight: 100,
  58. // fontSize: 16 //主题文字字体大小,默认为18px
  59. // },
  60. },
  61. tooltip: {
  62. trigger: 'axis',
  63. axisPointer: {
  64. type: 'shadow'
  65. }
  66. },
  67. grid: {
  68. left: '3%',
  69. right: '4%',
  70. bottom: '3%',
  71. containLabel: true
  72. },
  73. xAxis: [
  74. {
  75. type: 'category',
  76. data: this.resultYData.name,
  77. axisTick: {
  78. alignWithLabel: true
  79. },
  80. axisLabel: {
  81. interval: 0,
  82. rotate: 20,
  83. }
  84. }
  85. ],
  86. legend: {
  87. top: '5%', // 控制 板块控制器的位置
  88. right: 'center',
  89. // icon: 'rect',//形状 类型包括 circle,rect,line,roundRect,triangle,diamond,pin,arrow,none
  90. // itemWidth: 10, // 设置宽度
  91. // itemHeight: 4, // 设置高度
  92. itemGap: 40, // 设置两个legend之间的间距
  93. },
  94. yAxis: [
  95. {
  96. type: 'log',
  97. name: this.dw,
  98. splitLine: {
  99. lineStyle: {
  100. type: 'dashed',
  101. },
  102. },
  103. axisLabel: {
  104. // 轴文字
  105. fontSize: 12,
  106. },
  107. },
  108. ],
  109. series: [
  110. {
  111. name: this.seriesName,
  112. type: 'bar',
  113. barWidth: '50%',
  114. label: {
  115. show: true,
  116. position: 'top',
  117. },
  118. data: this.resultYData.value,
  119. itemStyle: {
  120. normal: {
  121. barBorderRadius: [10, 10, 0, 0],
  122. color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
  123. {
  124. offset: 0,
  125. color: 'rgba(1,186,188,1)',
  126. },
  127. {
  128. offset: 1,
  129. color: 'rgba(150,214,104,.9)',
  130. },
  131. ]),
  132. }
  133. }
  134. },
  135. ]
  136. }
  137. // 使用刚指定的配置项和数据显示图表。
  138. var myChart = echarts.init(this.$refs.dom)
  139. myChart.on('click',(params)=>{
  140. _this.$emit('visible',{sjyt:params.data.name});
  141. })
  142. myChart.setOption(option)
  143. /*window.addEventListener("resize", myChart.resize);*/
  144. // })
  145. }
  146. },
  147. }
  148. </script>
  149. <style scoped>
  150. </style>