departmentChart.vue 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  1. <template>
  2. <!-- 部门统计图 外部 报表 订单统计 -->
  3. <div id="depChart" :style="{ width: '100%', height: '600px' }"></div>
  4. </template>
  5. <script>
  6. import * as echarts from 'echarts'
  7. // import { depChart } from '@api/reportForms/order-statistics.js'
  8. export default {
  9. name: 'CustomerChart', // 客户统计图
  10. data() {
  11. return {
  12. // newData: {
  13. // departmentArr: [],//部门 数组
  14. //realQuantityArr: [],//实际金额
  15. // localMoneyArr: []//本币金额
  16. // }
  17. }
  18. },
  19. mounted() {
  20. // this.getDepChartData()
  21. this.initEcharts()
  22. },
  23. methods: {
  24. // 1、先获取 chart 数据
  25. getDepChartData() {
  26. // depChart().then(res => {
  27. // if (res.success) {
  28. // if (res.result) {
  29. // res.result.forEach(item => {
  30. // this.departmentArr.push(item.departmentArr)
  31. // this.realQuantityArr.push(item.realQuantityArr)
  32. // this.localMoneyArr.push(item.localMoneyArr)
  33. // })
  34. // console.log('返回的数组', this.departmentArr, this.realQuantityArr, this.localMoneyArr)
  35. // }
  36. // }
  37. // //2、后图
  38. // this.$nextTick(() => {
  39. // this.initEcharts()
  40. // })
  41. // })
  42. },
  43. initEcharts() {
  44. const myChart = echarts.init(document.getElementById('depChart')) //dark ,深色主题
  45. // 配置
  46. const option = {
  47. title: {
  48. bpttom: '20',
  49. text: '部门统计表',
  50. textStyle: {
  51. fontSize: 18,
  52. color: '#5470c6'
  53. }
  54. },
  55. tooltip: {
  56. trigger: 'axis',
  57. axisPointer: {
  58. type: 'cross',
  59. crossStyle: {
  60. color: '#999'
  61. }
  62. },
  63. textStyle: {
  64. fontSize: 18
  65. }
  66. },
  67. legend: {
  68. // textStyle: {
  69. // fontSize: 16,
  70. // color: '#5470c6'
  71. // },
  72. data: ['实际数量', '本币金额']
  73. },
  74. grid: {
  75. show: true, //是否显示直角坐标系网格。[ default: false ]
  76. left: '6%', // 组件离容器左侧的距离。
  77. right: '6%',
  78. borderColor: 'none', //网格的边框颜色
  79. bottom: '20%' //
  80. },
  81. xAxis: {
  82. type: 'category',
  83. axisLabel: {
  84. interval: 0 //控制X轴刻度全部显示
  85. // rotate: 30 //倾斜角度
  86. },
  87. axisPointer: {
  88. type: 'shadow'
  89. },
  90. data: ['业务一部', '业务二部', '业务三部', '业务四部', '业务五部', '业务六部', '业务七部']
  91. // data: this.departmentArr
  92. },
  93. yAxis: [
  94. {
  95. type: 'value',
  96. name: '实际数量',
  97. min: 0,
  98. max: 10000000,
  99. interval: 1000000,
  100. axisLabel: {
  101. // formatter: '{value} ml'
  102. }
  103. },
  104. {
  105. type: 'value',
  106. name: '本币金额',
  107. min: 0,
  108. max: 10000000,
  109. interval: 5000000,
  110. axisLabel: {
  111. // formatter: '{value} °C'
  112. }
  113. }
  114. ],
  115. series: [
  116. {
  117. name: '实际数量',
  118. type: 'bar',
  119. // tooltip: {
  120. // valueFormatter: function(value) {
  121. // // return value + ' ml';
  122. // }
  123. // },
  124. itemStyle: {
  125. color: 'orange'
  126. // normal:{
  127. // 颜色: function ( params ) {
  128. // //注意,如果颜色太少,后面的颜色不会自动循环。最好再定义几个颜色
  129. // 变量colorList = [ '#c23531' ,'#2f4554' , '#61a0a8' , '#d48265' ,'#91c7ae' ,'#749f83' , '#ca8622' ]
  130. // 返回颜色列表[参数. 数据索引]
  131. // }
  132. // }
  133. },
  134. barWidth: '30%',
  135. data: [5635464, 4230466, 7498980, 6546765, 9222342, 1655143, 5055143]
  136. // data: this.dyeLossRateArr
  137. },
  138. {
  139. name: '本币金额',
  140. type: 'line',
  141. tooltip: {
  142. // valueFormatter: function(value) {
  143. // // return value + ' ml'
  144. // }
  145. },
  146. data: [7237455, 5158676, 7864656, 6744645, 9543645, 4446511, 6564992]
  147. }
  148. ]
  149. }
  150. // 渲染
  151. myChart.setOption(option)
  152. window.addEventListener('resize', () => {
  153. if (myChart) {
  154. myChart.resize()
  155. console.log('eee')
  156. }
  157. })
  158. }
  159. },
  160. watch: {
  161. // 3、监听数据变化
  162. newData: {
  163. deep: true,
  164. handler() {
  165. // 数据变化,执行
  166. const { departmentArr, realQuantityArr, localMoneyArr } = this.newData
  167. this.initEcharts(departmentArr, realQuantityArr, localMoneyArr)
  168. // console.log('333')
  169. }
  170. }
  171. }
  172. }
  173. </script>
  174. <style lang="less" scoped>
  175. @import '~@assets/less/common.less';
  176. @import '~@assets/less/overwriter.less';
  177. /deep/ .ant-table-thead > tr > th {
  178. text-align: center;
  179. // font-weight: 700;
  180. }
  181. /deep/ .ant-table-tbody {
  182. text-align: center;
  183. }
  184. // /deep/ th.replacecolor {
  185. // background-color: #ccc;
  186. // }
  187. /deep/ .ant-table.ant-table-bordered .ant-table-footer {
  188. border: none;
  189. padding: 0;
  190. }
  191. </style>