【前端】智能库房综合管理系统前端项目
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

279 lines
6.8 KiB

3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
  1. <template>
  2. <div id="main1" :style="{height:height,width:width}" />
  3. </template>
  4. <script>
  5. import echarts from 'echarts'
  6. import resize from '@/views/dashboard/mixins/resize'
  7. export default {
  8. name: 'BarEcharts',
  9. mixins: [resize],
  10. props: {
  11. storageData: {
  12. type: Object,
  13. require: true,
  14. default: function() {
  15. return {}
  16. }
  17. },
  18. width: {
  19. type: String,
  20. default: '100%'
  21. },
  22. height: {
  23. type: String,
  24. default: '100%'
  25. }
  26. },
  27. data() {
  28. return {
  29. chart: null
  30. }
  31. },
  32. watch: {
  33. 'storageData': {
  34. handler(val) {
  35. setTimeout(() => {
  36. this.drawChart()
  37. }, 100)
  38. },
  39. immediate: true,
  40. deep: true
  41. }
  42. },
  43. mounted() {
  44. this.drawChart()
  45. },
  46. methods: {
  47. drawChart() {
  48. const app = {}
  49. const chartDom = document.getElementById('main1')
  50. this.chart = echarts.init(chartDom)
  51. let option = null
  52. const posList = [
  53. 'left',
  54. 'right',
  55. 'top',
  56. 'bottom',
  57. 'inside',
  58. 'insideTop',
  59. 'insideLeft',
  60. 'insideRight',
  61. 'insideBottom',
  62. 'insideTopLeft',
  63. 'insideTopRight',
  64. 'insideBottomLeft',
  65. 'insideBottomRight'
  66. ]
  67. app.configParameters = {
  68. rotate: {
  69. min: -90,
  70. max: 90
  71. },
  72. align: {
  73. options: {
  74. left: 'left',
  75. center: 'center',
  76. right: 'right'
  77. }
  78. },
  79. verticalAlign: {
  80. options: {
  81. top: 'top',
  82. middle: 'middle',
  83. bottom: 'bottom'
  84. }
  85. },
  86. position: {
  87. options: posList.reduce(function(map, pos) {
  88. map[pos] = pos
  89. return map
  90. }, {})
  91. },
  92. distance: {
  93. min: 0,
  94. max: 100
  95. }
  96. }
  97. app.config = {
  98. rotate: 90,
  99. align: 'left',
  100. verticalAlign: 'middle',
  101. position: 'insideBottom',
  102. distance: 15,
  103. onChange: function() {
  104. const labelOption = {
  105. rotate: app.config.rotate,
  106. align: app.config.align,
  107. verticalAlign: app.config.verticalAlign,
  108. position: app.config.position,
  109. distance: app.config.distance
  110. }
  111. this.chart.setOption({
  112. series: [
  113. {
  114. label: labelOption
  115. },
  116. {
  117. label: labelOption
  118. }
  119. ]
  120. })
  121. }
  122. }
  123. const labelOption = {
  124. show: false,
  125. position: app.config.position,
  126. distance: app.config.distance,
  127. align: app.config.align,
  128. verticalAlign: app.config.verticalAlign,
  129. rotate: app.config.rotate,
  130. formatter: '{c} {name|{a}}',
  131. fontSize: 16,
  132. rich: {
  133. name: {}
  134. }
  135. }
  136. option = {
  137. tooltip: {
  138. trigger: 'axis',
  139. axisPointer: {
  140. type: 'shadow'
  141. },
  142. formatter: function(params) {
  143. var res = "<div style='width:100%;height:24px;margin-bottom:5px;padding:0 12px;line-height:24px;'><p>" + echarts.format.formatTime('yyyy年M月', new Date(params[0].name)) + ' </p></div>'
  144. for (var i = 0; i < params.length; i++) {
  145. res += `<div style="color: #fff;font-size: 14px; padding:0 12px;line-height: 24px">
  146. <span style="display:inline-block;margin-right:5px;border-radius:2px;width:10px;height:10px;background:${[params[i].color]};"></span>
  147. ${params[i].seriesName}
  148. ${params[i].data}
  149. </div>`
  150. }
  151. return res
  152. }
  153. },
  154. legend: { // 图例
  155. data: ['出库', '入库'],
  156. right: 20,
  157. top: 10,
  158. icon: 'circle',
  159. textStyle: {
  160. color: '#fff'
  161. }
  162. },
  163. grid: {
  164. left: '3%',
  165. right: '3%',
  166. bottom: '8%',
  167. top: '17%',
  168. containLabel: true
  169. },
  170. xAxis: [{
  171. type: 'category',
  172. axisTick: { show: false },
  173. data: this.storageData.storageMonths,
  174. axisLine: {// 轴线的颜色以及宽度
  175. lineStyle: {
  176. color: '#113D72'
  177. }
  178. },
  179. axisLabel: {// x轴文字的配置
  180. show: true,
  181. textStyle: {
  182. color: '#fff'
  183. },
  184. formatter: function(value) {
  185. return echarts.format.formatTime('M月', new Date(value))
  186. }
  187. },
  188. splitLine: {// 分割线配置
  189. lineStyle: {
  190. color: '#113D72',
  191. type: 'dashed'
  192. }
  193. }
  194. }],
  195. yAxis: [{
  196. min: 0,
  197. max: 900,
  198. splitNumber: 3,
  199. type: 'value',
  200. axisLine: {// 轴线的颜色以及宽度
  201. show: false
  202. },
  203. axisLabel: {// 轴文字的配置
  204. show: true,
  205. textStyle: {
  206. color: '#fff'
  207. }
  208. },
  209. axisTick: { // 刻度线隐藏
  210. show: false
  211. },
  212. splitLine: {// 分割线配置
  213. lineStyle: {
  214. color: '#113D72',
  215. type: 'dashed'
  216. }
  217. }
  218. }],
  219. series: [
  220. {
  221. name: '出库',
  222. type: 'bar',
  223. barWidth: 10, // 柱图宽度
  224. barGap: '30%',
  225. label: labelOption,
  226. emphasis: {
  227. focus: 'series'
  228. },
  229. data: this.storageData.outStorageData,
  230. color: new echarts.graphic.LinearGradient(0, 1, 0, 0, [
  231. {
  232. offset: 0,
  233. color: '#6E48E6'
  234. },
  235. {
  236. offset: 1,
  237. color: '#3AA6FA '
  238. }
  239. ])
  240. },
  241. {
  242. name: '入库',
  243. type: 'bar',
  244. barWidth: 10, // 柱图宽度
  245. label: labelOption,
  246. emphasis: {
  247. focus: 'series'
  248. },
  249. data: this.storageData.inStorageData,
  250. color: new echarts.graphic.LinearGradient(0, 1, 0, 0, [
  251. {
  252. offset: 0,
  253. color: '#9DDD92'
  254. },
  255. {
  256. offset: 1,
  257. color: '#10BFAA'
  258. }
  259. ])
  260. }
  261. ]
  262. }
  263. option && this.chart.setOption(option)
  264. }
  265. }
  266. }
  267. </script>
  268. <style lang="scss" scoped>
  269. </style>