修改四级成绩分析页面 饼图改为柱状图

This commit is contained in:
Qi 2025-04-10 20:27:41 +08:00
parent c8405d3d11
commit 8670a0e655
1 changed files with 209 additions and 88 deletions

View File

@ -177,8 +177,25 @@
// //
console.log(result, 'res'); console.log(result, 'res');
const resdata = []; const resdata = [];
resdata.push({ value: result.rateByBatch.rate, name: '400-425人数占比' }); //
resdata.push({ value: 100 - result.rateByBatch.rate, name: '其他分数占比' }); for (const [range, rate] of Object.entries(result.rateByBatch)) {
//
resdata.push({
value: parseFloat(rate), //
name: `${range}分人数占比`,
});
}
//
resdata.sort((a, b) => {
const aMin = parseInt(a.name.split('-')[0]); //
const bMin = parseInt(b.name.split('-')[0]); //
return aMin - bMin; //
});
console.log(resdata, 'resdata');
//
resdata[0].name = '400分以下人数占比';
//
resdata[4].name = '475分以上人数占比';
const piedata = []; const piedata = [];
piedata.push({ value: result.scoreByBatch.read, name: '阅读' }); piedata.push({ value: result.scoreByBatch.read, name: '阅读' });
piedata.push({ value: result.scoreByBatch.listen, name: '听力' }); piedata.push({ value: result.scoreByBatch.listen, name: '听力' });
@ -312,18 +329,80 @@
drawResChart(piedata) { drawResChart(piedata) {
console.log(this.passRatePie); console.log(this.passRatePie);
console.log('piedata', piedata); console.log('piedata', piedata);
let xData = piedata.map((item) => item.name);
let Data = piedata.map((item) => item.value);
console.log('xData', xData);
console.log('Data', Data);
let myChart = echarts.init(document.getElementById('resChart')); let myChart = echarts.init(document.getElementById('resChart'));
let option = { //let option = {
tooltip: { // tooltip: {
trigger: 'item', // trigger: 'item',
confine: false, // confine: false,
avoidLabelOverlap: true, // avoidLabelOverlap: true,
// // //
itemStyle: { // itemStyle: {
fontSize: 100, // fontSize: 100,
}, // },
}, // },
// title: {
// text: '',
// left: 'left',
// top: '0%',
// textStyle: {
// fontSize: 16,
// },
// },
// legend: {
// top: 'center',
// right: '0%',
// orient: 'vertical',
// },
// color: ['#b3cde0', '#6497b1', '#005b96', '#03396c', '#e5e5e5'],
// series: [
// //
// {
// name: '',
// type: 'pie',
// center: ['30%', '50%'],
// radius: ['35%', '70%'],
// itemStyle: {
// borderRadius: 10,
// borderColor: '#fff',
// borderWidth: 2,
// },
// label: {
// show: true,
// fontSize: 14,
// overflow: 'truncate',
// minMargin: -1,
// },
// emphasis: {
// itemStyle: {
// shadowBlur: 10,
// shadowOffsetX: 0,
// shadowColor: 'rgba(0, 0, 0, 0.5)',
// },
// label: {
// show: true,
// fontSize: 15,
// fontWeight: 'bold',
// },
// },
// data: piedata,
// },
// ],
//};
let option = {
grid: {
left: '10%', //
right: '10%', //
bottom: '30%', // X
},
tooltip: {
trigger: 'axis',
},
title: { title: {
text: '四级分数占比', text: '四级分数占比',
left: 'left', left: 'left',
@ -332,44 +411,37 @@
fontSize: 16, fontSize: 16,
}, },
}, },
legend: { xAxis: {
top: 'center', type: 'category',
right: '0%', data: xData,
orient: 'vertical', axisLabel: {
interval: 0, //
//rotate: 10, // 45
margin: 15, // 线
formatter: function (value) {
// ''
return value.replace(/分/g, '分\n');
},
},
axisLine: {
show: true,
},
boundaryGap: true, //
},
yAxis: {
type: 'value',
}, },
color: ['#b3cde0', '#6497b1', '#005b96', '#03396c', '#e5e5e5'],
series: [ series: [
//
{ {
name: '四级通过率', data: Data,
type: 'pie', type: 'bar',
center: ['30%', '50%'],
radius: ['35%', '70%'],
itemStyle: {
borderRadius: 10,
borderColor: '#fff',
borderWidth: 2,
},
label: { label: {
show: true, show: true, //
fontSize: 14, position: 'top', //
overflow: 'truncate', formatter: '{c}%', // 使 {c}
minMargin: -1, fontSize: 12, //
color: '#000', //
}, },
emphasis: {
itemStyle: {
shadowBlur: 10,
shadowOffsetX: 0,
shadowColor: 'rgba(0, 0, 0, 0.5)',
},
label: {
show: true,
fontSize: 15,
fontWeight: 'bold',
},
},
data: piedata,
}, },
], ],
}; };
@ -379,18 +451,78 @@
drawPieChart(piedata) { drawPieChart(piedata) {
console.log(this.passRatePie); console.log(this.passRatePie);
console.log('piedata', piedata); console.log('piedata', piedata);
let xData = piedata.map((item) => item.name);
let data = piedata.map((item) => item.value);
let myChart = echarts.init(document.getElementById('pieChart')); let myChart = echarts.init(document.getElementById('pieChart'));
let option = { //let option = {
tooltip: { // tooltip: {
trigger: 'item', // trigger: 'item',
confine: false, // confine: false,
avoidLabelOverlap: true, // avoidLabelOverlap: true,
// // //
itemStyle: { // itemStyle: {
fontSize: 100, // fontSize: 100,
}, // },
}, // },
// title: {
// text: '',
// left: 'left',
// top: '0%',
// textStyle: {
// fontSize: 16,
// },
// },
// legend: {
// top: 'center',
// right: '0%',
// orient: 'vertical',
// },
// color: ['#b3cde0', '#6497b1', '#005b96', '#03396c', '#e5e5e5'],
// series: [
// //
// {
// name: '',
// type: 'pie',
// center: ['30%', '50%'],
// radius: ['35%', '70%'],
// itemStyle: {
// borderRadius: 10,
// borderColor: '#fff',
// borderWidth: 2,
// },
// label: {
// show: true,
// fontSize: 14,
// overflow: 'truncate',
// minMargin: -1,
// },
// emphasis: {
// itemStyle: {
// shadowBlur: 10,
// shadowOffsetX: 0,
// shadowColor: 'rgba(0, 0, 0, 0.5)',
// },
// label: {
// show: true,
// fontSize: 15,
// fontWeight: 'bold',
// },
// },
// data: piedata,
// },
// ],
//};
let option = {
grid: {
left: '10%', //
right: '10%', //
bottom: '30%', // X
},
tooltip: {
trigger: 'axis',
},
title: { title: {
text: '四级分数分析', text: '四级分数分析',
left: 'left', left: 'left',
@ -399,44 +531,33 @@
fontSize: 16, fontSize: 16,
}, },
}, },
legend: { xAxis: {
top: 'center', type: 'category',
right: '0%', data: xData,
orient: 'vertical', axisLabel: {
interval: 0, //
//rotate: 10, // 45
margin: 15, // 线
},
axisLine: {
show: true,
},
boundaryGap: true, //
},
yAxis: {
type: 'value',
}, },
color: ['#b3cde0', '#6497b1', '#005b96', '#03396c', '#e5e5e5'],
series: [ series: [
//
{ {
name: '四级通过率', data: data,
type: 'pie', type: 'bar',
center: ['30%', '50%'],
radius: ['35%', '70%'],
itemStyle: {
borderRadius: 10,
borderColor: '#fff',
borderWidth: 2,
},
label: { label: {
show: true, show: true, //
fontSize: 14, position: 'top', //
overflow: 'truncate', fontSize: 12, //
minMargin: -1, color: '#000', //
}, },
emphasis: { barWidth: '25%',
itemStyle: {
shadowBlur: 10,
shadowOffsetX: 0,
shadowColor: 'rgba(0, 0, 0, 0.5)',
},
label: {
show: true,
fontSize: 15,
fontWeight: 'bold',
},
},
data: piedata,
}, },
], ],
}; };