配置项如下
dataObj = {
year: ['语文', '数学', '英语', '物理','化学','生物','政治','历史','地理'],
data: {
value: [{
name: '及格线',
value: [60,60 , 60,60,60,60,60,60 , 60],
}, {
name: '高一',
value: [54, 64, 87, 92,66,73,58,63,84]
}, {
name: '高二',
value: [76, 74, 83, 95,62,59,77,91,70]
}, {
name: '高三',
value: [60, 89, 51, 66,54,62,83,91,81]
}]
}
}
let dataArr = []
dataObj.data.value.map(item => {
let datachild = []
let newArr = {
name: item.name,
type: 'line',
smooth: true,
symbolSize: 8,
data: item.value,
barWidth: '30%',
itemStyle: {
normal: {
color: item.name ==='及格线'?'red':item.name ==='高一'?'#0BE3FF'
:item.name ==='高三'?'pink':'#16f892'
}
}
}
dataArr.push(newArr)
})
console.log(dataArr)
option = {
backgroundColor: '#12193a',
color: ['#f0c725', '#16f892'],
title: {
left: 'center',
text: '2020年第二学年期中考试成绩预警',
textStyle: {
color: '#FFFFFF',
fontSize: '14',
}
},
tooltip: {
trigger: 'axis',
axisPointer: { // 坐标轴指示器,坐标轴触发有效
type: 'shadow' // 默认为直线,可选为:'line' | 'shadow'
}
},
legend: {
x: 'center',
top: '25',
textStyle: {
color: '#c1cadf',
"fontSize": 14
}
},
grid: {
left: '6%',
right: '4%',
top: '25%',
bottom: '3%',
containLabel: true
},
toolbox: {
show: true,
orient: 'vertical',
x: 'right',
y: 'center'
},
xAxis: [{
type: 'category',
boundaryGap: false,
data: dataObj.year,
axisLine: {
lineStyle: {
color: 'rgba(240,199,37,0.5)'
}
},
axisLabel: {
interval: 0,
color: '#c1cadf',
fontSize:'15'
}
}],
yAxis: [{
type: 'value',
name: '成绩',
nameTextStyle: {
color: '#c1cadf',
align: 'right',
lineHeight: 10
},
axisLine: {
lineStyle: {
color: 'rgba(240,199,37,0.5)'
}
},
axisLabel: {
interval: 0,
color: '#c1cadf',
fontSize:'15'
},
splitLine: {
show: false
}
}],
series: dataArr
};