175 lines
3.2 KiB
Vue
175 lines
3.2 KiB
Vue
<template>
|
|
<div :id="id" :style="{height: size.height+'px', width: size.width+'px'}" />
|
|
</template>
|
|
|
|
<script>
|
|
import echarts from 'echarts';
|
|
import { getLessonList, getLessonTimeChart } from '@/api/statistics';
|
|
|
|
export default {
|
|
props: {
|
|
id: {
|
|
type: String,
|
|
default: 'chart'
|
|
},
|
|
size: {
|
|
type: Object,
|
|
required: true
|
|
}
|
|
},
|
|
data() {
|
|
return {
|
|
option: {
|
|
backgroundColor: '#F0F2F5',
|
|
title: {
|
|
top: 20,
|
|
text: '课程统计',
|
|
textStyle: {
|
|
fontWeight: 'normal',
|
|
fontSize: 18,
|
|
color: '#000000'
|
|
},
|
|
left: 'center'
|
|
},
|
|
tooltip: {
|
|
trigger: 'axis',
|
|
axisPointer: {
|
|
type: 'shadow',
|
|
lineStyle: {
|
|
color: '#57617B'
|
|
}
|
|
}
|
|
},
|
|
legend: {
|
|
top: 20,
|
|
orient: 'vertical',
|
|
icon: 'rect',
|
|
itemWidth: 14,
|
|
itemHeight: 5,
|
|
itemGap: 13,
|
|
data: [],
|
|
right: '4%',
|
|
textStyle: {
|
|
fontSize: 12,
|
|
color: '#C0C0C0'
|
|
}
|
|
},
|
|
grid: {
|
|
top: 100,
|
|
left: '2%',
|
|
right: '2%',
|
|
bottom: '2%',
|
|
containLabel: true
|
|
},
|
|
xAxis: [{
|
|
type: 'category',
|
|
boundaryGap: true,
|
|
axisLine: {
|
|
lineStyle: {
|
|
color: '#57617B'
|
|
}
|
|
},
|
|
data: []
|
|
}],
|
|
yAxis: [{
|
|
type: 'value',
|
|
name: '(s)',
|
|
axisTick: {
|
|
show: false
|
|
},
|
|
axisLine: {
|
|
lineStyle: {
|
|
color: '#57617B'
|
|
}
|
|
},
|
|
axisLabel: {
|
|
margin: 10,
|
|
textStyle: {
|
|
fontSize: 14
|
|
}
|
|
},
|
|
splitLine: {
|
|
lineStyle: {
|
|
color: '#57617B'
|
|
}
|
|
}
|
|
}],
|
|
series: []
|
|
},
|
|
chart: null
|
|
};
|
|
},
|
|
watch: {
|
|
size() {
|
|
return this.chart.resize({...this.size, silent: false});
|
|
}
|
|
},
|
|
async created() {
|
|
await this.loadLessonData();
|
|
},
|
|
mounted() {
|
|
this.initChart();
|
|
},
|
|
beforeDestroy() {
|
|
if (!this.chart) {
|
|
return;
|
|
}
|
|
this.chart.dispose();
|
|
this.chart = null;
|
|
},
|
|
methods: {
|
|
initChart() {
|
|
this.chart = echarts.init(document.getElementById(this.id));
|
|
this.chart.setOption(this.option);
|
|
},
|
|
async loadLessonData() {
|
|
const data = [];
|
|
const resp = await getLessonList();
|
|
if (resp) {
|
|
const info = resp.data || [];
|
|
for (var i = 0; i < info.length; i++) {
|
|
const item = { ...info[i], data: []};
|
|
const rest = await getLessonTimeChart({id: info[i].statsProjectId});
|
|
if (rest) {
|
|
item.data = rest.data || [];
|
|
}
|
|
data.push(item);
|
|
}
|
|
}
|
|
|
|
this.option.series = [];
|
|
this.option.legend.data = [];
|
|
this.option.xAxis[0].data = ['控制权实训', ' 信号机实训', ' 道岔实训', '区段实训', '站台实训'];
|
|
data.forEach(elem => {
|
|
this.option.legend.data.push(elem.statsProjectName);
|
|
this.option.series.push({
|
|
name: elem.statsProjectName,
|
|
type: 'bar',
|
|
smooth: true,
|
|
symbol: 'circle',
|
|
symbolSize: 5,
|
|
showSymbol: false,
|
|
lineStyle: {
|
|
normal: {
|
|
width: 1
|
|
}
|
|
},
|
|
data: [0, 0, 0, 0, 0]
|
|
});
|
|
});
|
|
|
|
data.forEach((elem, i) => {
|
|
elem.data.forEach(item => {
|
|
const index = this.option.xAxis[0].data.findIndex(name => { return name == item.statsProjectName; });
|
|
if (index >= 0) {
|
|
this.option.series[i].data[index] = item.duration;
|
|
}
|
|
});
|
|
});
|
|
|
|
this.chart.setOption(this.option);
|
|
}
|
|
}
|
|
};
|
|
</script>
|