添加柱状图点击事件

This commit is contained in:
Cool 2024-05-31 20:38:23 +08:00
parent 0e736b3217
commit 4f2001c9d4
1 changed files with 133 additions and 373 deletions

View File

@ -25,6 +25,14 @@
<a-row :gutter="24"> <a-row :gutter="24">
<a-col :xl="24" :style="{ marginBottom: '24px' }"> <a-col :xl="24" :style="{ marginBottom: '24px' }">
<div class="container" > <div class="container" >
<div id="span" >
<div style="display: flex; justify-content: center; align-items: center">
<span style="font-size: 18px" >点击柱状图可查看该学院&nbsp </span>
<span style="font-size: 18px; color: red">各年级四级通过率</span>
</div>
<!-- <span style=" font-size: 18px;">&nbsp 变化</span> -->
</div>
<div id="map1" style="width: 100%; height: 600px"></div> <div id="map1" style="width: 100%; height: 600px"></div>
</div> </div>
</a-col> </a-col>
@ -60,6 +68,7 @@ export default {
collegetab2: [], collegetab2: [],
collegeMajorOptions: [], collegeMajorOptions: [],
collegeMajor: [], collegeMajor: [],
Url: { Url: {
getBatch: '/cet/getBatch', getBatch: '/cet/getBatch',
getEntrydate: '/cet/getEntrydate', getEntrydate: '/cet/getEntrydate',
@ -97,26 +106,6 @@ export default {
}; };
}, },
methods: { methods: {
onMajorChange(value) {
console.log(value, 'value');
let length = value.length;
//value,this.collegeMajorOptionsvaluethis.collegeMajorOptionschildren
for (let i = 0; i < value.length; i++) {
for (let j = 0; j < this.collegeMajorOptions.length; j++) {
if (value[i] == this.collegeMajorOptions[j].value) {
length += this.collegeMajorOptions[j].children.length;
length -= 1;
}
if (length > 5) {
message.error('最多选择五个专业');
//value
value.pop();
return;
}
}
}
console.log(length, 'length');
},
allQuery() { allQuery() {
this.tab1loading = true; this.tab1loading = true;
let college = ['全校']; let college = ['全校'];
@ -127,7 +116,6 @@ export default {
this.query(query, college, [this.oneentrydate]); this.query(query, college, [this.oneentrydate]);
}, },
async majorQuery() { async majorQuery() {
if (this.majorentrydate.length == 0) { if (this.majorentrydate.length == 0) {
message.error('请选择年级'); message.error('请选择年级');
return; return;
@ -157,44 +145,6 @@ export default {
}); });
} }
}, },
collegeQuery() {
if (this.collegeentrydate.length == 0) {
message.error('请选择年级');
return;
}
if (this.collegetab2.length == 0) {
message.error('请选择学院');
return;
}
this.tab2loading = true;
let query = 'tab2';
this.query(query, this.collegetab2, this.collegeentrydate);
},
test(value) {
console.log(this.collegeMajor);
console.log(value);
},
//
checkAll(e) {
this.college = ['全校'];
this.showGroup = !this.showGroup;
},
//
checkOne(e) {
console.log(e);
this.college = e;
this.showBox = true;
if (e.length == 0) {
this.showBox = false;
}
},
//
checkoneentrydate(e) {
console.log(e.target.value, 'e');
this.entrydate = [e.target.value];
},
// //
async getCollegeMajorData() { async getCollegeMajorData() {
@ -234,309 +184,6 @@ export default {
console.log(this.collegeOptions, 'collegeOptions'); console.log(this.collegeOptions, 'collegeOptions');
}); });
}, },
onMajorEntrydateChange(value) {
console.log(value, 'value');
if (value.length > 5) {
//valuethis.lastMajorEntrydate
for (let i = 0; i < value.length; i++) {
if (!this.lastMajorEntrydate.includes(value[i])) {
message.error('最多选择五个');
//value[i]
value.splice(i, 1);
return;
}
}
}
this.lastMajorEntrydate = value;
},
//
onCollegeChange(value) {
console.log(value, 'value');
if (value.length > 5) {
message.error('最多选择五个');
//lastCollegevaluelastCollege
for (let i = 0; i < value.length; i++) {
if (!this.lastCollege.includes(value[i])) {
value.splice(i, 1);
return;
}
}
return;
}
this.lastCollege = value;
},
//
onCollegeEntrydateChange(value) {
console.log(value, 'value');
if (value.length > 5) {
message.error('最多选择五个');
//lastCollegeEntrydatevaluelastCollegeEntrydate
for (let i = 0; i < value.length; i++) {
if (!this.lastCollegeEntrydate.includes(value[i])) {
value.splice(i, 1);
return;
}
}
return;
}
this.lastCollegeEntrydate = value;
},
//
onCollegeMajorChange(value) {
//valuethis.lastCollegeMajorvaluethis.lastCollegeMajor,this.majorOptionsthis.lastCollegeMajorvalue
for (let i = 0; i < value.length; i++) {
if (!this.lastCollegeMajor.map((item) => item[1]).includes(value[i])) {
if (this.majorLength == 5) {
message.error('最多选择五个');
//valuevalue[i]
value.splice(i, 1);
return;
}
this.lastCollegeMajor.push([this.collegeMajor, value[i]]);
this.majorLength++;
}
}
for (let i = 0; i < this.lastCollegeMajor.length; i++) {
if (!value.includes(this.lastCollegeMajor[i][1])) {
//this.majorOptions
if (this.majorOptions.find((item) => item.value == this.lastCollegeMajor[i][1])) {
this.lastCollegeMajor.splice(i, 1);
console.log('splice');
this.majorLength--;
}
}
}
console.log(value, 'value');
},
removeTag(index) {
if (this.majorCheckOn.includes(this.lastCollegeMajor[index][1])) {
let index1 = this.majorCheckOn.indexOf(this.lastCollegeMajor[index][1]);
this.majorCheckOn.splice(index1, 1);
}
this.lastCollegeMajor.splice(index, 1);
this.majorLength--;
},
//
onMajorCollegeChange(value) {
let val = value.target.value;
console.log(val, 'value');
console.log(this.collegeMajorOptions.find((item) => item.value == val).children, 'majorOptions');
this.majorOptions = this.collegeMajorOptions.find((item) => item.value == val).children;
//this.majorCheckOnthis.lastCollegeMajorthis.lastCollegeMajorthis.majorCheckOn,
// for (let i = 0; i < this.majorCheckOn.length; i++) {
// if (!this.lastCollegeMajor.includes(this.majorCheckOn[i])) {
// this.lastCollegeMajor.push(this.majorCheckOn[i]);
// }
// }
// for (let i = 0; i < this.lastCollegeMajor.length; i++) {
// if (!this.majorCheckOn.includes(this.lastCollegeMajor[i])) {
// this.lastCollegeMajor.splice(i, 1);
// console.log("splice")
// }
// }
// this.lastCollegeMajor = this.majorCheckOn;
console.log(this.lastCollegeMajor, 'lastCollegeMajor');
this.majorCheckOn = this.lastCollegeMajor.map((item) => item[1]);
console.log(this.majorCheckOn, 'majorCheckOn');
},
clearMajor() {
this.majorCheckOn = [];
this.lastCollegeMajor = [];
this.majorLength = 0;
},
clearCollege() {
this.collegetab2 = [];
this.collegeentrydate = [];
this.lastCollege = [];
this.lastCollegeEntrydate = [];
},
//tab2\3
drawChart(data, tab) {
let seriesData = [];
let xData = this.majorentrydate.sort((a, b) => a - b);
if (tab == 'tab2') {
xData = this.collegeentrydate.sort((a, b) => a - b);
}
let k = 0;
let legendData = [];
let colors = [
'#5370c5',
'#91CC75',
'#fac858',
'#ee6666',
'#73c0de',
'#FF6A6A',
'#FFA500',
'#EE2C2C',
'#90EE90',
'#008B8B',
'#FFC0CB',
'#FFDAB9',
'#FFDEAD',
'#FFE4B5',
'#FFE4C4',
'#FFE4E1',
'#FFEBCD',
'#FFEFD5',
'#FFFAF0',
'#FFFAFA',
'#FFFFE0',
'#FFFFF0',
'#FFFFFF',
'#F0F8FF',
'#FAEBD7',
'#FAF0E6',
'#FAFAD2',
'#F5FFFA',
'#F8F8FF',
'#F0FFF0',
'#F0FFFF',
'#F0E68C',
'#F0F8FF',
'#F0FFF0',
'#F0FFFF',
'#F4A460',
'#F5DEB3',
'#F5F5DC',
'#F5F5F5',
'#F5FFFA',
'#F8F8FF',
'#F9EBEA',
'#FAD7A0',
'#FAF0E6',
'#FAFAD2',
'#FAF0E6 ',
];
let isJK = false;
for (let i in data) {
console.log(i, 'i');
legendData.push(i);
let yData = [];
// legendData=[];
console.log(data[i], 'data[i]');
for (let j in data[i]) {
console.log(data[i][j].college, 'data[i][j].college111');
// if(data[i][j].college == ''){
yData.push(data[i][j].passRate);
// legendData.push(data[i][j].college);
}
console.log(yData, 'yData');
seriesData.push({
name: i,
type: 'bar',
//
barWidth: 25,
data: yData,
//
barGap: '30%',
//
itemStyle: {
normal: {
label: {
show: true, //
position: 'top', //
formatter: '{c}%',
textStyle: {
//
color: 'black',
fontSize: 13,
},
},
color: colors[k++],
},
},
});
}
console.log(legendData, 'legendData');
console.log(seriesData, 'dasaaseriresdata');
// debugger
let myChart = null;
console.log(tab, 'tab');
if (tab == 'tab2') {
myChart = document.getElementById('map2');
if (myChart) {
myChart = echarts.getInstanceByDom(myChart);
if (myChart) {
myChart.dispose();
}
}
myChart = echarts.init(document.getElementById('map2'));
} else if (tab == 'tab3') {
myChart = document.getElementById('map3');
if (myChart) {
myChart = echarts.getInstanceByDom(myChart);
if (myChart) {
myChart.dispose();
}
}
myChart = echarts.init(document.getElementById('map3'));
}
//
let option = {
title: {
text: '本批次学院四级通过率排名',
},
legend: {},
tooltip: {
trigger: 'axis',
axisPointer: {
type: 'shadow',
},
formatter: function (params) {
//tooltip,
let result = params[0].name + '级通过率<br>';
for (let i = 0; i < params.length; i++) {
result += params[i].marker + legendData[i] + ' : ' + params[i].value + '%' + '<br>';
}
return result;
},
},
toolbox: {
show: true,
feature: {
magicType: { show: true, type: ['line', 'bar'] },
restore: { show: true },
saveAsImage: { show: true },
},
},
grid: {
left: '3%',
right: '4%',
bottom: '3%',
containLabel: true,
},
xAxis: [
{
type: 'category',
data: xData,
axisLabel: {
interval: 0, //x
rotate: 0, //0
},
},
],
yAxis: [
{
type: 'value',
name: '通过率',
axisLabel: {
formatter: '{value} %',
},
},
],
series: seriesData,
};
// 使
console.log(option, 'option');
console.log(myChart, 'myChart');
setTimeout(() => {
myChart.setOption(option);
}, 1);
},
dataChart(data, tab) { dataChart(data, tab) {
let seriesData = []; let seriesData = [];
let xData = []; let xData = [];
@ -664,12 +311,8 @@ export default {
} }
} }
let myChart = null; let myChart = null;
if (tab == 'tab2') { if (tab == 'tab1') {
myChart = echarts.init(document.getElementById('map2'));
} else if (tab == 'tab1') {
myChart = echarts.init(document.getElementById('map1')); myChart = echarts.init(document.getElementById('map1'));
} else if (tab == 'tab3') {
myChart = echarts.init(document.getElementById('map3'));
} }
// //
// const college1 = this.college; // const college1 = this.college;
@ -792,9 +435,128 @@ export default {
}, },
]; ];
} }
myChart.setOption(option, true);
// 使 // 使
myChart.on('click', async (params) => {
let name = params.name;
//name
name = name.replace(/\n/g, '');
console.log(
this.collegeOptions.map((item) => item.value),
'collegeOptions'
);
console.log(name, 'params');
console.log(this.collegeOptions.map((item) => item.value).includes(name), 'bool');
if (params != null && params != undefined && params.name != '' && this.collegeOptions.map((item) => item.value).includes(name)) {
console.log(params, 'params');
let entrydate = this.entrydateOptions.map((item) => item.value);
let queryParams = {
college: [name],
entrydate: entrydate,
level: 'cet4',
};
let url = this.Url.getCollegeRate;
console.log(queryParams, 'queryParams');
let result = await defHttp.post({ url: url, data: queryParams });
myChart.setOption(option); console.log(myChart, 'mychart');
if (!result) {
return;
}
console.log(result.data, 'result');
result = result.data[name];
let collegeOption = {
title: {
text: name + '四级通过率',
},
xAxis: {
data: result.map((item) => item.entrydate),
},
//
tooltip: {
trigger: 'axis',
axisPointer: {
type: 'shadow',
},
formatter: function (params) {
//tooltip,
let result = params[0].name + '<br>';
for (let i = 0; i < params.length; i++) {
result += params[i].marker + name + ' : ' + params[i].value + '%' + '<br>';
}
return result;
},
},
series: {
type: 'line',
data: result.map((item) => item.passRate),
label: {
show: true, //
position: 'top', //
formatter: function (params) {
//
return params.value + '%';
},
//
},
universalTransition: {
// enabled: true,
// divideShape: 'clone',
},
},
yAxis: {},
animationDurationUpdate: 500,
graphic: [
{
type: 'rect',
left: 20,
top: 40,
z: 1, //
shape: {
width: 70, //
height: 35, //
},
style: {
fill: 'rgba(24, 144, 255)', //
},
},
{
type: 'text',
left: 38,
top: 50,
z: 2, //
style: {
text: '返 回',
fontSize: 15,
fill: 'white', //
},
onclick: function () {
myChart.setOption(option, true);
let spanElement = document.getElementById('span');
// span
spanElement.style.display = 'block';
},
},
],
};
console.log(collegeOption, 'collegeOption');
let spanElement = document.getElementById('span');
// span
spanElement.style.display = 'none';
myChart.setOption(collegeOption, true);
console.log(myChart, 'mychart');
// this.college = [params];
// this.query(tab, this.college, this.entrydate);
}
});
}, },
// //
async getBatch() { async getBatch() {
@ -846,8 +608,6 @@ export default {
this.$nextTick(() => { this.$nextTick(() => {
if (query == 'tab1') { if (query == 'tab1') {
this.dataChart(result.data, query); this.dataChart(result.data, query);
} else if (query == 'tab2') {
this.drawChart(result.data, query);
} }
}); });
} }
@ -865,7 +625,7 @@ export default {
<style lang="less" scoped> <style lang="less" scoped>
.container { .container {
display: flex; // display: flex;
background-color: #fff; background-color: #fff;
padding: 15px; padding: 15px;
border-radius: 4px; border-radius: 4px;