This commit is contained in:
2025-09-10 16:27:38 +08:00
parent a41e65989b
commit 300e3363d6
3 changed files with 134 additions and 102 deletions

View File

@@ -39,118 +39,80 @@ class RuYuanZaiYuanModel:
years = [str(year) for year in range(2015, 2025)]
# 构建学前教育数据
urban_enroll = [] # 城区入园
town_enroll = [] # 镇区入园人
rural_enroll = [] # 乡村入园人数
urban_in_school = [] # 城区在园人数
town_in_school = [] # 镇区在园人数
rural_in_school = [] # 乡村在园人数
enroll_total = [] # 入园
in_school_total = [] # 在园总
for year in years:
# 入园数(招生数据)
pre_enroll = yunnan_enroll.get("education_data", {}).get("preschool", {}).get(year, {})
urban_enroll.append(pre_enroll.get("urban", 0))
town_enroll.append(pre_enroll.get("town", 0))
rural_enroll.append(pre_enroll.get("rural", 0))
# 入园数(招生数据)
enroll_data = yunnan_enroll["education_data"]["preschool"].get(year, {})
enroll_total.append(enroll_data.get("total", 0))
# 在园数(在校生数据)
pre_in_school = yunnan_in_school.get("education_data", {}).get("preschool", {}).get(year, {})
urban_in_school.append(pre_in_school.get("urban", 0))
town_in_school.append(pre_in_school.get("town", 0))
rural_in_school.append(pre_in_school.get("rural", 0))
# 在园数(在校生数据)
in_school_data = yunnan_in_school["student_data"]["preschool"].get(year, {})
in_school_total.append(in_school_data.get("total", 0))
# 构建option数据结构
# 构建ECharts配置
option = {
"grid": {
"left": 0,
"right": 0,
"top": 40,
"bottom": 10,
"containLabel": True,
},
"textStyle": {
"color": "#fff",
"title": {
"text": "云南省学前教育人数统计",
"left": "center",
"textStyle": {"color": "#333"}
},
"tooltip": {
"trigger": "axis",
"axisPointer": {
"type": "cross",
"crossStyle": { "color": "#999" },
},
"textStyle": { "color": "#fff" },
"backgroundColor": "rgba(96,98,102,0.8)",
"borderColor": "rgba(255,255,255,0.3)",
"borderWidth": 1,
"axisPointer": {"type": "shadow"}
},
"legend": {
"data": ["城区入园", "镇区入园人", "乡村入园人数",
"城区在园人数", "镇区在园人数", "乡村在园人数"],
"top": 0,
"textStyle": { "color": "#fff" },
"icon": "roundRect",
"itemWidth": 12,
"itemHeight": 12,
"data": ["入园", "在园总"],
"top": 30,
"textStyle": {"color": "#333"}
},
"xAxis": [
{
"type": "category",
"data": years,
"axisPointer": { "type": "shadow" },
"axisLine": { "lineStyle": { "color": "#fff" } },
"axisLabel": { "color": "#fff" },
"nameTextStyle": { "color": "#fff" },
"xAxis": {
"type": "category",
"data": years,
"axisLabel": {"color": "#333"},
"axisLine": {"lineStyle": {"color": "#333"}}
},
"yAxis": {
"type": "value",
"name": "人数",
"min": 0,
"max": 100,
"interval": 30,
"axisLabel": {
"formatter": "{value} 万人",
"color": "#333"
},
],
"yAxis": [
{
"type": "value",
"axisLabel": { "formatter": "{value}", "color": "#fff" },
}
],
"axisLine": {"lineStyle": {"color": "#333"}},
"splitLine": {"lineStyle": {"color": "rgba(0,0,0,0.1)"}}
},
"series": [
{
"name": "城区入园",
"name": "入园",
"type": "bar",
"data": urban_enroll,
"itemStyle": { "borderRadius": [6, 6, 0, 0] },
"data": enroll_total,
"itemStyle": {
"color": "#5470c6",
"borderRadius": [4, 4, 0, 0]
},
"barWidth": "40%"
},
{
"name": "镇区入园人",
"type": "bar",
"data": town_enroll,
"itemStyle": { "borderRadius": [6, 6, 0, 0] },
},
{
"name": "乡村入园人数",
"type": "bar",
"data": rural_enroll,
"itemStyle": { "borderRadius": [6, 6, 0, 0] },
},
{
"name": "城区在园人数",
"name": "在园总",
"type": "line",
"data": urban_in_school,
"yAxisIndex": 0,
"lineStyle": { "width": 3 },
"symbolSize": 8,
},
{
"name": "镇区在园人数",
"type": "line",
"data": town_in_school,
"yAxisIndex": 0,
"lineStyle": { "width": 3 },
"symbolSize": 8,
},
{
"name": "乡村在园人数",
"type": "line",
"data": rural_in_school,
"yAxisIndex": 0,
"lineStyle": { "width": 3 },
"data": in_school_total,
"lineStyle": {"color": "#91cc75", "width": 3},
"symbol": "circle",
"symbolSize": 8,
"itemStyle": {"color": "#91cc75"}
}
],
"grid": {
"left": "3%",
"right": "4%",
"bottom": "3%",
"containLabel": True
}
}
return option