BarTdsjyt.vue 3.8 KB

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