mocNoChart.vue 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. <template>
  2. <div>
  3. <div id="mocNoChart" :style="{width:width,height:height}"></div>
  4. </div>
  5. </template>
  6. <script>
  7. import { mocNoData } from "@/api/process/moc";
  8. export default {
  9. props: {
  10. width: {
  11. type: String,
  12. default: '100%'
  13. },
  14. height: {
  15. type: String,
  16. default: '200px'
  17. },
  18. },
  19. data() {
  20. return {
  21. option: {
  22. /* 周围边距 */
  23. grid: {
  24. left: '3%',
  25. right: '3%',
  26. bottom: '1%',
  27. top: '15%',
  28. containLabel: true
  29. },
  30. /* 标识 */
  31. legend: {
  32. data: ['永久MOC', '临时MOC'],
  33. },
  34. toolbox: {
  35. show: true,
  36. feature: {
  37. mark: {show: true},
  38. magicType: {
  39. show: true,
  40. type: ['pie', 'funnel']
  41. },
  42. restore: {show: true},
  43. saveAsImage: {show: true}
  44. }
  45. },
  46. /* 坐标轴显示 */
  47. tooltip: {
  48. trigger: 'axis',
  49. axisPointer: { // 坐标轴指示器,坐标轴触发有效
  50. /*type: 'shadow' // 默认为直线,可选为:'line' | 'shadow'*/
  51. type: 'cross',
  52. label: {
  53. backgroundColor: '#a0a0a0'
  54. }
  55. }
  56. },
  57. xAxis: {
  58. data: [],
  59. },
  60. yAxis: {
  61. },
  62. series: [{
  63. name: '永久MOC',
  64. type: 'bar',
  65. // barWidth: '40%',
  66. stack: 'MOC',
  67. data: []
  68. },
  69. {
  70. name: '临时MOC',
  71. type: 'bar',
  72. // barWidth: '40%',
  73. stack: 'MOC',
  74. data: []
  75. },
  76. ]
  77. },
  78. // 查询参数
  79. queryParams: {},
  80. chart: null,
  81. chartData1 : [],
  82. chartData2 : [],
  83. }
  84. },
  85. mounted() {
  86. this.$nextTick(() => {
  87. mocNoData({timeliness: 1}).then(response => {
  88. this.chartData1 = response;
  89. mocNoData({timeliness: 2}).then(response => {
  90. this.chartData2 = response;
  91. let xData = [];
  92. let yData1 = [];
  93. let yData2 = [];
  94. for(let i = 0 ; i < this.chartData1.length ; i++) {
  95. xData.push(this.chartData1[i].dataName);
  96. }
  97. for(let i = 0 ; i < this.chartData2.length ; i++) {
  98. xData.push(this.chartData2[i].dataName);
  99. }
  100. xData = this.unique(xData);
  101. this.option.xAxis.data = xData;
  102. for(let i = 0 ; i < xData.length ; i++) {
  103. yData1[i] = 0;
  104. yData2[i] = 0;
  105. for(let j = 0 ; j < this.chartData1.length ; j++) {
  106. if (xData[i] == this.chartData1[j].dataName) {
  107. yData1[i] = this.chartData1[j].dataNum;
  108. }
  109. }
  110. for(let j = 0 ; j < this.chartData2.length ; j++) {
  111. if (xData[i] == this.chartData2[j].dataName) {
  112. yData2[i] = this.chartData2[j].dataNum;
  113. }
  114. }
  115. }
  116. this.option.series[0].data = yData1;
  117. this.option.series[1].data = yData2;
  118. this.initChart();
  119. });
  120. });
  121. })
  122. },
  123. methods: {
  124. // 数组去重
  125. unique(arr) {
  126. if (!Array.isArray(arr)) {
  127. console.log('type error!')
  128. return;
  129. }
  130. arr = arr.sort()
  131. var arrry= [arr[0]];
  132. for (var i = 1; i < arr.length; i++) {
  133. if (arr[i] !== arr[i-1]) {
  134. arrry.push(arr[i]);
  135. }
  136. }
  137. return arrry;
  138. },
  139. /** 获取当前年份 */
  140. getNowTime() {
  141. var now = new Date();
  142. },
  143. initChart() {
  144. // 基于准备好的dom,初始化echarts实例
  145. this.chart = this.echarts.init(document.getElementById('mocNoChart'))
  146. this.chart.setOption(this.option)
  147. }
  148. }
  149. }
  150. </script>