diff --git a/src/views/statistics/hunliao.vue b/src/views/statistics/hunliao.vue index 07c7a730..ce2e7be9 100644 --- a/src/views/statistics/hunliao.vue +++ b/src/views/statistics/hunliao.vue @@ -105,6 +105,9 @@ export default { tooltip: { trigger: 'axis' }, + legend: { + top: 30 + }, xAxis: { type: 'category', data: [] @@ -112,7 +115,6 @@ export default { yAxis: { type: 'value' }, - lenged: [], series: [{ data: [0, 0, 0, 0, 0, 0, 0], stack: 'Ad', @@ -146,13 +148,11 @@ export default { that.start_date = year + '-' + month + '-01'; that.end_date = year + '-' + month + '-' + days; that.queryDate = year + '-' + month; - let duration = that.endWeekNum - that.firstWeekNum + 1; - for (let i = 1; i <= duration; i++) { + for (let i = that.firstWeekNum; i <= that.endWeekNum; i++) { that.xAxisOrigin.push('第' + i + '周'); } that.xAxisData = that.xAxisOrigin; let height = document.getElementById('mainDom').clientHeight; - console.log('height',height); height= height-60; that.tableHeight = height; document.getElementById('bachart1').style.height = height + 'px'; @@ -175,7 +175,6 @@ export default { }, 500) }, queryTypeChange(value) { - console.log(value) this.queryDate = ''; }, getWeekOfYear(a,b,c) { @@ -197,19 +196,18 @@ export default { query: { start_date: that.start_date, end_date: that.end_date, mgroup_name: "混料", is_count_utask: -1 }, }; let option = deepCopy(that.basicOption); - option.xAxis.data = that.xAxisData; option.title.text = '混料统计'; + let dateLabels = that.xAxisData; let exec = that.queryType == '月' ? 'lineWeek' : 'lineMonth'; that.$API.bi.dataset.exec.req(exec, obj).then((res) => { let dataList = res.data2.ds0 ? res.data2.ds0 : []; that.dataList = dataList; if (dataList.length > 0) { option.series = []; - let seriesData = [], nameList = []; + let nameList = []; dataList.forEach(ite => { if (nameList.indexOf(ite.物料名) > -1) { } else { nameList.push(ite.物料名); - seriesData.push([0,0,0,0,0,0,0,0,0,0,0,0]) let obj = {}; obj.text = ite.物料名; obj.value = ite.物料名; @@ -230,11 +228,15 @@ export default { that.specsFilters.push(obj3); } }) + let seriesData = []; + for (let i = 0; i < dateLabels.length; i++) { + seriesData.push(new Array(nameList.length).fill(0)); + } dataList.forEach(item => { let indexX = 0, indexY = 0; if (that.queryType == '月') { - indexX = nameList.indexOf(item.物料名); - indexY = item.周 - that.firstWeekNum; + indexX = item.周 - that.firstWeekNum; + indexY = nameList.indexOf(item.物料名); if(dateList.indexOf(item.周)>-1){}else{ dateList.push(item.周); let obj = {}; @@ -244,15 +246,17 @@ export default { } } else { that.dateFilters = [1,2,3,4,5,6,7,8,9,10,11,12]; - indexX = nameList.indexOf(item.物料名); - indexY = item.月 - 1; + indexX = item.月 - 1; + indexY = nameList.indexOf(item.物料名); + } + if (indexX >= 0 && indexX < seriesData.length && indexY >= 0) { + seriesData[indexX][indexY] += item.合格数; } - seriesData[indexX][indexY] += item.合格数; }); + option.xAxis.data = nameList; for (let n = 0; n < seriesData.length; n++) { let obj = {}; - obj.name = nameList[n]; - obj.stack = 'Ad'; + obj.name = dateLabels[n]; obj.type = 'bar'; obj.barWidth = '15px'; obj.data = seriesData[n]; @@ -260,6 +264,7 @@ export default { } that.setChart("bachart1", option); } else { + option.xAxis.data = []; that.setChart("bachart1", option); } });