someoneLossChart.vue 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. <template>
  2. <!-- 染损报表 指定供应商-->
  3. <div id="someoneLossChart" :style="{ width: '100%', height: '600px' }"></div>
  4. </template>
  5. <script>
  6. import * as echarts from 'echarts' //必须有
  7. import { someoneLoss } from '@api/reportForms/dye-loss-table.js'
  8. export default {
  9. name: 'SomeoneLossChart', // 指定供应商染损分析图
  10. data() {
  11. return {
  12. venName: '',
  13. colorArr: [],
  14. cinvNameArr: [],
  15. cinvNameColorArr: [],
  16. // newData: {
  17. // cvenNameArr: [],
  18. dyeLossRateArr: []
  19. // }
  20. }
  21. },
  22. mounted() {
  23. this.getSomeoneLossData()
  24. },
  25. methods: {
  26. // 1、先获取 chart 数据
  27. getSomeoneLossData() {
  28. someoneLoss({ venName: this.venName }).then(res => {
  29. if (res.success) {
  30. // console.log('this.venName', this.venName)
  31. // console.log('指定供应商返回数据', res.result)
  32. res.result.forEach(item => {
  33. this.cinvNameColorArr.push(item.cinvNameColor)
  34. this.dyeLossRateArr.push(item.dyeLossRate)
  35. })
  36. //截取指定下标数据
  37. this.cinvNameColorArr = this.cinvNameColorArr.slice(0, 10)
  38. this.dyeLossRateArr = this.dyeLossRateArr.slice(0, 10)
  39. console.log('物料+颜色chart数组', this.cinvNameColorArr)
  40. console.log('染损chart数组', this.dyeLossRateArr)
  41. }
  42. //2、执行chart
  43. this.$nextTick(() => {
  44. this.initEcharts()
  45. // console.log('111')
  46. })
  47. })
  48. },
  49. initEcharts() {
  50. const myChart = echarts.init(document.getElementById('someoneLossChart')) //dark ,深色主题
  51. // 配置
  52. const option = {
  53. title: {
  54. text: '指定供应商物料染损统计图',
  55. textStyle: {
  56. fontSize: 18,
  57. color: '#5470c6'
  58. }
  59. },
  60. tooltip: {
  61. textStyle: {
  62. fontSize: 18
  63. // color: '#5470c6'
  64. }
  65. },
  66. legend: {
  67. textStyle: {
  68. fontSize: 16,
  69. color: '#5470c6'
  70. },
  71. data: [
  72. {
  73. name: '染损(%)',
  74. icon: 'circle' // 图例的图标样式
  75. }
  76. ]
  77. },
  78. grid: {
  79. show: true, //是否显示直角坐标系网格。[ default: false ]
  80. left: '8%', // 组件离容器左侧的距离。
  81. right: '10px',
  82. borderColor: 'none', //网格的边框颜色
  83. bottom: '40%' //
  84. },
  85. xAxis: {
  86. type: 'category',
  87. axisLabel: {
  88. interval: 0, //控制X轴刻度全部显示
  89. rotate: 40 //倾斜角度
  90. },
  91. splitArea: {
  92. show: true,
  93. areaStyle: {
  94. color: ['rgba(84, 112, 198,0.04)', 'rgba(176, 177, 183,0.05)']
  95. }
  96. },
  97. data: this.cinvNameColorArr
  98. },
  99. yAxis: {
  100. type: 'value',
  101. name: '(%)'
  102. },
  103. series: [
  104. {
  105. name: '染损(%)',
  106. type: 'line',
  107. // 折现部门渐变色
  108. areaStyle: {
  109. normal: {
  110. color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
  111. { offset: 0, color: 'blue' },
  112. { offset: 0.5, color: 'rgba(148,235,113,0.3)' },
  113. { offset: 1, color: 'rgba(148,235,113,0.1)' }
  114. ])
  115. }
  116. },
  117. smooth: true,
  118. data: this.dyeLossRateArr
  119. }
  120. ]
  121. }
  122. // 渲染
  123. myChart.setOption(option)
  124. //resize方法实现自动缩放
  125. window.addEventListener('resize', this.chart.resize)
  126. }
  127. },
  128. watch: {
  129. // 3、监听数据变化
  130. newData: {
  131. deep: true,
  132. handler() {
  133. // 数据变化,执行
  134. const { cvenNameArr, dyeLossRateArr } = this.newData
  135. this.initEcharts(cvenNameArr, dyeLossRateArr)
  136. console.log('333')
  137. }
  138. }
  139. }
  140. }
  141. </script>
  142. <style lang="less" scoped>
  143. @import '~@assets/less/common.less';
  144. @import '~@assets/less/overwriter.less';
  145. /deep/ .ant-table-thead > tr > th {
  146. text-align: center;
  147. // font-weight: 700;
  148. }
  149. /deep/ .ant-table-tbody {
  150. text-align: center;
  151. }
  152. // /deep/ th.replacecolor {
  153. // background-color: #ccc;
  154. // }
  155. /deep/ .ant-table-footer .ant-table.body {
  156. // overflow: hidden !important;
  157. }
  158. /deep/ .ant-table.ant-table-bordered .ant-table-footer {
  159. border: none;
  160. padding: 0;
  161. }
  162. #myChart {
  163. h6 {
  164. font-size: 16px;
  165. font-weight: 700;
  166. }
  167. }
  168. </style>