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

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');
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 = [];
piedata.push({ value: result.scoreByBatch.read, name: '阅读' });
piedata.push({ value: result.scoreByBatch.listen, name: '听力' });
@ -312,18 +329,80 @@
drawResChart(piedata) {
console.log(this.passRatePie);
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 option = {
tooltip: {
trigger: 'item',
confine: false,
avoidLabelOverlap: true,
//
itemStyle: {
fontSize: 100,
},
},
//let option = {
// tooltip: {
// trigger: 'item',
// confine: false,
// avoidLabelOverlap: true,
// //
// itemStyle: {
// 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: {
text: '四级分数占比',
left: 'left',
@ -332,44 +411,37 @@
fontSize: 16,
},
},
legend: {
top: 'center',
right: '0%',
orient: 'vertical',
xAxis: {
type: 'category',
data: xData,
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: [
//
{
name: '四级通过率',
type: 'pie',
center: ['30%', '50%'],
radius: ['35%', '70%'],
itemStyle: {
borderRadius: 10,
borderColor: '#fff',
borderWidth: 2,
},
data: Data,
type: 'bar',
label: {
show: true,
fontSize: 14,
overflow: 'truncate',
minMargin: -1,
show: true, //
position: 'top', //
formatter: '{c}%', // 使 {c}
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) {
console.log(this.passRatePie);
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 option = {
tooltip: {
trigger: 'item',
confine: false,
avoidLabelOverlap: true,
//
itemStyle: {
fontSize: 100,
},
},
//let option = {
// tooltip: {
// trigger: 'item',
// confine: false,
// avoidLabelOverlap: true,
// //
// itemStyle: {
// 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: {
text: '四级分数分析',
left: 'left',
@ -399,44 +531,33 @@
fontSize: 16,
},
},
legend: {
top: 'center',
right: '0%',
orient: 'vertical',
xAxis: {
type: 'category',
data: xData,
axisLabel: {
interval: 0, //
//rotate: 10, // 45
margin: 15, // 线
},
axisLine: {
show: true,
},
boundaryGap: true, //
},
yAxis: {
type: 'value',
},
color: ['#b3cde0', '#6497b1', '#005b96', '#03396c', '#e5e5e5'],
series: [
//
{
name: '四级通过率',
type: 'pie',
center: ['30%', '50%'],
radius: ['35%', '70%'],
itemStyle: {
borderRadius: 10,
borderColor: '#fff',
borderWidth: 2,
},
data: data,
type: 'bar',
label: {
show: true,
fontSize: 14,
overflow: 'truncate',
minMargin: -1,
show: true, //
position: 'top', //
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,
barWidth: '25%',
},
],
};