barCharto.vue 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283
  1. <template>
  2. <div :class="$style.statisticsPage" :style="{width:width,height:height}">
  3. <div v-show="show" :id="'staff'+id" :style="{height:'100%'}" />
  4. <div v-show="!show" :style="{height:'100%'}">
  5. <div style="height:8%;font-size:24px;font-weight: 600;"> {{ title }} </div>
  6. <div :class="$style.nullShow">暂无数据</div>
  7. </div>
  8. </div>
  9. </template>
  10. <script>
  11. import * as echarts from 'echarts'
  12. export default {
  13. components: {
  14. },
  15. props: {
  16. value: {
  17. type: Array
  18. },
  19. width: {
  20. type: String,
  21. default: '100%'
  22. },
  23. height: {
  24. type: String,
  25. default: '100%'
  26. },
  27. id: {
  28. type: Number,
  29. default: 0
  30. },
  31. click: {
  32. type: String,
  33. default: 'true'
  34. },
  35. colorw: {
  36. type: String,
  37. default: '#fff'
  38. },
  39. title: {
  40. type: String
  41. },
  42. data: {
  43. type: Array
  44. },
  45. lineTF: {
  46. type: Boolean,
  47. default: false
  48. },
  49. colorIndex: {
  50. type: Number,
  51. default: 0
  52. },
  53. stack: {
  54. type: Boolean,
  55. default: false
  56. },
  57. legendVal: {
  58. type: Boolean,
  59. default: true
  60. }
  61. },
  62. data () {
  63. return {
  64. correspondence: {
  65. numO: '1年以下',
  66. numOT: '1-3年',
  67. numTF: '3-5年',
  68. numF: '5年以上',
  69. // numAll: '设备总数',
  70. numP: '待处理',
  71. numC: '已完成',
  72. numJ: '计划数',
  73. numW: '完成数',
  74. assets: '金额(万元)'
  75. },
  76. correspondenceUn: {
  77. rate: '完成率'
  78. },
  79. correspondenceCondition: {
  80. // numAll: '设备总数',
  81. numLimit: '限用',
  82. numR: '使用',
  83. numScrap: '报废',
  84. numS: '停用'
  85. },
  86. dynamicMappingCondition: {
  87. '限用': '限用数',
  88. '使用': '使用数',
  89. '报废': '报废数',
  90. '停用': '停用数'
  91. },
  92. // color: ['rgb(78,203,115)', 'rgb(251,211,55)', 'rgb(16,142,233)']
  93. color: ['#5470c6', '#339933', '#FF0033', 'rgb(251,211,55)'],
  94. show: false
  95. }
  96. },
  97. watch: {
  98. value: {
  99. handler (newVal) {
  100. if (newVal.length > 0) {
  101. this.show = true
  102. setTimeout(() => {
  103. this.drawLine()
  104. }, 100)
  105. } else {
  106. this.show = false
  107. }
  108. },
  109. deep: true
  110. }
  111. },
  112. mounted () {
  113. // setTimeout(() => {
  114. // this.drawLine()
  115. // }, 100);
  116. },
  117. methods: {
  118. drawLine () {
  119. const that = this
  120. const xData = []
  121. for (const key in this.value[0]) {
  122. if (this.correspondenceCondition.hasOwnProperty(key) || this.correspondence.hasOwnProperty(key) || key === 'org') {
  123. xData.push(key)
  124. }
  125. }
  126. const serArr = []
  127. for (let i = 1; i < xData.length; i++) {
  128. const ser = {
  129. name: '',
  130. type: 'bar',
  131. barWidth: xData.length > 3 ? 30 : 20,
  132. color: ''
  133. }
  134. if (this.stack) {
  135. ser['stack'] = 'Ad'
  136. }
  137. ser.name = xData[i]
  138. ser.color = this.color[i - 1 + this.colorIndex]
  139. serArr.push(ser)
  140. }
  141. if (this.lineTF) {
  142. serArr.push({
  143. name: 'rate',
  144. type: 'line',
  145. // barWidth: xData.length>3?10:20,
  146. color: 'rgb(251,211,55)'
  147. })
  148. }
  149. const staff = echarts.init(document.getElementById('staff' + this.id))
  150. const option = {
  151. title: {
  152. text: this.title,
  153. left: 'left',
  154. textStyle: { fontSize: 24, color: this.colorw }
  155. },
  156. legend: {
  157. left: 'left',
  158. top: '40',
  159. show: this.legendVal,
  160. textStyle: {
  161. color: '#fff'
  162. },
  163. formatter: function (name) {
  164. return that.correspondence[name] || that.correspondenceUn[name] || that.dynamicMappingCondition[that.correspondenceCondition[name]]
  165. }
  166. },
  167. grid: { // 让图表占满容器
  168. top: '80px',
  169. left: '40px',
  170. right: '20px',
  171. bottom: '40px'
  172. },
  173. tooltip: {
  174. trigger: 'axis',
  175. axisPointer: {
  176. type: 'cross',
  177. crossStyle: {
  178. color: '#999'
  179. }
  180. },
  181. formatter: function (params) {
  182. let str = `${that.value[params[0].dataIndex].org}`
  183. params.forEach(item => {
  184. let nameNum = ''
  185. nameNum = that.correspondence[item.seriesName] || that.correspondenceUn[item.seriesName] || that.dynamicMappingCondition[that.correspondenceCondition[item.seriesName]]
  186. str += `<br /> ${item.marker} ${nameNum} ${item.data[item.seriesName]}`
  187. })
  188. return str
  189. }
  190. },
  191. dataset: {
  192. dimensions: xData,
  193. source: this.value
  194. },
  195. xAxis: {
  196. type: 'category',
  197. axisLabel: {
  198. color: '#fff',
  199. interval: 0,
  200. rotate: 20,
  201. margin: 15,
  202. formatter: function (params) {
  203. let str = ''
  204. const paramsLen = params.length
  205. const len = 5
  206. const rowNumber = Math.ceil(paramsLen / len)
  207. if (paramsLen > len) {
  208. for (let i = 0; i < rowNumber; i++) {
  209. let temp = ''
  210. const start = i * len
  211. const end = start + len
  212. if (i === rowNumber - 1) {
  213. temp = params.substring(start, paramsLen)
  214. } else {
  215. temp = params.substring(start, end) + '\n'
  216. }
  217. str += temp
  218. }
  219. } else {
  220. str = params
  221. }
  222. return str
  223. }
  224. }
  225. },
  226. yAxis: {
  227. axisLabel: {
  228. color: '#fff',
  229. min: 0,
  230. formatter: function (value) {
  231. const mid = (value + '').indexOf('.') === -1 ? value + '' : ''
  232. let str = ''
  233. const paramsLen = mid.length
  234. const len = 4
  235. const rowNumber = Math.ceil(paramsLen / len)
  236. if (paramsLen > len) {
  237. for (let i = 0; i < rowNumber; i++) {
  238. let temp = ''
  239. const start = i * len
  240. const end = start + len
  241. if (i === rowNumber - 1) {
  242. temp = mid.substring(start, paramsLen)
  243. } else {
  244. temp = mid.substring(start, end) + '\n'
  245. }
  246. str += temp
  247. }
  248. } else {
  249. str = mid
  250. }
  251. return str
  252. }
  253. }
  254. // interval: interval
  255. },
  256. series: serArr
  257. }
  258. option && staff.setOption(option)
  259. }
  260. }
  261. }
  262. </script>
  263. <style lang="scss" module>
  264. /* #zlmbPie:hover{
  265. transition: all 0.5s;
  266. transform:scale(1.03);
  267. } */
  268. .statisticsPage{
  269. box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
  270. padding: 1%;
  271. /* background-color: rgba(6, 30, 93, 0.5); */
  272. .nullShow{
  273. display: flex;
  274. align-items: center;
  275. justify-content: center;
  276. font-size: 18px;
  277. height: 92%;
  278. }
  279. }
  280. </style>