BarTdsjyt.vue 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. <template>
  2. <div ref="dom" style="width:calc(100% - 0px);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. formatter:function(value){
  95. let str = ''
  96. let num = 3; //每行显示字数
  97. let valLength = value.length; //该项x轴字数
  98. let rowNum = Math.ceil(valLength / num); // 行数
  99. if(rowNum > 1) {
  100. for(let i = 0; i < rowNum; i++) {
  101. let temp = "";
  102. let start = i * num;
  103. let end = start + num;
  104. temp = value.substring(start, end) + "\n";
  105. str += temp;
  106. }
  107. return str;
  108. } else {
  109. return value;
  110. }
  111. }
  112. }
  113. }
  114. ],
  115. legend: {
  116. top: '5%', // 控制 板块控制器的位置
  117. right: 'center',
  118. // icon: 'rect',//形状 类型包括 circle,rect,line,roundRect,triangle,diamond,pin,arrow,none
  119. // itemWidth: 10, // 设置宽度
  120. // itemHeight: 4, // 设置高度
  121. itemGap: 40, // 设置两个legend之间的间距
  122. },
  123. yAxis: [
  124. {
  125. type: 'log',
  126. name: this.dw,
  127. splitLine: {
  128. lineStyle: {
  129. type: 'dashed',
  130. },
  131. },
  132. axisLabel: {
  133. // 轴文字
  134. fontSize: 12,
  135. },
  136. },
  137. ],
  138. series: [
  139. {
  140. name: this.seriesName,
  141. type: 'bar',
  142. barWidth: '50%',
  143. label: {
  144. show: true,
  145. position: 'top',
  146. },
  147. data: this.resultYData.value,
  148. itemStyle: {
  149. normal: {
  150. barBorderRadius: [10, 10, 0, 0],
  151. color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
  152. {
  153. offset: 0,
  154. color: 'rgba(1,186,188,1)',
  155. },
  156. {
  157. offset: 1,
  158. color: 'rgba(150,214,104,.9)',
  159. },
  160. ]),
  161. }
  162. }
  163. },
  164. ]
  165. }
  166. // 使用刚指定的配置项和数据显示图表。
  167. var myChart = echarts.init(this.$refs.dom)
  168. myChart.on('click', (params) => {
  169. for (const param of this.sjyt) {
  170. if (param.title == params.name){
  171. _this.$emit('visible', {sjyt: param.value});
  172. _this.$emit('visibleSz', {pzyt: param.value});
  173. }
  174. }
  175. })
  176. myChart.setOption(option);
  177. myChart.resize();
  178. }
  179. },
  180. }
  181. </script>
  182. <style scoped>
  183. </style>