chart.vue 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. <template>
  2. <div>
  3. <!-- 当日工段投产良率 -->
  4. <Echart
  5. :options="options"
  6. id="bottom2Chart"
  7. height="410px"
  8. width="100%"
  9. ref="column-board"
  10. ></Echart>
  11. </div>
  12. </template>
  13. <script>
  14. import Echart from '@/common/echart'
  15. //import { formatDate } from '../../../../utils/index.js'
  16. export default {
  17. data () {
  18. return {
  19. timing :null,
  20. options:{
  21. tooltip: {
  22. trigger: 'axis',
  23. axisPointer: {
  24. type: 'shadow'
  25. }
  26. },
  27. legend: {
  28. textStyle: {
  29. fontSize: 18
  30. },
  31. itemWidth: 29,
  32. itemHeight: 19
  33. },
  34. grid: {
  35. left: '3%',
  36. right: '4%',
  37. bottom: '3%',
  38. containLabel: true
  39. },
  40. xAxis: [
  41. {
  42. type: 'category',
  43. data:[],
  44. axisLabel: {
  45. fontSize: 16
  46. }
  47. }
  48. ],
  49. yAxis: [
  50. {
  51. type: 'value',
  52. axisLabel: {
  53. fontSize: 16
  54. }
  55. },
  56. {
  57. type: 'value',
  58. min: 0,
  59. max: 100,
  60. interval: 20,
  61. axisLabel: {
  62. formatter: '{value}%',
  63. fontSize: 16
  64. }
  65. }
  66. ],
  67. series: [
  68. {
  69. name: '已备料',
  70. type: 'bar',
  71. barWidth: 20,
  72. stack: 'Ad',
  73. emphasis: {
  74. focus: 'series'
  75. },
  76. data:[],
  77. itemStyle: {
  78. color: '#9FE6B8' //fac858
  79. },
  80. },
  81. {
  82. name: '未备料',
  83. type: 'bar',
  84. stack: 'Ad',
  85. barWidth: 10,
  86. data:[],
  87. emphasis: {
  88. focus: 'series'
  89. },
  90. itemStyle: {
  91. color: '#FFE900' //fac858
  92. },
  93. },
  94. {
  95. name: '备料比例%',
  96. type: 'line',
  97. data:[],
  98. yAxisIndex: 1,
  99. tooltip: {
  100. valueFormatter: function (value) {
  101. return value + '%';
  102. }
  103. },
  104. itemStyle: {
  105. normal: {
  106. barBorderRadius: 5,
  107. color: new this.$echarts.graphic.LinearGradient(0, 0, 0, 1, [
  108. { offset: 0, color: "rgba(0,161,26,0.8)" },
  109. { offset: 0.2, color: "rgba(0,161,26,0.5)" },
  110. { offset: 1, color: "rgba(0,161,26,0.2)" }
  111. ])
  112. }
  113. },
  114. emphasis: {
  115. focus: 'series'
  116. }
  117. }
  118. ]
  119. },
  120. };
  121. },
  122. components: {
  123. Echart, //子组件
  124. },
  125. props: {
  126. cdata: {
  127. type: Object,
  128. default: () => ({})
  129. },
  130. },
  131. mounted() {
  132. this.refreshdata();
  133. },
  134. beforeDestroy () {
  135. clearInterval(this.timing);
  136. this.chart.dispose()
  137. this.chart.clear()
  138. this.chart=null
  139. },
  140. methods: {
  141. refreshdata() {
  142. this.getdata();
  143. this.timing = setInterval(() => {
  144. this.getdata(); //获取-数据
  145. }, 10000);
  146. },
  147. async getdata() {
  148. this.options.xAxis[0].data = [];
  149. this.options.series[0].data = [];
  150. this.options.series[1].data =[];
  151. this.options.series[2].data = [];
  152. var caller = 'KB!WHMAKEPREPAREPG';
  153. await this.$http.get("kanban/datalist.action?caller="+caller+"&_noc=1&page=1&pageSize=100&condition=1=1")
  154. .then((result)=>{
  155. let dataList = JSON.parse(result.data.data);
  156. let xAxis0 = new Array();
  157. let series0 = new Array();
  158. let series1 = new Array();
  159. let series2 = new Array();
  160. for (let index = 0; index < dataList.length; index++) {
  161. const element = dataList[index];
  162. xAxis0.push(element.v_whname);
  163. /*if(index%2 == 0) {
  164. xAxis0.push(element.v_whname);
  165. }else{
  166. xAxis0.push('\n'+element.v_whname);
  167. }*/
  168. //已备料
  169. series0.push(element.v_haveqty);
  170. //未备料
  171. series1.push(element.v_unqty);
  172. //备料率
  173. series2.push(element.v_rate);
  174. }
  175. this.options.xAxis[0].data = xAxis0;
  176. this.options.series[0].data = series0;
  177. this.options.series[1].data = series1;
  178. this.options.series[2].data = series2;
  179. },(result)=>{
  180. console.error(result)
  181. }
  182. );
  183. }
  184. }
  185. }
  186. </script>