This commit is contained in:
2025-09-10 16:39:30 +08:00
parent 300e3363d6
commit d0259d12f3
3 changed files with 93 additions and 49 deletions

View File

@@ -30,26 +30,25 @@ class RuYuanZaiYuanModel:
# 提取云南省级数据 # 提取云南省级数据
yunnan_enroll = next((item for item in enrollment_data if item["area_name"] == "云南省"), None) yunnan_enroll = next((item for item in enrollment_data if item["area_name"] == "云南省"), None)
yunnan_in_school = next((item for item in in_school_data if item["area_name"] == "云南省"), None)
if not yunnan_enroll or not yunnan_in_school: if not yunnan_enroll:
return {} return {}
# 提取年份数据(2015-2024) # 提取年份数据(2015-2024)
years = [str(year) for year in range(2015, 2025)] years = [str(year) for year in range(2015, 2025)]
# 构建学前教育数据 # 构建学前教育数据
enroll_total = [] # 入园总数 urban_data = [] # 城区数据
in_school_total = [] # 在园总数 town_data = [] # 镇区数据
rural_data = [] # 乡村数据
total_enroll = [] # 总入园数
for year in years: for year in years:
# 入园总数(招生数据)
enroll_data = yunnan_enroll["education_data"]["preschool"].get(year, {}) enroll_data = yunnan_enroll["education_data"]["preschool"].get(year, {})
enroll_total.append(enroll_data.get("total", 0)) urban_data.append(enroll_data.get("urban", 0) / 10000) # 转换为万人
town_data.append(enroll_data.get("town", 0) / 10000) # 转换为万人
# 在园总数(在校生数据) rural_data.append(enroll_data.get("rural", 0) / 10000) # 转换为万人
in_school_data = yunnan_in_school["student_data"]["preschool"].get(year, {}) total_enroll.append(enroll_data.get("total", 0) / 10000) # 转换为万人
in_school_total.append(in_school_data.get("total", 0))
# 构建ECharts配置 # 构建ECharts配置
option = { option = {
@@ -60,51 +59,103 @@ class RuYuanZaiYuanModel:
}, },
"tooltip": { "tooltip": {
"trigger": "axis", "trigger": "axis",
"axisPointer": {"type": "shadow"} "axisPointer": {
"type": "cross",
"crossStyle": {"color": "#999"}
},
"textStyle": {"color": "#333"},
"backgroundColor": "rgba(255, 255, 255, 0.8)",
"borderColor": "rgba(0, 0, 0, 0.2)",
"borderWidth": 1
}, },
"legend": { "legend": {
"data": ["入园总数", "在园总"], "data": ["城区", "镇区", "乡村", "总入园"],
"top": 30, "top": 30,
"textStyle": {"color": "#333"} "textStyle": {"color": "#333"},
"icon": "roundRect",
"itemWidth": 12,
"itemHeight": 12
}, },
"xAxis": { "xAxis": [
"type": "category", {
"data": years, "type": "category",
"axisLabel": {"color": "#333"}, "data": years,
"axisLine": {"lineStyle": {"color": "#333"}} "axisPointer": {"type": "shadow"},
}, "axisLabel": {"color": "#333"},
"yAxis": { "axisLine": {"lineStyle": {"color": "#333"}}
"type": "value", }
"name": "人数", ],
"min": 0, "yAxis": [
"max": 100, {
"interval": 30, "type": "value",
"axisLabel": { "name": "人数",
"formatter": "{value} 万人", "min": 0,
"color": "#333" "max": 100,
"interval": 20,
"axisLabel": {
"formatter": "{value} 万人",
"color": "#333"
},
"axisLine": {"lineStyle": {"color": "#333"}},
"splitLine": {"lineStyle": {"color": "rgba(0,0,0,0.1)"}}
}, },
"axisLine": {"lineStyle": {"color": "#333"}}, {
"splitLine": {"lineStyle": {"color": "rgba(0,0,0,0.1)"}} "type": "value",
}, "name": "总入园数",
"min": 0,
"max": 40,
"interval": 8,
"axisLabel": {
"formatter": "{value} 万人",
"color": "#333"
},
"axisLine": {"lineStyle": {"color": "#333"}},
"splitLine": {"show": False}
}
],
"series": [ "series": [
{ {
"name": "入园总数", "name": "城区",
"type": "bar", "type": "bar",
"data": enroll_total, "data": urban_data,
"itemStyle": { "itemStyle": {
"color": "#5470c6", "color": "#5470c6",
"borderRadius": [4, 4, 0, 0] "borderRadius": [6, 6, 0, 0]
}, },
"barWidth": "40%" "barWidth": "25%", # 增加柱子宽度
"barGap": "-10%" # 设置负数让柱子重叠以减少空隙
}, },
{ {
"name": "在园总数", "name": "镇区",
"type": "bar",
"data": town_data,
"itemStyle": {
"color": "#91cc75",
"borderRadius": [6, 6, 0, 0]
},
"barWidth": "25%", # 增加柱子宽度
"barGap": "-10%" # 设置负数让柱子重叠以减少空隙
},
{
"name": "乡村",
"type": "bar",
"data": rural_data,
"itemStyle": {
"color": "#fac858",
"borderRadius": [6, 6, 0, 0]
},
"barWidth": "25%", # 增加柱子宽度
"barGap": "-10%" # 设置负数让柱子重叠以减少空隙
},
{
"name": "总入园数",
"type": "line", "type": "line",
"data": in_school_total, "yAxisIndex": 1,
"lineStyle": {"color": "#91cc75", "width": 3}, "data": total_enroll,
"lineStyle": {"color": "#ee6666", "width": 3},
"symbol": "circle", "symbol": "circle",
"symbolSize": 8, "symbolSize": 8,
"itemStyle": {"color": "#91cc75"} "itemStyle": {"color": "#ee6666"}
} }
], ],
"grid": { "grid": {

View File

@@ -51,8 +51,7 @@
<div class="chart-controls"> <div class="chart-controls">
<div class="btn-group"> <div class="btn-group">
<button class="btn active" data-type="both">全部显示</button> <button class="btn active" data-type="enroll">入园数总量</button>
<button class="btn" data-type="enroll">入园数总量</button>
<button class="btn" data-type="inschool">在园数总量</button> <button class="btn" data-type="inschool">在园数总量</button>
</div> </div>
</div> </div>
@@ -65,7 +64,7 @@
// 初始化图表 // 初始化图表
var preschoolChart = echarts.init(document.getElementById('preschoolChart')); var preschoolChart = echarts.init(document.getElementById('preschoolChart'));
var chartData = null; var chartData = null;
var currentType = 'both'; var currentType = 'enroll';
// 显示加载状态 // 显示加载状态
function showLoading() { function showLoading() {
@@ -89,13 +88,7 @@
var option = JSON.parse(JSON.stringify(chartData)); var option = JSON.parse(JSON.stringify(chartData));
// 根据当前选择的类型过滤数据 // 根据用户要求,现在显示所有系列数据,不需要过滤
if (currentType === 'enroll') {
option.series = [option.series[0]]; // 只显示入园总数
} else if (currentType === 'inschool') {
option.series = [option.series[1]]; // 只显示在园总数
}
preschoolChart.setOption(option); preschoolChart.setOption(option);
} }